aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/sledjchisl
diff options
context:
space:
mode:
authoronefang2020-04-25 05:16:24 +1000
committeronefang2020-04-25 05:16:24 +1000
commitf91b9aee396de79684f3c2f98d5486a9816ac0e7 (patch)
treea7fab28f949b49ed47cbe9d55cccae0502394559 /src/sledjchisl
parentClean up cleanup(). (diff)
downloadopensim-SC_OLD-f91b9aee396de79684f3c2f98d5486a9816ac0e7.zip
opensim-SC_OLD-f91b9aee396de79684f3c2f98d5486a9816ac0e7.tar.gz
opensim-SC_OLD-f91b9aee396de79684f3c2f98d5486a9816ac0e7.tar.bz2
opensim-SC_OLD-f91b9aee396de79684f3c2f98d5486a9816ac0e7.tar.xz
Some db clean up, and support INSERT.
Diffstat (limited to 'src/sledjchisl')
-rw-r--r--src/sledjchisl/sledjchisl.c206
1 files changed, 156 insertions, 50 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c
index d6c7730..35f6202 100644
--- a/src/sledjchisl/sledjchisl.c
+++ b/src/sledjchisl/sledjchisl.c
@@ -1016,6 +1016,14 @@ d("Freeing field %s", fld->name);
1016 flds->free(flds); 1016 flds->free(flds);
1017} 1017}
1018 1018
1019enum dbCommandType
1020{
1021 CT_SELECT,
1022 CT_CREATE,
1023 CT_UPDATE,
1024 CT_NONE
1025};
1026
1019typedef struct _dbRequest dbRequest; 1027typedef struct _dbRequest dbRequest;
1020struct _dbRequest 1028struct _dbRequest
1021{ 1029{
@@ -1028,11 +1036,13 @@ struct _dbRequest
1028 MYSQL_BIND *inBind, *outBind; 1036 MYSQL_BIND *inBind, *outBind;
1029 rowData *rows; 1037 rowData *rows;
1030 my_ulonglong count; 1038 my_ulonglong count;
1039 enum dbCommandType type;
1031 boolean freeOutParams; 1040 boolean freeOutParams;
1032}; 1041};
1033 1042
1034void dbDoSomething(dbRequest *req, boolean count, ...) 1043int dbDoSomething(dbRequest *req, boolean count, ...)
1035{ 1044{
1045 int ret = 0;
1036 va_list ap; 1046 va_list ap;
1037 struct timespec now, then; 1047 struct timespec now, then;
1038 int i, j; 1048 int i, j;
@@ -1046,45 +1056,94 @@ void dbDoSomething(dbRequest *req, boolean count, ...)
1046 if (NULL == req->prep) 1056 if (NULL == req->prep)
1047 { 1057 {
1048 D("Creating prepared statement for %s - %s", req->table, req->where); 1058 D("Creating prepared statement for %s - %s", req->table, req->where);
1059
1060 if (0 == req->type)
1061 req->type = CT_SELECT;
1062
1049 req->flds = dbGetFields(req->db, req->table); 1063 req->flds = dbGetFields(req->db, req->table);
1050 if (NULL == req->flds) 1064 if (NULL == req->flds)
1051 { 1065 {
1052 E("Unknown fields for table %s.", req->table); 1066 E("Unknown fields for table %s.", req->table);
1067 ret++;
1053 goto end; 1068 goto end;
1054 } 1069 }
1055 1070
1056 char *select = xmprintf(""); 1071 switch (req->type)
1057 i = 0;
1058 while (req->outParams[i] != NULL)
1059 { 1072 {
1060 char *t = xmprintf("%s,%s", select, req->outParams[i]); 1073 case CT_SELECT :
1061 free(select); 1074 {
1062 select = t; 1075 char *select = xmprintf("");
1063 i++;
1064 }
1065 if (0 == i)
1066 {
1067 free(select);
1068 if (count)
1069 select = xmprintf(",Count(*)");
1070 else
1071 select = xmprintf(",*");
1072 }
1073 1076
1074 if (NULL == req->join) 1077 i = 0;
1075 req->join = ""; 1078 while (req->outParams[i] != NULL)
1079 {
1080 char *t = xmprintf("%s,%s", select, req->outParams[i]);
1081 free(select);
1082 select = t;
1083 i++;
1084 }
1085 if (0 == i)
1086 {
1087 free(select);
1088 if (count)
1089 select = xmprintf(",Count(*)");
1090 else
1091 select = xmprintf(",*");
1092 }
1076 1093
1077 if (req->where) 1094 if (NULL == req->join)
1078 req->sql = xmprintf("SELECT %s FROM %s %s WHERE %s", &select[1], req->table, req->join, req->where); 1095 req->join = "";
1079 else 1096
1080 req->sql = xmprintf("SELECT %s FROM %s", &select[1], req->table, req->join); 1097 if (req->where)
1081 free(select); 1098 req->sql = xmprintf("SELECT %s FROM %s %s WHERE %s", &select[1], req->table, req->join, req->where);
1082 if (req->order) 1099 else
1083 { 1100 req->sql = xmprintf("SELECT %s FROM %s", &select[1], req->table, req->join);
1084 char *t = xmprintf("%s ORDER BY %s", req->sql, req->order); 1101 free(select);
1102 if (req->order)
1103 {
1104 char *t = xmprintf("%s ORDER BY %s", req->sql, req->order);
1105
1106 free(req->sql);
1107 req->sql = t;
1108 }
1109 break;
1110 }
1111
1112 case CT_CREATE :
1113 {
1114 char *values = xmprintf("");
1115
1116 i = 0;
1117 while (req->inParams[i] != NULL)
1118 {
1119 char *t = xmprintf("%s, %s=?", values, req->inParams[i]);
1120 free(values);
1121 values = t;
1122 i++;
1123 }
1124 if (0 == i)
1125 {
1126 E("Statement prepare for INSERT must have in paramaters.");
1127 ret++;
1128 free(values);
1129 values = xmprintf("");
1130 }
1131 req->sql = xmprintf("INSERT INTO %s SET %s", req->table, &values[1]);
1132 free(values);
1133
1134 break;
1135 }
1085 1136
1086 free(req->sql); 1137 case CT_UPDATE :
1087 req->sql = t; 1138 {
1139 break;
1140 }
1141
1142 case CT_NONE :
1143 {
1144 W("No SQL type!");
1145 break;
1146 }
1088 } 1147 }
1089 1148
1090d("New SQL statement - %s", req->sql); 1149d("New SQL statement - %s", req->sql);
@@ -1095,11 +1154,13 @@ d("New SQL statement - %s", req->sql);
1095 if (NULL == req->prep) 1154 if (NULL == req->prep)
1096 { 1155 {
1097 E("Statement prepare init failed: %s\n", mysql_stmt_error(req->prep)); 1156 E("Statement prepare init failed: %s\n", mysql_stmt_error(req->prep));
1157 ret++;
1098 goto end; 1158 goto end;
1099 } 1159 }
1100 if (mysql_stmt_prepare(req->prep, req->sql, strlen(req->sql))) 1160 if (mysql_stmt_prepare(req->prep, req->sql, strlen(req->sql)))
1101 { 1161 {
1102 E("Statement prepare failed: %s\n", mysql_stmt_error(req->prep)); 1162 E("Statement prepare failed: %s\n", mysql_stmt_error(req->prep));
1163 ret++;
1103 goto end; 1164 goto end;
1104 } 1165 }
1105 1166
@@ -1111,6 +1172,7 @@ d("New SQL statement - %s", req->sql);
1111 if (i != req->inCount) 1172 if (i != req->inCount)
1112 { 1173 {
1113 E("In parameters count don't match %d != %d for - %s", i, req->inCount, req->sql); 1174 E("In parameters count don't match %d != %d for - %s", i, req->inCount, req->sql);
1175 ret++;
1114 goto freeIt; 1176 goto freeIt;
1115 } 1177 }
1116 req->inBind = xzalloc(i * sizeof(MYSQL_BIND)); 1178 req->inBind = xzalloc(i * sizeof(MYSQL_BIND));
@@ -1122,6 +1184,7 @@ W("Allocated %d %d inBinds for %s", i, req->inCount, req->sql);
1122 if (NULL == fld) 1184 if (NULL == fld)
1123 { 1185 {
1124 E("Unknown input field %d %s.%s for - %s", i, req->table, req->inParams[i], req->sql); 1186 E("Unknown input field %d %s.%s for - %s", i, req->table, req->inParams[i], req->sql);
1187 ret++;
1125 goto freeIt; 1188 goto freeIt;
1126 } 1189 }
1127 else 1190 else
@@ -1135,45 +1198,53 @@ W("Allocated %d %d inBinds for %s", i, req->inCount, req->sql);
1135 { 1198 {
1136 case MYSQL_TYPE_TINY: 1199 case MYSQL_TYPE_TINY:
1137 { 1200 {
1201d("TINY %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1138 break; 1202 break;
1139 } 1203 }
1140 1204
1141 case MYSQL_TYPE_SHORT: 1205 case MYSQL_TYPE_SHORT:
1142 { 1206 {
1143 req->inBind[i].is_unsigned = FALSE; 1207 req->inBind[i].is_unsigned = FALSE;
1208d("SHORT %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1144 break; 1209 break;
1145 } 1210 }
1146 1211
1147 case MYSQL_TYPE_INT24: 1212 case MYSQL_TYPE_INT24:
1148 { 1213 {
1149 req->inBind[i].is_unsigned = FALSE; 1214 req->inBind[i].is_unsigned = FALSE;
1215d("INT24 %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1150 break; 1216 break;
1151 } 1217 }
1152 1218
1153 case MYSQL_TYPE_LONG: 1219 case MYSQL_TYPE_LONG:
1154 { 1220 {
1155 req->inBind[i].is_unsigned = FALSE; 1221 req->inBind[i].is_unsigned = FALSE;
1222d("LONG %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1156 break; 1223 break;
1157 } 1224 }
1158 1225
1159 case MYSQL_TYPE_LONGLONG: 1226 case MYSQL_TYPE_LONGLONG:
1160 { 1227 {
1161 req->inBind[i].is_unsigned = FALSE; 1228 req->inBind[i].is_unsigned = FALSE;
1229d("LONGLONG %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1162 break; 1230 break;
1163 } 1231 }
1164 1232
1165 case MYSQL_TYPE_FLOAT: 1233 case MYSQL_TYPE_FLOAT:
1166 { 1234 {
1235d("FLOAT %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1167 break; 1236 break;
1168 } 1237 }
1169 1238
1170 case MYSQL_TYPE_DOUBLE: 1239 case MYSQL_TYPE_DOUBLE:
1171 { 1240 {
1241d("DOUBLE %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1172 break; 1242 break;
1173 } 1243 }
1174 1244
1175 case MYSQL_TYPE_NEWDECIMAL: 1245 case MYSQL_TYPE_NEWDECIMAL:
1176 { 1246 {
1247d("NEWDECIMAL %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1177 break; 1248 break;
1178 } 1249 }
1179 1250
@@ -1182,12 +1253,14 @@ W("Allocated %d %d inBinds for %s", i, req->inCount, req->sql);
1182 case MYSQL_TYPE_DATETIME: 1253 case MYSQL_TYPE_DATETIME:
1183 case MYSQL_TYPE_TIMESTAMP: 1254 case MYSQL_TYPE_TIMESTAMP:
1184 { 1255 {
1256d("DATE / TIME ish %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1185 break; 1257 break;
1186 } 1258 }
1187 1259
1188 case MYSQL_TYPE_STRING: 1260 case MYSQL_TYPE_STRING:
1189 case MYSQL_TYPE_VAR_STRING: 1261 case MYSQL_TYPE_VAR_STRING:
1190 { 1262 {
1263d("STRING / VARSTRING %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1191 req->inBind[i].is_null = xzalloc(sizeof(my_bool)); 1264 req->inBind[i].is_null = xzalloc(sizeof(my_bool));
1192 req->inBind[i].length = xzalloc(sizeof(unsigned long)); 1265 req->inBind[i].length = xzalloc(sizeof(unsigned long));
1193 break; 1266 break;
@@ -1198,6 +1271,7 @@ W("Allocated %d %d inBinds for %s", i, req->inCount, req->sql);
1198 case MYSQL_TYPE_MEDIUM_BLOB: 1271 case MYSQL_TYPE_MEDIUM_BLOB:
1199 case MYSQL_TYPE_LONG_BLOB: 1272 case MYSQL_TYPE_LONG_BLOB:
1200 { 1273 {
1274d("BLOBs %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1201 req->inBind[i].is_null = xzalloc(sizeof(my_bool)); 1275 req->inBind[i].is_null = xzalloc(sizeof(my_bool));
1202 break; 1276 break;
1203 } 1277 }
@@ -1205,11 +1279,13 @@ W("Allocated %d %d inBinds for %s", i, req->inCount, req->sql);
1205 case MYSQL_TYPE_BIT: 1279 case MYSQL_TYPE_BIT:
1206 { 1280 {
1207 req->inBind[i].is_null = xzalloc(sizeof(my_bool)); 1281 req->inBind[i].is_null = xzalloc(sizeof(my_bool));
1282d("BIT %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1208 break; 1283 break;
1209 } 1284 }
1210 1285
1211 case MYSQL_TYPE_NULL: 1286 case MYSQL_TYPE_NULL:
1212 { 1287 {
1288d("NULL %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1213 break; 1289 break;
1214 } 1290 }
1215 } 1291 }
@@ -1217,18 +1293,22 @@ W("Allocated %d %d inBinds for %s", i, req->inCount, req->sql);
1217 } 1293 }
1218 1294
1219// TODO - if this is not a count, setup result bind paramateres, may be needed for counts as well. 1295// TODO - if this is not a count, setup result bind paramateres, may be needed for counts as well.
1220 prepare_meta_result = mysql_stmt_result_metadata(req->prep); 1296 if (CT_SELECT == req->type)
1221 if (!prepare_meta_result)
1222 { 1297 {
1223 D(" mysql_stmt_result_metadata() error %d, returned no meta information - %s\n", mysql_stmt_errno(req->prep), mysql_stmt_error(req->prep)); 1298 prepare_meta_result = mysql_stmt_result_metadata(req->prep);
1224 goto freeIt; 1299 if (!prepare_meta_result)
1300 {
1301 E(" mysql_stmt_result_metadata() error %d, returned no meta information - %s\n", mysql_stmt_errno(req->prep), mysql_stmt_error(req->prep));
1302 ret++;
1303 goto freeIt;
1304 }
1225 } 1305 }
1226 1306
1227 if (count) 1307 if (count)
1228 { 1308 {
1229I("count!!!!!!!!!!!!!!!!"); 1309I("count!!!!!!!!!!!!!!!!");
1230 } 1310 }
1231 else 1311 else if (CT_SELECT == req->type)
1232 { 1312 {
1233 req->outCount = mysql_num_fields(prepare_meta_result); 1313 req->outCount = mysql_num_fields(prepare_meta_result);
1234 i = 0; 1314 i = 0;
@@ -1253,6 +1333,7 @@ I("count!!!!!!!!!!!!!!!!");
1253 if (i != req->outCount) 1333 if (i != req->outCount)
1254 { 1334 {
1255 E("Out parameters count doesn't match %d != %d foqr - %s", i, req->outCount, req->sql); 1335 E("Out parameters count doesn't match %d != %d foqr - %s", i, req->outCount, req->sql);
1336 ret++;
1256 goto freeIt; 1337 goto freeIt;
1257 } 1338 }
1258 req->outBind = xzalloc(i * sizeof(MYSQL_BIND)); 1339 req->outBind = xzalloc(i * sizeof(MYSQL_BIND));
@@ -1264,6 +1345,7 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1264 if (NULL == fld) 1345 if (NULL == fld)
1265 { 1346 {
1266 E("Unknown output field %d %s.%s foqr - %s", i, req->table, req->outParams[i], req->sql); 1347 E("Unknown output field %d %s.%s foqr - %s", i, req->table, req->outParams[i], req->sql);
1348 ret++;
1267 goto freeIt; 1349 goto freeIt;
1268 } 1350 }
1269 else 1351 else
@@ -1306,7 +1388,7 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1306 1388
1307 case MYSQL_TYPE_LONGLONG: 1389 case MYSQL_TYPE_LONGLONG:
1308 { 1390 {
1309//d("LONG LONG %s %d", fld->name, req->outBind[i].buffer_length); 1391//d("LONGLONG %s %d", fld->name, req->outBind[i].buffer_length);
1310 req->outBind[i].is_unsigned = FALSE; 1392 req->outBind[i].is_unsigned = FALSE;
1311 break; 1393 break;
1312 } 1394 }
@@ -1334,14 +1416,14 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1334 case MYSQL_TYPE_DATETIME: 1416 case MYSQL_TYPE_DATETIME:
1335 case MYSQL_TYPE_TIMESTAMP: 1417 case MYSQL_TYPE_TIMESTAMP:
1336 { 1418 {
1337//d("DATETIME %s %d", fld->name, req->outBind[i].buffer_length); 1419//d("DATE / TIME ish %s %d", fld->name, req->outBind[i].buffer_length);
1338 break; 1420 break;
1339 } 1421 }
1340 1422
1341 case MYSQL_TYPE_STRING: 1423 case MYSQL_TYPE_STRING:
1342 case MYSQL_TYPE_VAR_STRING: 1424 case MYSQL_TYPE_VAR_STRING:
1343 { 1425 {
1344//d("STRING %s %d", fld->name, req->outBind[i].buffer_length); 1426//d("STRING / VARSTRING %s %d", fld->name, req->outBind[i].buffer_length);
1345 req->outBind[i].length = xzalloc(sizeof(unsigned long)); 1427 req->outBind[i].length = xzalloc(sizeof(unsigned long));
1346 break; 1428 break;
1347 } 1429 }
@@ -1351,7 +1433,7 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1351 case MYSQL_TYPE_MEDIUM_BLOB: 1433 case MYSQL_TYPE_MEDIUM_BLOB:
1352 case MYSQL_TYPE_LONG_BLOB: 1434 case MYSQL_TYPE_LONG_BLOB:
1353 { 1435 {
1354//d("BLOB %s %d", fld->name, req->outBind[i].buffer_length); 1436//d("BLOBs %s %d", fld->name, req->outBind[i].buffer_length);
1355 break; 1437 break;
1356 } 1438 }
1357 1439
@@ -1371,14 +1453,15 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1371 } 1453 }
1372 if (mysql_stmt_bind_result(req->prep, req->outBind)) 1454 if (mysql_stmt_bind_result(req->prep, req->outBind))
1373 { 1455 {
1374 E("Bind failed error %d.", mysql_stmt_errno(req->prep)); 1456 E("Bind failed error %d.", mysql_stmt_errno(req->prep));
1375 goto freeIt; 1457 ret++;
1458 goto freeIt;
1376 } 1459 }
1377 } 1460 }
1378 } 1461 }
1379 1462
1380 1463
1381//d("input bind for %s", req->sql); 1464d("input bind for %s", req->sql);
1382 for (i = 0; i < req->inCount; i++) 1465 for (i = 0; i < req->inCount; i++)
1383 { 1466 {
1384 dbField *fld = req->flds->get(req->flds, req->inParams[i], NULL, false); 1467 dbField *fld = req->flds->get(req->flds, req->inParams[i], NULL, false);
@@ -1386,6 +1469,7 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1386 if (NULL == fld) 1469 if (NULL == fld)
1387 { 1470 {
1388 E("Unknown input field %s.%s for - %s", req->table, req->inParams[i], req->sql); 1471 E("Unknown input field %s.%s for - %s", req->table, req->inParams[i], req->sql);
1472 ret++;
1389 goto freeIt; 1473 goto freeIt;
1390 } 1474 }
1391 else 1475 else
@@ -1397,7 +1481,8 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1397 int c = va_arg(ap, int); 1481 int c = va_arg(ap, int);
1398 signed char d = (signed char) c; 1482 signed char d = (signed char) c;
1399 1483
1400 memcpy(&d, req->inBind[i].buffer, (size_t) fld->length); 1484 memcpy(req->inBind[i].buffer, &d, (size_t) fld->length);
1485T("TINY %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1401 break; 1486 break;
1402 } 1487 }
1403 1488
@@ -1406,7 +1491,8 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1406 int c = va_arg(ap, int); 1491 int c = va_arg(ap, int);
1407 short int d = (short int) c; 1492 short int d = (short int) c;
1408 1493
1409 memcpy(&d, req->inBind[i].buffer, (size_t) fld->length); 1494 memcpy(req->inBind[i].buffer, &d, (size_t) fld->length);
1495T("SHORT %d %s %d = %d", i, fld->name, req->inBind[i].buffer_length, c);
1410 break; 1496 break;
1411 } 1497 }
1412 1498
@@ -1414,7 +1500,8 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1414 { 1500 {
1415 int d = va_arg(ap, int); 1501 int d = va_arg(ap, int);
1416 1502
1417 memcpy(&d, req->inBind[i].buffer, (size_t) fld->length); 1503 memcpy(req->inBind[i].buffer, &d, (size_t) fld->length);
1504T("INT24 %d %s %d - %d", i, fld->name, req->inBind[i].buffer_length, d);
1418 break; 1505 break;
1419 } 1506 }
1420 1507
@@ -1422,7 +1509,8 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1422 { 1509 {
1423 long d = va_arg(ap, long); 1510 long d = va_arg(ap, long);
1424 1511
1425 memcpy(&d, req->inBind[i].buffer, (size_t) fld->length); 1512 memcpy(req->inBind[i].buffer, &d, (size_t) fld->length);
1513T("LONG %d %s %d = %ld", i, fld->name, req->inBind[i].buffer_length, d);
1426 break; 1514 break;
1427 } 1515 }
1428 1516
@@ -1430,7 +1518,8 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1430 { 1518 {
1431 long long int d = va_arg(ap, long long int); 1519 long long int d = va_arg(ap, long long int);
1432 1520
1433 memcpy(&d, req->inBind[i].buffer, (size_t) fld->length); 1521 memcpy(req->inBind[i].buffer, &d, (size_t) fld->length);
1522T("LONGLONG %d %s %d = %lld", i, fld->name, req->inBind[i].buffer_length, d);
1434 break; 1523 break;
1435 } 1524 }
1436 1525
@@ -1439,7 +1528,8 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1439 double c = va_arg(ap, double); 1528 double c = va_arg(ap, double);
1440 float d = (float) c; 1529 float d = (float) c;
1441 1530
1442 memcpy(&d, req->inBind[i].buffer, (size_t) fld->length); 1531 memcpy(req->inBind[i].buffer, &d, (size_t) fld->length);
1532T("FLOAT %d %s %d = %f", i, fld->name, req->inBind[i].buffer_length, d);
1443 break; 1533 break;
1444 } 1534 }
1445 1535
@@ -1447,12 +1537,14 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1447 { 1537 {
1448 double d = va_arg(ap, double); 1538 double d = va_arg(ap, double);
1449 1539
1450 memcpy(&d, req->inBind[i].buffer, (size_t) fld->length); 1540 memcpy(req->inBind[i].buffer, &d, (size_t) fld->length);
1541T("DOUBLE %d %s %d = %f", i, fld->name, req->inBind[i].buffer_length, d);
1451 break; 1542 break;
1452 } 1543 }
1453 1544
1454 case MYSQL_TYPE_NEWDECIMAL: 1545 case MYSQL_TYPE_NEWDECIMAL:
1455 { 1546 {
1547T("NEWDECIMAL %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1456 break; 1548 break;
1457 } 1549 }
1458 1550
@@ -1463,7 +1555,8 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1463 { 1555 {
1464 MYSQL_TIME d = va_arg(ap, MYSQL_TIME); 1556 MYSQL_TIME d = va_arg(ap, MYSQL_TIME);
1465 1557
1466 memcpy(&d, req->inBind[i].buffer, (size_t) fld->length); 1558 memcpy(req->inBind[i].buffer, &d, (size_t) fld->length);
1559T("DATE / TIME ish %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1467 break; 1560 break;
1468 } 1561 }
1469 1562
@@ -1478,6 +1571,7 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1478 *(req->inBind[i].length) = l; 1571 *(req->inBind[i].length) = l;
1479 strncpy(req->inBind[i].buffer, d, (size_t) l); 1572 strncpy(req->inBind[i].buffer, d, (size_t) l);
1480 ((char *) req->inBind[i].buffer)[l] = '\0'; 1573 ((char *) req->inBind[i].buffer)[l] = '\0';
1574T("STRING / VARSTRING %d %s %d = %s", i, fld->name, req->inBind[i].buffer_length, d);
1481 break; 1575 break;
1482 } 1576 }
1483 1577
@@ -1486,16 +1580,20 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1486 case MYSQL_TYPE_MEDIUM_BLOB: 1580 case MYSQL_TYPE_MEDIUM_BLOB:
1487 case MYSQL_TYPE_LONG_BLOB: 1581 case MYSQL_TYPE_LONG_BLOB:
1488 { 1582 {
1583// TODO - should write this, we will likely need it. Main problem is - how long is this blob? Probably should add alongth param before the blob.
1584T("BLOBs %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1489 break; 1585 break;
1490 } 1586 }
1491 1587
1492 case MYSQL_TYPE_BIT: 1588 case MYSQL_TYPE_BIT:
1493 { 1589 {
1590T("BIT %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1494 break; 1591 break;
1495 } 1592 }
1496 1593
1497 case MYSQL_TYPE_NULL: 1594 case MYSQL_TYPE_NULL:
1498 { 1595 {
1596T("NULL %d %s %d", i, fld->name, req->inBind[i].buffer_length);
1499 break; 1597 break;
1500 } 1598 }
1501 } 1599 }
@@ -1504,6 +1602,7 @@ W("Allocated %d %d outBinds for %s", i, req->outCount, req->sql);
1504 if (mysql_stmt_bind_param(req->prep, req->inBind)) 1602 if (mysql_stmt_bind_param(req->prep, req->inBind))
1505 { 1603 {
1506 E("Bind failed error %d.", mysql_stmt_errno(req->prep)); 1604 E("Bind failed error %d.", mysql_stmt_errno(req->prep));
1605 ret++;
1507 goto freeIt; 1606 goto freeIt;
1508 } 1607 }
1509 1608
@@ -1514,6 +1613,7 @@ d("Execute %s", req->sql);
1514 if (mysql_stmt_execute(req->prep)) 1613 if (mysql_stmt_execute(req->prep))
1515 { 1614 {
1516 E("Statement execute failed %d: %s\n", mysql_stmt_errno(req->prep), mysql_stmt_error(req->prep)); 1615 E("Statement execute failed %d: %s\n", mysql_stmt_errno(req->prep), mysql_stmt_error(req->prep));
1616 ret++;
1517 goto freeIt; 1617 goto freeIt;
1518 } 1618 }
1519 1619
@@ -1526,6 +1626,7 @@ d("Execute %s", req->sql);
1526 if (mysql_stmt_store_result(req->prep)) 1626 if (mysql_stmt_store_result(req->prep))
1527 { 1627 {
1528 E(" mysql_stmt_store_result() failed %d: %s", mysql_stmt_errno(req->prep), mysql_stmt_error(req->prep)); 1628 E(" mysql_stmt_store_result() failed %d: %s", mysql_stmt_errno(req->prep), mysql_stmt_error(req->prep));
1629 ret++;
1529 goto freeIt; 1630 goto freeIt;
1530 } 1631 }
1531 req->rowCount = mysql_stmt_num_rows(req->prep); 1632 req->rowCount = mysql_stmt_num_rows(req->prep);
@@ -1577,6 +1678,7 @@ d("Execute %s", req->sql);
1577 if (NULL == req->outBind[i].buffer) 1678 if (NULL == req->outBind[i].buffer)
1578 { 1679 {
1579 E("Field %d %s is NULL", i, fld->name); 1680 E("Field %d %s is NULL", i, fld->name);
1681 ret++;
1580 goto freeIt; 1682 goto freeIt;
1581 } 1683 }
1582 char *t = xmprintf("%d", (int) *((int *) (req->outBind[i].buffer))); 1684 char *t = xmprintf("%d", (int) *((int *) (req->outBind[i].buffer)));
@@ -1654,7 +1756,10 @@ freeIt:
1654 if (prepare_meta_result) 1756 if (prepare_meta_result)
1655 mysql_free_result(prepare_meta_result); 1757 mysql_free_result(prepare_meta_result);
1656 if (mysql_stmt_free_result(req->prep)) 1758 if (mysql_stmt_free_result(req->prep))
1759 {
1657 E("Statement result freeing failed %d: %s\n", mysql_stmt_errno(req->prep), mysql_stmt_error(req->prep)); 1760 E("Statement result freeing failed %d: %s\n", mysql_stmt_errno(req->prep), mysql_stmt_error(req->prep));
1761 ret++;
1762 }
1658 1763
1659end: 1764end:
1660 va_end(ap); 1765 va_end(ap);
@@ -1673,7 +1778,8 @@ end:
1673 I("The prepared0 statement itself is NOT NULL."); 1778 I("The prepared0 statement itself is NOT NULL.");
1674 else 1779 else
1675 W("The prepared0 statement itself is NULL!"); 1780 W("The prepared0 statement itself is NULL!");
1676 return; 1781
1782 return ret;
1677} 1783}
1678 1784
1679// Copy the SQL results into the request structure. 1785// Copy the SQL results into the request structure.