Skip to content

Commit

Permalink
correct handling for big int types
Browse files Browse the repository at this point in the history
  • Loading branch information
maryryang committed Jan 2, 2024
1 parent 1962df4 commit 34b7891
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions generic/pgtclSqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ Pg_sqlite_bindValue(sqlite3 *sqlite_db, sqlite3_stmt *statement, int column, cha
break;
}
case PG_SQLITE_INT: {
int ival = atoi(value);
char* end;
long ival = strtoul(value, &end, 10);
if(ival == 0) {
// It might be a boolean column mapped to an integer column
ival = Pg_sqlite_toBool(value);
}
if (sqlite3_bind_int(statement, column+1, ival) == SQLITE_OK)
if (sqlite3_bind_int64(statement, column+1, ival) == SQLITE_OK)
return TCL_OK;
break;
}
Expand Down Expand Up @@ -509,8 +510,9 @@ Pg_sqlite_executeCheck(Tcl_Interp *interp, sqlite3 *sqlite_db, sqlite3_stmt *sta
break;
}
case PG_SQLITE_INT: {
int ival = sqlite3_column_int(statement, i);
int rval = atoi(row[i]);
char* end;
long ival = sqlite3_column_int64(statement, i);
long rval = strtoul(row[i], &end, 10);
if(ival != rval) {
status = TCL_OK;
goto cleanup_and_exit;
Expand Down Expand Up @@ -1671,7 +1673,7 @@ Pg_sqlite(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST ob
char *pghandle_name = Tcl_GetString(objv[3]);
int nTuples;
int tupleIndex;
int maxInt = 0;
long maxInt = 0;
double maxFloat = 0.0;
char maxString[BUFSIZ];
int maxValid = 0;
Expand Down Expand Up @@ -1775,7 +1777,8 @@ Pg_sqlite(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST ob
break;
}
case PG_SQLITE_INT: {
int valInt = atoi(val);
char* end;
long valInt = strtoul(val, &end, 10);
if(!maxValid || valInt > maxInt) {
maxInt = valInt;
maxValid = 1;
Expand All @@ -1794,7 +1797,6 @@ Pg_sqlite(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST ob
}
ckfree((void *)columns);
columns = NULL;

if (sqlite3_step(statement) != SQLITE_DONE) {
errorMessage = sqlite3_errmsg(sqlite_db);
returnCode = TCL_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlite3.test
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test pgtcl-sqlite3-1.1 {import postgresql result} -body {
set rows [
pg_sqlite sqlite_conn import_postgres_result $res -create pg_class \
-as {relname text relnamespace integer reltype integer relowner integer} \
-check -pkey {relname}
-check -pkey {relname relnamespace}
]

sqlite_conn eval {select count(*) as count from pg_class;} row {
Expand Down

0 comments on commit 34b7891

Please sign in to comment.