Skip to content

Commit a3e3e72

Browse files
author
mohamed ali
committed
bool value in sql, revised
1 parent c384d35 commit a3e3e72

File tree

10 files changed

+84
-53
lines changed

10 files changed

+84
-53
lines changed

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 30
29+
compileSdkVersion 31
3030

3131
sourceSets {
3232
main.java.srcDirs += 'src/main/kotlin'

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.50'
2+
ext.kotlin_version = '1.6.10'
33
repositories {
44
google()
55
jcenter()

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 46;
6+
objectVersion = 50;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -156,7 +156,7 @@
156156
97C146E61CF9000F007C117D /* Project object */ = {
157157
isa = PBXProject;
158158
attributes = {
159-
LastUpgradeCheck = 1020;
159+
LastUpgradeCheck = 1300;
160160
ORGANIZATIONNAME = "";
161161
TargetAttributes = {
162162
97C146ED1CF9000F007C117D = {

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1300"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

example/lib/db_model.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class DbModel extends DatabaseModel {
99
// student
1010
late DbColumn studentName;
1111
late IntColumn studentDegree;
12+
late BoolColumn studentSuccess;
1213
late Table studentsTable;
1314

1415
late IntColumn studentGradeFk;
@@ -26,7 +27,6 @@ class DbModel extends DatabaseModel {
2627

2728
@override
2829
void defineDatabaseObjects(Database db) {
29-
3030
// Grade table
3131
gradeName = db.stringColumn('gradeName', 50);
3232
studentsCount = db.intColumn('studentsCount', defaultValue: 0);
@@ -37,8 +37,9 @@ class DbModel extends DatabaseModel {
3737
studentName = db.stringColumn('studentName', 200);
3838
studentDegree = db.intColumn('studentDegree', defaultValue: 0);
3939
studentJoinDate = db.dateColumn('studentJoinDate', allowNull: true);
40+
studentSuccess = db.boolColumn('studentSuccess', allowNull: true, defaultValue: true);
4041

41-
studentsTable = db.newTable("Students", [studentName, studentDegree, studentJoinDate]);
42+
studentsTable = db.newTable("Students", [studentName, studentDegree, studentJoinDate, studentSuccess]);
4243

4344
// fk
4445
studentGradeFk = studentsTable.addFKto(gradesTable, "studentGradeFk");

example/lib/main.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class _MyHomePageState extends State<MyHomePage> {
105105
'studentName': 'ahmed$i-1',
106106
'studentDegree': i * 10,
107107
'studentJoinDate': DateTime(2020, 1, i),
108+
'studentSuccess': false,
108109
'studentGradeFk': 1
109110
}).execute(transactionContext);
110111
}
@@ -114,6 +115,7 @@ class _MyHomePageState extends State<MyHomePage> {
114115
'studentName': 'ahmed$i-2',
115116
'studentDegree': i * 10,
116117
'studentJoinDate': DateTime(2020, 1, i),
118+
'studentSuccess': 1, // int value for bool
117119
'studentGradeFk': 2
118120
}).execute(transactionContext);
119121
}
@@ -178,8 +180,13 @@ class _MyHomePageState extends State<MyHomePage> {
178180

179181
var q4 = await db.Select().From(dbm.studentGradeView).Page(0, 2).execute(dbc);
180182

181-
log('select first 2 from view => $q3');
182-
expect(2, q3.length);
183+
log('select first 2 from view => $q4');
184+
expect(2, q4.length);
185+
186+
var q5 = await db.Select().From(dbm.studentGradeView).Where(dbm.studentSuccess.Equal(true)).Page(0, 2).execute(dbc);
187+
188+
log('select by bool field, first 2 from view => $q5');
189+
expect(2, q5.length);
183190

184191
dbc.close();
185192
}

example/pubspec.lock

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.8.1"
10+
version: "2.8.2"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -21,7 +21,7 @@ packages:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.1.0"
24+
version: "1.2.0"
2525
charcode:
2626
dependency: transitive
2727
description:
@@ -94,7 +94,14 @@ packages:
9494
name: matcher
9595
url: "https://pub.dartlang.org"
9696
source: hosted
97-
version: "0.12.10"
97+
version: "0.12.11"
98+
material_color_utilities:
99+
dependency: transitive
100+
description:
101+
name: material_color_utilities
102+
url: "https://pub.dartlang.org"
103+
source: hosted
104+
version: "0.1.3"
98105
meta:
99106
dependency: transitive
100107
description:
@@ -115,14 +122,14 @@ packages:
115122
name: path_provider
116123
url: "https://pub.dartlang.org"
117124
source: hosted
118-
version: "2.0.7"
125+
version: "2.0.9"
119126
path_provider_android:
120127
dependency: transitive
121128
description:
122129
name: path_provider_android
123130
url: "https://pub.dartlang.org"
124131
source: hosted
125-
version: "2.0.7"
132+
version: "2.0.11"
126133
path_provider_ios:
127134
dependency: transitive
128135
description:
@@ -136,42 +143,42 @@ packages:
136143
name: path_provider_linux
137144
url: "https://pub.dartlang.org"
138145
source: hosted
139-
version: "2.1.2"
146+
version: "2.1.5"
140147
path_provider_macos:
141148
dependency: transitive
142149
description:
143150
name: path_provider_macos
144151
url: "https://pub.dartlang.org"
145152
source: hosted
146-
version: "2.0.3"
153+
version: "2.0.5"
147154
path_provider_platform_interface:
148155
dependency: transitive
149156
description:
150157
name: path_provider_platform_interface
151158
url: "https://pub.dartlang.org"
152159
source: hosted
153-
version: "2.0.1"
160+
version: "2.0.3"
154161
path_provider_windows:
155162
dependency: transitive
156163
description:
157164
name: path_provider_windows
158165
url: "https://pub.dartlang.org"
159166
source: hosted
160-
version: "2.0.4"
167+
version: "2.0.5"
161168
platform:
162169
dependency: transitive
163170
description:
164171
name: platform
165172
url: "https://pub.dartlang.org"
166173
source: hosted
167-
version: "3.0.2"
174+
version: "3.1.0"
168175
plugin_platform_interface:
169176
dependency: transitive
170177
description:
171178
name: plugin_platform_interface
172179
url: "https://pub.dartlang.org"
173180
source: hosted
174-
version: "2.0.2"
181+
version: "2.1.2"
175182
process:
176183
dependency: transitive
177184
description:
@@ -204,7 +211,7 @@ packages:
204211
name: sqflite_common
205212
url: "https://pub.dartlang.org"
206213
source: hosted
207-
version: "2.0.1+1"
214+
version: "2.2.0"
208215
stack_trace:
209216
dependency: transitive
210217
description:
@@ -246,7 +253,7 @@ packages:
246253
name: test_api
247254
url: "https://pub.dartlang.org"
248255
source: hosted
249-
version: "0.4.2"
256+
version: "0.4.8"
250257
typed_data:
251258
dependency: transitive
252259
description:
@@ -260,21 +267,21 @@ packages:
260267
name: vector_math
261268
url: "https://pub.dartlang.org"
262269
source: hosted
263-
version: "2.1.0"
270+
version: "2.1.1"
264271
win32:
265272
dependency: transitive
266273
description:
267274
name: win32
268275
url: "https://pub.dartlang.org"
269276
source: hosted
270-
version: "2.3.0"
277+
version: "2.4.1"
271278
xdg_directories:
272279
dependency: transitive
273280
description:
274281
name: xdg_directories
275282
url: "https://pub.dartlang.org"
276283
source: hosted
277-
version: "0.2.0"
284+
version: "0.2.0+1"
278285
sdks:
279-
dart: ">=2.14.0 <3.0.0"
286+
dart: ">=2.15.0 <3.0.0"
280287
flutter: ">=2.5.0"

lib/src/core/expression.dart

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -376,36 +376,41 @@ class ValueExpr extends Expr {
376376
@override
377377
String toSql(Statement? st) {
378378
if (name != null && st != null && val != null) {
379-
st._addParam(name!, val!.toString());
379+
st._addParam(name!, (val! is DateTime || val! is String) ? val!.toString() : val!);
380380
return "?";
381381
//return "@${name}";
382382
}
383383
//
384384
if (val == null) {
385385
return "NULL";
386-
} else if (val is String || val is DateTime) {
386+
}
387+
else if (val is String || val is DateTime) {
387388
return "'${val}'";
388-
} else //double, bool, int
389+
}
390+
// else if(val is bool){
391+
// return (val as bool) ? '1' : '0';
392+
// }
393+
else // num, bool
389394
{
390395
return val.toString();
391396
}
392397
}
393398

394-
String _valueString() {
395-
if (val == null) {
396-
return 'NULL';
397-
}
398-
//
399-
if (this.fieldType == dbType.Date && this.val is DateTime) {
400-
return (val! as DateTime).dateString();
401-
}
402-
//
403-
if (fieldType == dbType.DateTime && val is DateTime) {
404-
return (val! as DateTime).dateTimeString();
405-
}
406-
//
407-
return val.toString();
408-
}
399+
// String _valueString() {
400+
// if (val == null) {
401+
// return 'NULL';
402+
// }
403+
// //
404+
// if (this.fieldType == dbType.Date && this.val is DateTime) {
405+
// return (val! as DateTime).dateString();
406+
// }
407+
// //
408+
// if (fieldType == dbType.DateTime && val is DateTime) {
409+
// return (val! as DateTime).dateTimeString();
410+
// }
411+
// //
412+
// return val.toString();
413+
// }
409414
}
410415

411416
class InExpression extends Expr {
@@ -421,7 +426,11 @@ class InExpression extends Expr {
421426
return "NULL";
422427
} else if (val is String || val is DateTime) {
423428
return "'${val}'";
424-
} else //double
429+
}
430+
// else if(val is bool){
431+
// return val ? '1' : '0';
432+
// }
433+
else // num, bool
425434
{
426435
return val.toString();
427436
}

lib/src/core/table.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class Table extends DbTable {
4343
IntColumn addFKto(Table table, String name,
4444
{bool allowNull = false,
4545
bool unique = false,
46-
IntegrityRule onUpdate = IntegrityRule.noAction,
47-
IntegrityRule onDelete = IntegrityRule.noAction}) {
46+
IntegrityRule onUpdate = IntegrityRule.cascade,
47+
IntegrityRule onDelete = IntegrityRule.cascade}) {
4848
IntColumn tmp = db.intColumn(name, allowNull: allowNull, unique: unique);
4949

5050
this.fields.add(tmp);

pubspec.lock

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.8.1"
10+
version: "2.8.2"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -21,7 +21,7 @@ packages:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.1.0"
24+
version: "1.2.0"
2525
charcode:
2626
dependency: transitive
2727
description:
@@ -66,7 +66,14 @@ packages:
6666
name: matcher
6767
url: "https://pub.dartlang.org"
6868
source: hosted
69-
version: "0.12.10"
69+
version: "0.12.11"
70+
material_color_utilities:
71+
dependency: transitive
72+
description:
73+
name: material_color_utilities
74+
url: "https://pub.dartlang.org"
75+
source: hosted
76+
version: "0.1.3"
7077
meta:
7178
dependency: transitive
7279
description:
@@ -148,7 +155,7 @@ packages:
148155
name: test_api
149156
url: "https://pub.dartlang.org"
150157
source: hosted
151-
version: "0.4.2"
158+
version: "0.4.8"
152159
typed_data:
153160
dependency: transitive
154161
description:
@@ -162,7 +169,7 @@ packages:
162169
name: vector_math
163170
url: "https://pub.dartlang.org"
164171
source: hosted
165-
version: "2.1.0"
172+
version: "2.1.1"
166173
sdks:
167-
dart: ">=2.12.0 <3.0.0"
174+
dart: ">=2.14.0 <3.0.0"
168175
flutter: ">=1.17.0"

0 commit comments

Comments
 (0)