@@ -82,15 +82,15 @@ public void run() {
82
82
for (int i = 0 ; i < numQueries ; i ++) {
83
83
ReadableArray sqlQuery = queries .getArray (i );
84
84
String sql = sqlQuery .getString (0 );
85
- String [] bindArgs = convertParamsToStringArray ( sqlQuery .getArray (1 ) );
85
+ ReadableArray queryArgs = sqlQuery .getArray (1 );
86
86
try {
87
87
if (isSelect (sql )) {
88
- results [i ] = doSelectInBackgroundAndPossiblyThrow (sql , bindArgs , db );
88
+ results [i ] = doSelectInBackgroundAndPossiblyThrow (sql , queryArgs , db );
89
89
} else { // update/insert/delete
90
90
if (readOnly ) {
91
91
results [i ] = new SQLitePLuginResult (EMPTY_ROWS , EMPTY_COLUMNS , 0 , 0 , new ReadOnlyException ());
92
92
} else {
93
- results [i ] = doUpdateInBackgroundAndPossiblyThrow (sql , bindArgs , db );
93
+ results [i ] = doUpdateInBackgroundAndPossiblyThrow (sql , queryArgs , db );
94
94
}
95
95
}
96
96
} catch (Throwable e ) {
@@ -110,15 +110,33 @@ public void run() {
110
110
}
111
111
112
112
// do a update/delete/insert operation
113
- private SQLitePLuginResult doUpdateInBackgroundAndPossiblyThrow (String sql , String [] bindArgs ,
114
- SQLiteDatabase db ) {
113
+ private SQLitePLuginResult doUpdateInBackgroundAndPossiblyThrow (String sql , ReadableArray queryArgs , SQLiteDatabase db ) throws IllegalArgumentException {
115
114
debug ("\" run\" query: %s" , sql );
116
115
SQLiteStatement statement = null ;
117
116
try {
118
117
statement = db .compileStatement (sql );
119
118
debug ("compiled statement" );
120
- if (bindArgs != null ) {
121
- statement .bindAllArgsAsStrings (bindArgs );
119
+ // Bind all of the arguments
120
+ for (int i = 0 ; i < queryArgs .size (); i ++) {
121
+ ReadableType type = queryArgs .getType (i );
122
+ switch (type ) {
123
+ case Null :
124
+ statement .bindNull (i + 1 );
125
+ break ;
126
+ case Boolean :
127
+ final long b = queryArgs .getBoolean (i ) ? 1 : 0 ;
128
+ statement .bindLong (i + 1 , b );
129
+ break ;
130
+ case Number :
131
+ final double f = queryArgs .getDouble (i );
132
+ statement .bindDouble (i + 1 , f );
133
+ break ;
134
+ case String :
135
+ statement .bindString (i + 1 , unescapeBlob (queryArgs .getString (i )));
136
+ break ;
137
+ default :
138
+ throw new IllegalArgumentException ("Unexpected data type given" );
139
+ }
122
140
}
123
141
debug ("bound args" );
124
142
if (isInsert (sql )) {
@@ -145,11 +163,11 @@ private SQLitePLuginResult doUpdateInBackgroundAndPossiblyThrow(String sql, Stri
145
163
}
146
164
147
165
// do a select operation
148
- private SQLitePLuginResult doSelectInBackgroundAndPossiblyThrow (String sql , String [] bindArgs ,
149
- SQLiteDatabase db ) {
166
+ private SQLitePLuginResult doSelectInBackgroundAndPossiblyThrow (String sql , ReadableArray queryArgs , SQLiteDatabase db ) {
150
167
debug ("\" all\" query: %s" , sql );
151
168
Cursor cursor = null ;
152
169
try {
170
+ String [] bindArgs = convertParamsToStringArray (queryArgs );
153
171
cursor = db .rawQuery (sql , bindArgs );
154
172
int numRows = cursor .getCount ();
155
173
if (numRows == 0 ) {
@@ -177,7 +195,7 @@ private SQLitePLuginResult doSelectInBackgroundAndPossiblyThrow(String sql, Stri
177
195
private Object getValueFromCursor (Cursor cursor , int index , int columnType ) {
178
196
switch (columnType ) {
179
197
case Cursor .FIELD_TYPE_FLOAT :
180
- return cursor .getFloat (index );
198
+ return cursor .getDouble (index );
181
199
case Cursor .FIELD_TYPE_INTEGER :
182
200
return cursor .getInt (index );
183
201
case Cursor .FIELD_TYPE_BLOB :
0 commit comments