Skip to content

Commit d7dc593

Browse files
committed
fix(mysql_utils): fix updateData processing logic when the type is String
- Added test cases for Urdu Arabic text in mysql_utils_test.dart
1 parent 631ffa5 commit d7dc593

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

lib/src/mysql_utils.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,7 @@ class MysqlUtils {
183183
List<String> _setkeys = [];
184184
List values = [];
185185
updateData.forEach((key, value) {
186-
if (value is String) {
187-
_setkeys.add('`$key` = ?');
188-
values.add(value);
189-
} else if (value is List) {
186+
if (value is List) {
190187
if (value.length != 2) {
191188
throw ('$key value.length!=2');
192189
}
@@ -197,6 +194,9 @@ class MysqlUtils {
197194
_setkeys.add('`$key` = `$key` - ?');
198195
values.add(value.last);
199196
}
197+
} else {
198+
_setkeys.add('`$key` = ?');
199+
values.add(value);
200200
}
201201
});
202202
values.addAll(_whereAndValues.last);

test/binary_id_test.dart

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:typed_data';
2-
31
import 'package:mysql_utils/mysql_utils.dart';
42
import 'package:test/test.dart';
53

@@ -37,7 +35,7 @@ void main() {
3735
});
3836

3937
tearDownAll(() async {
40-
await db.close();
38+
//await db.close();
4139
});
4240

4341
test('Execute: create table ', () async {
@@ -51,34 +49,19 @@ void main() {
5149
});
5250

5351
test('Execute: insert data ', () async {
54-
await db.query('INSERT INTO test_data3 (name) VALUES ("binary data test")');
55-
final result = await db.query("SELECT (id) FROM test_data3");
56-
final row = result.rows.first;
57-
final uuid = binaryToUuid(row['id']);
58-
52+
await db.insert(
53+
table: 'test_data3',
54+
insertData: {
55+
'name': 'binary data test',
56+
},
57+
);
5958
final result2 =
6059
await db.query("SELECT BIN_TO_UUID(id) as UUID FROM test_data3");
6160
final row2 = result2.rows.first;
62-
63-
expect(uuid, row2['UUID']);
61+
print(row2['UUID']);
6462
});
6563

6664
test('Execute: drop table ', () async {
6765
await db.query("DROP TABLE IF EXISTS `test_data3`");
6866
});
6967
}
70-
71-
String binaryToUuid(String idStr) {
72-
final bytes = Uint8List.fromList(idStr.codeUnits);
73-
assert(bytes.length == 16);
74-
String hex = _bytesToHex(bytes);
75-
return '${hex.substring(0, 8)}-${hex.substring(8, 12)}-${hex.substring(12, 16)}-${hex.substring(16, 20)}-${hex.substring(20)}';
76-
}
77-
78-
String _bytesToHex(List<int> bytes) {
79-
final buffer = StringBuffer();
80-
for (final byte in bytes) {
81-
buffer.write(byte.toRadixString(16).padLeft(2, '0'));
82-
}
83-
return buffer.toString();
84-
}

test/mysql_utils_test.dart

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void main() {
8888
// fields: 'id',
8989
where: {'id': 2},
9090
);
91+
print(req1);
9192
expect(req1['id'], 2);
9293
});
9394

@@ -97,6 +98,7 @@ void main() {
9798
fields: 'id',
9899
where: {'int_column': 1001},
99100
);
101+
print(req1);
100102
expect(req1.length, 3);
101103
});
102104

@@ -114,6 +116,19 @@ void main() {
114116
);
115117
expect(req2, BigInt.from(1));
116118
});
119+
test('Execute: urdu arabic', () async {
120+
final textData = 'السلام علیکم';
121+
await db.update(
122+
table: 'test_data',
123+
updateData: {'string_column': textData},
124+
where: {'id': 2},
125+
);
126+
var req2 = await db.getOne(
127+
table: 'test_data',
128+
where: {'id': 2},
129+
);
130+
expect(req2['string_column'], textData);
131+
});
117132

118133
test('Execute: count ', () async {
119134
var req1 = await db.count(
@@ -181,19 +196,19 @@ void main() {
181196
await db.rollback();
182197
});
183198

184-
// test('Execute: delete ', () async {
185-
// var req1 = await db.delete(
186-
// table: 'test_data',
187-
// where: {
188-
// 'id': ['>', 0]
189-
// },
190-
// );
191-
// expect(req1, BigInt.from(3));
192-
// });
199+
test('Execute: delete ', () async {
200+
var req1 = await db.delete(
201+
table: 'test_data',
202+
where: {
203+
'id': ['>', 0]
204+
},
205+
);
206+
expect(req1, BigInt.from(3));
207+
});
193208

194-
// test('Execute: drop table ', () async {
195-
// await db.query("DROP TABLE IF EXISTS `test_data`");
196-
// });
209+
test('Execute: drop table ', () async {
210+
await db.query("DROP TABLE IF EXISTS `test_data`");
211+
});
197212

198213
test('Execute: isAlive ', () async {
199214
bool isAlive = await db.isConnectionAlive();

0 commit comments

Comments
 (0)