Changeset 76
- Timestamp:
- 07/22/08 08:48:15 (1 month ago)
- Files:
-
- trunk/php_sqlite3.h (modified) (4 diffs)
- trunk/sqlite3.c (modified) (58 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/php_sqlite3.h
r74 r76 109 109 sqlite3 *db; 110 110 php_sqlite3_func *funcs; 111 } php_sqlite3_db_object; 111 112 112 zend_llist stmt_list; 113 } php_sqlite3_db_object; 113 /*typedef struct _php_sqlite3_stmt { 114 sqlite3_stmt *stmt; 115 int initialised; 116 } php_sqlite3_stmt;*/ 114 117 115 118 /* sqlite3 objects to be destroyed */ … … 124 127 typedef struct _php_sqlite3_result_object { 125 128 zend_object zo; 126 sqlite3_stmt * *intern_stmt;129 sqlite3_stmt *intern_stmt; 127 130 php_sqlite3_db_object *db_obj; 128 131 int initialised; … … 130 133 int is_prepared_statement; 131 134 int complete; 132 int buffered;133 134 long num_rows;135 135 } php_sqlite3_result; 136 136 … … 141 141 php_sqlite3_db_object *db_obj; 142 142 int initialised; 143 143 144 144 /* Keep track of the zvals for bound parameters */ 145 145 HashTable *bound_params; trunk/sqlite3.c
r74 r76 40 40 static int php_sqlite3_compare_stmt_free( php_sqlite3_stmt_free_list **stmt_list, sqlite3_stmt *statement ); 41 41 42 #define SQLITE3_CHECK_INITIALIZED(member, class_name) \ 43 if (!(member)) { \ 44 php_error_docref(NULL TSRMLS_CC, E_WARNING, "The " #class_name " object has not been correctly initialised"); \ 45 RETURN_FALSE; \ 46 } 47 42 48 /* {{{ PHP_INI 43 49 */ … … 148 154 } 149 155 150 zend_llist_clean(&(db_obj->stmt_list));151 156 if (db_obj->initialised) { 152 157 errcode = sqlite3_close(db_obj->db); … … 173 178 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 174 179 180 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 181 175 182 if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", 176 183 &sql, &sql_len)) { … … 215 222 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 216 223 224 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 225 217 226 if (ZEND_NUM_ARGS() != 0) { 218 227 WRONG_PARAM_COUNT; … … 232 241 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 233 242 243 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 244 234 245 if (ZEND_NUM_ARGS() != 0) { 235 246 WRONG_PARAM_COUNT; … … 248 259 zval *object = getThis(); 249 260 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 261 262 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 250 263 251 264 if (ZEND_NUM_ARGS() != 0) { … … 268 281 int extension_len, extension_dir_len; 269 282 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 283 284 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 270 285 271 286 if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", … … 329 344 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 330 345 346 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 347 331 348 if (ZEND_NUM_ARGS() != 0) { 332 349 WRONG_PARAM_COUNT; … … 342 359 PHP_METHOD(sqlite3, escapeString) 343 360 { 344 php_sqlite3_db_object *db_obj;345 zval *object = getThis();346 361 char *sql, *ret; 347 362 int sql_len; 348 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);349 363 350 364 if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", … … 371 385 { 372 386 php_sqlite3_db_object *db_obj; 373 php_sqlite3_stmt * internp;387 php_sqlite3_stmt *stmt_obj; 374 388 zval *object = getThis(); 375 389 char *sql; … … 377 391 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 378 392 393 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 394 379 395 if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", 380 396 &sql, &sql_len)) { … … 387 403 388 404 object_init_ex(return_value, php_sqlite3_stmt_entry); 389 internp= (php_sqlite3_stmt *)zend_object_store_get_object(return_value TSRMLS_CC);390 internp->db_obj = db_obj;391 392 errcode = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &( internp->stmt), NULL);405 stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(return_value TSRMLS_CC); 406 stmt_obj->db_obj = db_obj; 407 408 errcode = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &(stmt_obj->stmt), NULL); 393 409 if (errcode != SQLITE_OK) { 394 410 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to prepare statement: %d, %s", errcode, sqlite3_errmsg(db_obj->db)); 411 zval_dtor(return_value); 395 412 RETURN_FALSE; 396 413 } … … 409 426 int sql_len, return_code; 410 427 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 428 429 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 411 430 412 431 if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", … … 432 451 result->db_obj = db_obj; 433 452 434 return_code = sqlite3_prepare_v2(db_obj->db, sql, sql_len, result->intern_stmt, NULL);453 return_code = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &(result->intern_stmt), NULL); 435 454 if (return_code != SQLITE_OK) { 436 455 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to prepare statement: %d, %s", return_code, sqlite3_errmsg(db_obj->db)); 437 efree(result->intern_stmt);438 456 result->intern_stmt = NULL; 439 457 RETURN_FALSE; 440 458 } 441 459 442 443 return_code = sqlite3_step(*(result->intern_stmt)); 444 result->num_rows = 0; 460 result->initialised = 1; 461 return_code = sqlite3_step(result->intern_stmt); 445 462 446 463 switch (return_code) { 447 464 case SQLITE_ROW: /* Valid Row */ 448 {449 #ifdef scottmac_0450 /* loop through to fill numRows */451 do452 {453 result->num_rows++;454 } while (sqlite3_step(*(result->intern_stmt)) == SQLITE_ROW);455 #endif456 }457 /* No break is intentional */458 465 case SQLITE_DONE: /* Valid but no results */ 459 466 { 460 php_sqlite3_stmt_free_list *free_item;467 /*php_sqlite3_stmt_free_list *free_item; 461 468 free_item = emalloc(sizeof(php_sqlite3_stmt_free_list)); 462 free_item->stmt = *(result->intern_stmt);469 free_item->stmt = result->intern_stmt; 463 470 free_item->statement_object = NULL; 464 471 free_item->result_object = return_value; 465 Z_ADDREF_P(return_value);466 zend_llist_add_element(&(db_obj->stmt_list), &free_item); 467 sqlite3_reset( *(result->intern_stmt));472 //Z_ADDREF_P(return_value); 473 zend_llist_add_element(&(db_obj->stmt_list), &free_item);*/ 474 sqlite3_reset(result->intern_stmt); 468 475 break; 469 476 } 470 477 default: 471 478 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db)); 472 sqlite3_finalize(*(result->intern_stmt)); 479 sqlite3_finalize(result->intern_stmt); 480 zval_dtor(return_value); 473 481 RETURN_FALSE; 474 482 } … … 519 527 sqlite3_stmt *stmt; 520 528 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 529 530 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 521 531 522 532 if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", … … 763 773 long sql_func_num_args = -1; 764 774 775 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 776 765 777 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 766 778 … … 813 825 zval *step_callback, *fini_callback; 814 826 long sql_func_num_args = -1; 815 816 827 db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); 828 829 SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) 817 830 818 831 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "szz|l", &sql_func, &sql_func_len, &step_callback, &fini_callback, &sql_func_num_args) == FAILURE) { … … 868 881 PHP_METHOD(sqlite3_stmt, paramCount) 869 882 { 870 php_sqlite3_stmt *internp; 871 zval *object = getThis(); 872 873 internp = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 883 php_sqlite3_stmt *stmt_obj; 884 zval *object = getThis(); 885 stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 874 886 875 887 if (ZEND_NUM_ARGS() != 0) { … … 877 889 } 878 890 879 RETURN_LONG(sqlite3_bind_parameter_count( internp->stmt));891 RETURN_LONG(sqlite3_bind_parameter_count(stmt_obj->stmt)); 880 892 } 881 893 /* }}} */ … … 886 898 PHP_METHOD(sqlite3_stmt, close) 887 899 { 888 php_sqlite3_stmt *internp; 889 zval *object = getThis(); 890 891 internp = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 900 php_sqlite3_stmt *stmt_obj; 901 zval *object = getThis(); 902 stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 892 903 893 904 if (ZEND_NUM_ARGS() != 0) { … … 895 906 } 896 907 897 zend_llist_del_element(&(internp->db_obj->stmt_list), internp->stmt,898 (int (*)(void *, void *)) php_sqlite3_compare_stmt_free); 908 /*zend_llist_del_element(&(stmt_obj->db_obj->stmt_list), stmt_obj->stmt, 909 (int (*)(void *, void *)) php_sqlite3_compare_stmt_free);*/ 899 910 900 911 RETURN_TRUE; … … 907 918 PHP_METHOD(sqlite3_stmt, reset) 908 919 { 909 php_sqlite3_stmt *internp; 910 zval *object = getThis(); 911 912 internp = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 920 php_sqlite3_stmt *stmt_obj; 921 zval *object = getThis(); 922 stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 913 923 914 924 if (ZEND_NUM_ARGS() != 0) { … … 916 926 } 917 927 918 if (sqlite3_reset( internp->stmt) != SQLITE_OK) {919 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle( internp->stmt)));928 if (sqlite3_reset(stmt_obj->stmt) != SQLITE_OK) { 929 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); 920 930 RETURN_FALSE; 921 931 } … … 929 939 PHP_METHOD(sqlite3_stmt, clear) 930 940 { 931 php_sqlite3_stmt *internp; 932 zval *object = getThis(); 933 934 internp = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 941 php_sqlite3_stmt *stmt_obj; 942 zval *object = getThis(); 943 stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 935 944 936 945 if (ZEND_NUM_ARGS() != 0) { … … 938 947 } 939 948 940 if (sqlite3_clear_bindings( internp->stmt) != SQLITE_OK) {941 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle( internp->stmt)));949 if (sqlite3_clear_bindings(stmt_obj->stmt) != SQLITE_OK) { 950 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); 942 951 RETURN_FALSE; 943 952 } … … 946 955 } 947 956 /* }}} */ 948 949 #if scottmac_0950 /* {{{ proto bool SQLite3_stmt::bind_params(string types, mixed variable [,mixed,....])951 Bind Paramater to a stmt variable952 */953 PHP_METHOD(sqlite3_stmt, bind_params)954 {955 php_sqlite3_stmt *internp;956 zval *object = getThis();957 int argc = ZEND_NUM_ARGS();958 char *types;959 int types_len, num_varargs, i, ofs = 0;960 zval ***varargs = NULL;961 962 internp = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);963 964 if (argc < 2) {965 WRONG_PARAM_COUNT;966 }967 968 if (zend_parse_parameters(1 TSRMLS_CC, "s",969 &types, &types_len) == FAILURE) {970 return;971 }972 973 num_varargs = argc - 1;974 975 if (!types_len) {976 php_error_docref(NULL TSRMLS_CC, E_WARNING, "No parameter types specified");977 RETURN_FALSE;978 }979 980 if (types_len != num_varargs) {981 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of parameter types specified does not match number of bind variables");982 RETURN_FALSE;983 }984 985 if (types_len != sqlite3_bind_parameter_count(internp->stmt)) {986 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of bind variables does not match number of parameters in prepared statement");987 RETURN_FALSE;988 }989 990 varargs = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);991 992 if (zend_get_parameters_array_ex(argc, varargs) == FAILURE) {993 zend_wrong_param_count(TSRMLS_C);994 efree(varargs);995 RETURN_FALSE;996 }997 998 for (i = 1; i <= sqlite3_bind_parameter_count(internp->stmt); i++) {999 switch (types[ofs]) {1000 case 'i': /* Integer */1001 sqlite3_bind_int(internp->stmt, i, Z_LVAL_PP(varargs[i]));1002 break;1003 1004 case 'd': /* double */1005 sqlite3_bind_double(internp->stmt, i, Z_DVAL_PP(varargs[i]));1006 break;1007 1008 case 'b': /* blob */1009 case 's': /* string */1010 sqlite3_bind_text(internp->stmt, i, Z_STRVAL_PP(varargs[i]), Z_STRLEN_PP(varargs[i]), SQLITE_STATIC);1011 break;1012 1013 case 'n': /* null */1014 sqlite3_bind_null(internp->stmt, i);1015 break;1016 1017 }1018 ofs++;1019 }1020 1021 efree(varargs);1022 RETURN_TRUE;1023 }1024 /* }}} */1025 #endif1026 957 1027 958 static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param *param, php_sqlite3_stmt *stmt TSRMLS_DC) /* {{{ */ … … 1075 1006 PHP_METHOD(sqlite3_stmt, bindParam) 1076 1007 { 1077 php_sqlite3_stmt * internp;1008 php_sqlite3_stmt *stmt_obj; 1078 1009 zval *object = getThis(); 1079 1010 struct php_sqlite3_bound_param param = {0}; 1080 internp= (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);1011 stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 1081 1012 1082 1013 param.param_number = -1; … … 1093 1024 Z_ADDREF_P(param.parameter); 1094 1025 1095 if (!register_bound_parameter_to_sqlite(¶m, internpTSRMLS_CC)) {1026 if (!register_bound_parameter_to_sqlite(¶m, stmt_obj TSRMLS_CC)) { 1096 1027 if (param.parameter) { 1097 1028 zval_ptr_dtor(&(param.parameter)); … … 1109 1040 PHP_METHOD(sqlite3_stmt, bindValue) 1110 1041 { 1111 php_sqlite3_stmt * internp;1042 php_sqlite3_stmt *stmt_obj; 1112 1043 zval *object = getThis(); 1113 1044 struct php_sqlite3_bound_param param = {0}; 1114 internp= (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);1045 stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 1115 1046 1116 1047 param.param_number = -1; … … 1127 1058 Z_ADDREF_P(param.parameter); 1128 1059 1129 if (!register_bound_parameter_to_sqlite(¶m, internpTSRMLS_CC)) {1060 if (!register_bound_parameter_to_sqlite(¶m, stmt_obj TSRMLS_CC)) { 1130 1061 if (param.parameter) { 1131 1062 zval_ptr_dtor(&(param.parameter)); … … 1143 1074 PHP_METHOD(sqlite3_stmt, execute) 1144 1075 { 1145 php_sqlite3_stmt * internp;1076 php_sqlite3_stmt *stmt_obj; 1146 1077 php_sqlite3_result *result; 1147 1078 zval *object = getThis(); 1148 int return_code = 0 , num_rows = 0;1079 int return_code = 0; 1149 1080 struct php_sqlite3_bound_param *param; 1150 internp= (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);1081 stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); 1151 1082 1152 1083 if (ZEND_NUM_ARGS() != 0) { … … 1154 1085 } 1155 1086 1156 if ( internp->bound_params) {1157 zend_hash_internal_pointer_reset( internp->bound_params);1158 while (zend_hash_get_current_data( internp->bound_params, (void **)¶m) == SUCCESS) {1087 if (stmt_obj->bound_params) { 1088 zend_hash_internal_pointer_reset(stmt_obj->bound_params); 1089 while (zend_hash_get_current_data(stmt_obj->bound_params, (void **)¶m) == SUCCESS) { 1159 1090 /* If the ZVAL is null then it should be bound as that */ 1160 1091 if (Z_TYPE_P(param->parameter) == IS_NULL) { 1161 sqlite3_bind_null( internp->stmt, param->param_number);1092 sqlite3_bind_null(stmt_obj->stmt, param->param_number); 1162 1093 continue; 1163 1094 } … … 1166 1097 case SQLITE_INTEGER: 1167 1098 convert_to_long(param->parameter); 1168 sqlite3_bind_int( internp->stmt, param->param_number, Z_LVAL_P(param->parameter));1099 sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(param->parameter)); 1169 1100 break; 1170 1101 1171 1102 case SQLITE_FLOAT: 1172 1103 /* convert_to_double(param->parameter);*/ 1173 sqlite3_bind_double( internp->stmt, param->param_number, Z_DVAL_P(param->parameter));1104 sqlite3_bind_double(stmt_obj->stmt, param->param_number, Z_DVAL_P(param->parameter)); 1174 1105 break; 1175 1106 … … 1192 1123 } 1193 1124 1194 sqlite3_bind_blob( internp->stmt, param->param_number, buffer, blength, SQLITE_TRANSIENT);1125 sqlite3_bind_blob(stmt_obj->stmt, param->param_number, buffer, blength, SQLITE_TRANSIENT); 1195 1126 1196 1127 if (stream) { … … 1202 1133 case SQLITE3_TEXT: 1203 1134 convert_to_string(param->parameter); 1204 sqlite3_bind_text( internp->stmt, param->param_number, Z_STRVAL_P(param->parameter), Z_STRLEN_P(param->parameter), SQLITE_STATIC);1135 sqlite3_bind_text(stmt_obj->stmt, param->param_number, Z_STRVAL_P(param->parameter), Z_STRLEN_P(param->parameter), SQLITE_STATIC); 1205 1136 break; 1206 1137 1207 1138 case SQLITE_NULL: 1208 sqlite3_bind_null( internp->stmt, param->param_number);1139 sqlite3_bind_null(stmt_obj->stmt, param->param_number); 1209 1140 break; 1210 1141 … … 1213 1144 RETURN_FALSE; 1214 1145 } 1215 zend_hash_move_forward( internp->bound_params);1216 } 1217 } 1218 1219 return_code = sqlite3_step( internp->stmt);1146 zend_hash_move_forward(stmt_obj->bound_params); 1147 } 1148 } 1149 1150 return_code = sqlite3_step(stmt_obj->stmt); 1220 1151 1221 1152 switch (return_code) { 1222 1153 case SQLITE_ROW: /* Valid Row */ 1223 #ifdef scottmac_01224 /* loop through to fill numRows */1225 do1226 {1227 num_rows++;1228 } while (sqlite3_step(internp->stmt) == SQLITE_ROW);1229 #endif1230 1154 case SQLITE_DONE: /* Valid but no results */ 1231 1155 { 1232 php_sqlite3_stmt_free_list *free_item; 1233 1234 sqlite3_reset(internp->stmt); 1156 sqlite3_reset(stmt_obj->stmt); 1235 1157 object_init_ex(return_value, php_sqlite3_result_entry); 1236 1158 result = (php_sqlite3_result *)zend_object_store_get_object(return_value TSRMLS_CC); 1237 1159 1238 free_item = emalloc(sizeof(php_sqlite3_stmt_free_list)); 1239 free_item->stmt = internp->stmt; 1240 free_item->statement_object = object; 1241 free_item->result_object = return_value; 1242 Z_ADDREF_P(object); 1243 Z_ADDREF_P(return_value); 1244 1245 zend_llist_add_element(&(internp->db_obj->stmt_list), &free_item); 1246 /* We don't need the default one that came with it now */ 1247 1248 efree(result->intern_stmt); 1160 zend_objects_store_add_ref(object TSRMLS_CC); 1161 1249 1162 result->is_prepared_statement = 1; 1250 result->in tern_stmt = &internp->stmt;1251 result-> num_rows = num_rows;1252 result->db_obj = internp->db_obj;1163 result->initialised = 1; 1164 result->intern_stmt = stmt_obj->stmt; 1165 result->db_obj = stmt_obj->db_obj; 1253 1166 break; 1254 1167 } 1255 1168 case SQLITE_ERROR: 1256 sqlite3_reset( internp->stmt);1169 sqlite3_reset(stmt_obj->stmt); 1257 1170 1258 1171 default: 1259 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(internp->stmt))); 1172 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); 1173 zval_dtor(return_value); 1260 1174 RETURN_FALSE; 1261 1175 } … … 1270 1184 PHP_METHOD(sqlite3_result, numColumns) 1271 1185 { 1272 php_sqlite3_result *internp; 1273 zval *object = getThis(); 1274 internp = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1186 php_sqlite3_result *result_obj; 1187 zval *object = getThis(); 1188 result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1189 1190 SQLITE3_CHECK_INITIALIZED(result_obj->initialised, SQLite3_result) 1275 1191 1276 1192 if (ZEND_NUM_ARGS() != 0) { … … 1278 1194 } 1279 1195 1280 RETURN_LONG(sqlite3_column_count( *(internp->intern_stmt)));1196 RETURN_LONG(sqlite3_column_count(result_obj->intern_stmt)); 1281 1197 } 1282 1198 /* }}} */ … … 1287 1203 PHP_METHOD(sqlite3_result, columnName) 1288 1204 { 1289 php_sqlite3_result * internp;1205 php_sqlite3_result *result_obj; 1290 1206 zval *object = getThis(); 1291 1207 int column = 0; 1292 internp = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1208 result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1209 1210 SQLITE3_CHECK_INITIALIZED(result_obj->initialised, SQLite3_result) 1293 1211 1294 1212 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &column) == FAILURE) { … … 1296 1214 } 1297 1215 1298 RETVAL_STRING((char *)sqlite3_column_name( *(internp->intern_stmt), column), 1);1216 RETVAL_STRING((char *)sqlite3_column_name(result_obj->intern_stmt, column), 1); 1299 1217 } 1300 1218 /* }}} */ … … 1305 1223 PHP_METHOD(sqlite3_result, columnType) 1306 1224 { 1307 php_sqlite3_result * internp;1225 php_sqlite3_result *result_obj; 1308 1226 zval *object = getThis(); 1309 1227 int column = 0; 1310 internp = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1228 result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1229 1230 SQLITE3_CHECK_INITIALIZED(result_obj->initialised, SQLite3_result) 1311 1231 1312 1232 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &column) == FAILURE) { … … 1314 1234 } 1315 1235 1316 RETURN_LONG(sqlite3_column_type( *(internp->intern_stmt), column));1236 RETURN_LONG(sqlite3_column_type(result_obj->intern_stmt, column)); 1317 1237 } 1318 1238 /* }}} */ … … 1323 1243 PHP_METHOD(sqlite3_result, fetchArray) 1324 1244 { 1325 php_sqlite3_result * internp;1245 php_sqlite3_result *result_obj; 1326 1246 zval *object = getThis(); 1327 1247 int i, ret, mode = PHP_SQLITE3_BOTH; 1328 internp = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1248 result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1249 1250 SQLITE3_CHECK_INITIALIZED(result_obj->initialised, SQLite3_result) 1329 1251 1330 1252 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mode) == FAILURE) { … … 1332 1254 } 1333 1255 1334 if ( internp->complete == 1) {1335 RETURN_FALSE; 1336 } 1337 1338 ret = sqlite3_step( *(internp->intern_stmt));1256 if (result_obj->complete == 1) { 1257 RETURN_FALSE; 1258 } 1259 1260 ret = sqlite3_step(result_obj->intern_stmt); 1339 1261 switch (ret) { 1340 1262 case SQLITE_ROW: … … 1346 1268 array_init(return_value); 1347 1269 1348 for (i = 0; i < sqlite3_data_count( *(internp->intern_stmt)); i++) {1270 for (i = 0; i < sqlite3_data_count(result_obj->intern_stmt); i++) { 1349 1271 zval *data; 1350 1272 1351 data = sqlite_value_to_zval( *(internp->intern_stmt), i);1273 data = sqlite_value_to_zval(result_obj->intern_stmt, i); 1352 1274 1353 1275 if (mode & PHP_SQLITE3_NUM) { … … 1359 1281 Z_ADDREF_P(data); 1360 1282 } 1361 add_assoc_zval(return_value, (char*)sqlite3_column_name( *(internp->intern_stmt), i), data);1283 add_assoc_zval(return_value, (char*)sqlite3_column_name(result_obj->intern_stmt, i), data); 1362 1284 } 1363 1285 } … … 1365 1287 case SQLITE_DONE: 1366 1288 /* Can't call sqlite3_step again, so store the value */ 1367 internp->complete = 1;1289 result_obj->complete = 1; 1368 1290 RETURN_FALSE; 1369 1291 1370 1292 default: 1371 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle( *(internp->intern_stmt))));1293 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->intern_stmt))); 1372 1294 } 1373 1295 } … … 1379 1301 PHP_METHOD(sqlite3_result, reset) 1380 1302 { 1381 php_sqlite3_result *internp; 1382 zval *object = getThis(); 1383 internp = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1303 php_sqlite3_result *result_obj; 1304 zval *object = getThis(); 1305 result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1306 1307 SQLITE3_CHECK_INITIALIZED(result_obj->initialised, SQLite3_result) 1384 1308 1385 1309 if (ZEND_NUM_ARGS() != 0) { … … 1387 1311 } 1388 1312 1389 if (sqlite3_reset( *(internp->intern_stmt)) != SQLITE_OK) {1390 RETURN_FALSE; 1391 } 1392 1393 internp->complete = 0;1313 if (sqlite3_reset(result_obj->intern_stmt) != SQLITE_OK) { 1314 RETURN_FALSE; 1315 } 1316 1317 result_obj->complete = 0; 1394 1318 1395 1319 RETURN_TRUE; … … 1397 1321 /* }}} */ 1398 1322 1399 #ifdef scottmac_0 1400 /* {{{ proto bool SQLite3_result::numRows() 1401 Returns the number of rows in a result set 1402 */ 1403 PHP_METHOD(sqlite3_result, numRows) 1404 { 1405 php_sqlite3_result *internp; 1406 zval *object = getThis(); 1407 internp = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1323 /* {{{ proto bool SQLite3_result::finalize() 1324 Closes the result set 1325 */ 1326 PHP_METHOD(sqlite3_result, finalize) 1327 { 1328 php_sqlite3_result *result_obj; 1329 zval *object = getThis(); 1330 result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); 1331 1332 SQLITE3_CHECK_INITIALIZED(result_obj->initialised, SQLite3_result) 1408 1333 1409 1334 if (ZEND_NUM_ARGS() != 0) { 1410 1335 WRONG_PARAM_COUNT; 1411 1336 } 1412 RETURN_LONG(internp->num_rows);1413 }1414 /* }}} */1415 #endif1416 1417 /* {{{ proto bool SQLite3_result::finalize()1418 Closes the result set1419 */1420 PHP_METHOD(sqlite3_result, finalize)1421 {1422 php_sqlite3_result *internp;1423 zval *object = getThis();1424 internp = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC);1425 1426 if (ZEND_NUM_ARGS() != 0) {1427 WRONG_PARAM_COUNT;1428 }1429 1337 1430 1338 /* We need to finalize an internal statement */ 1431 if ( internp->is_prepared_statement == 0) {1432 zend_llist_del_element(&(internp->db_obj->stmt_list), *(internp->intern_stmt),1433 (int (*)(void *, void *)) php_sqlite3_compare_stmt_free);1339 if (result_obj->is_prepared_statement == 0) { 1340 result_obj->initialised = 0; 1341 sqlite3_finalize(result_obj->intern_stmt); 1434 1342 } else { 1435 sqlite3_reset(*(internp->intern_stmt)); 1436 } 1437 1438 /*zval_dtor(object); 1439 ZVAL_NULL(object);*/ 1343 sqlite3_reset(result_obj->intern_stmt); 1344 } 1440 1345 1441 1346 RETURN_TRUE; … … 1577 1482 ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_result_reset, 0) 1578 1483 ZEND_END_ARG_INFO() 1579 1580 #ifdef scottmac_01581 static1582 ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_result_numrows, 0)1583 ZEND_END_ARG_INFO()1584 #endif1585 1484 1586 1485 static … … 1620 1519 PHP_ME(sqlite3_stmt, clear, arginfo_sqlite3_stmt_clear, ZEND_ACC_PUBLIC) 1621 1520 PHP_ME(sqlite3_stmt, execute, arginfo_sqlite3_stmt_execute, ZEND_ACC_PUBLIC) 1622 #if scottmac_01623 PHP_ME(sqlite3_stmt, bind_params, NULL, ZEND_ACC_PUBLIC)1624 #endif1625 1521 PHP_ME(sqlite3_stmt, bindParam, arginfo_sqlite3_stmt_bindparam, ZEND_ACC_PUBLIC) 1626 1522 PHP_ME(sqlite3_stmt, bindValue, arginfo_sqlite3_stmt_bindvalue, ZEND_ACC_PUBLIC) … … 1636 1532 PHP_ME(sqlite3_result, fetchArray, arginfo_sqlite3_result_fetcharray, ZEND_ACC_PUBLIC) 1637 1533 PHP_ME(sqlite3_result, reset, arginfo_sqlite3_result_reset, ZEND_ACC_PUBLIC) 1638 #ifdef scottmac_01639 PHP_ME(sqlite3_result, numRows, arginfo_sqlite3_result_numrows, ZEND_ACC_PUBLIC)1640 #endif1641 1534 PHP_ME(sqlite3_result, finalize, arginfo_sqlite3_result_finalize, ZEND_ACC_PUBLIC) 1642 1535 … … 1707 1600 func = intern->funcs; 1708 1601 intern->funcs = func->next; 1709 if (intern-> db) {1602 if (intern->initialised && intern->db) { 1710 1603 sqlite3_create_function(intern->db, func->func_name, func->argc, SQLITE_UTF8, func, NULL, NULL, NULL); 1711 1604 } … … 1725 1618 } 1726 1619 1727 zend_llist_clean(&(intern->stmt_list)); 1728 1729 if (intern->db) { 1620 if (intern->initialised && intern->db) { 1730 1621 sqlite3_close(intern->db); 1731 intern-> db = NULL;1622 intern->initialised = 0; 1732 1623 } 1733 1624 … … 1768 1659 1769 1660 if (intern->intern_stmt) { 1770 sqlite3_reset( *(intern->intern_stmt));1661 sqlite3_reset(intern->intern_stmt); 1771 1662 } 1772 1663 1773 1664 /* The result set occured from a straight execute statement */ 1774 1665 if (intern->intern_stmt && intern->is_prepared_statement == 0) { 1775 sqlite3_finalize(*(intern->intern_stmt)); 1776 efree(intern->intern_stmt); 1666 sqlite3_finalize(intern->intern_stmt); 1777 1667 } 1778 1668 … … 1793 1683 memset(&intern->zo, 0, sizeof(php_sqlite3_db_object)); 1794 1684 1795 /* Non standard stuff, not sure if this is really required still */1796 zend_llist_init(&(intern->stmt_list), sizeof(php_sqlite3_stmt_free_list *), (llist_dtor_func_t)php_sqlite3_stmt_free, 0); 1685 /* Non standard stuff, not sure if this is really required still 1686 zend_llist_init(&(intern->stmt_list), sizeof(php_sqlite3_stmt_free_list *), (llist_dtor_func_t)php_sqlite3_stmt_free, 0);*/ 1797 1687 1798 1688 zend_object_std_init(&intern->zo, class_type TSRMLS_CC); … … 1834 1724 memset(&intern->zo, 0, sizeof(php_sqlite3_result)); 1835 1725 1836 intern->intern_stmt = emalloc(sizeof(sqlite3_stmt *)); 1837 intern->buffered = 0; 1726 intern->intern_stmt = NULL; 1838 1727 intern->complete = 0; 1839 1728 intern->is_prepared_statement = 0; 1840 intern->num_rows = 0;1841 1729 1842 1730 zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
