diff options
author | stephan <stephan@noemail.net> | 2025-03-04 21:25:18 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2025-03-04 21:25:18 +0000 |
commit | e34ad2b0b3a18124625c77d65241e7c409258bca (patch) | |
tree | 660e52404e00956a50c30453394fecb427d0888c /src/tclsqlite.c | |
parent | f5965e9d51a8007961ae059e1bac4908c0878afd (diff) | |
download | sqlite-e34ad2b0b3a18124625c77d65241e7c409258bca.tar.gz sqlite-e34ad2b0b3a18124625c77d65241e7c409258bca.zip |
tclsqlite3 patch from Christian Werner: replace FILE handles with TCL channels for the db copy command.
FossilOrigin-Name: ea1f7f8de4abb80fe41a115c9f601ff27cd728493640c6d47d868913feec28dc
Diffstat (limited to 'src/tclsqlite.c')
-rw-r--r-- | src/tclsqlite.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/tclsqlite.c b/src/tclsqlite.c index e249247ca..c619ffca4 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1232,6 +1232,7 @@ static int auth_callback( } #endif /* SQLITE_OMIT_AUTHORIZATION */ +#if 0 /* ** This routine reads a line of text from FILE in, stores ** the text in memory obtained from malloc() and returns a pointer @@ -1276,6 +1277,7 @@ static char *local_getline(char *zPrompt, FILE *in){ zLine = realloc( zLine, n+1 ); return zLine; } +#endif /* @@ -2520,9 +2522,10 @@ static int SQLITE_TCLAPI DbObjCmd( char *zLine; /* A single line of input from the file */ char **azCol; /* zLine[] broken up into columns */ const char *zCommit; /* How to commit changes */ - FILE *in; /* The input file */ + Tcl_Channel in; /* The input file */ int lineno = 0; /* Line number of input file */ char zLineNum[80]; /* Line number print buffer */ + Tcl_DString str; Tcl_Obj *pResult; /* interp result */ const char *zSep; @@ -2601,23 +2604,24 @@ static int SQLITE_TCLAPI DbObjCmd( sqlite3_finalize(pStmt); return TCL_ERROR; } - in = fopen(zFile, "rb"); + in = Tcl_OpenFileChannel(interp, zFile, "rb", 0666); if( in==0 ){ - Tcl_AppendResult(interp, "Error: cannot open file: ", zFile, (char*)0); sqlite3_finalize(pStmt); return TCL_ERROR; } azCol = malloc( sizeof(azCol[0])*(nCol+1) ); if( azCol==0 ) { Tcl_AppendResult(interp, "Error: can't malloc()", (char*)0); - fclose(in); + Tcl_Close(interp, in); return TCL_ERROR; } + Tcl_DStringInit(&str); (void)sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0); zCommit = "COMMIT"; - while( (zLine = local_getline(0, in))!=0 ){ + while( Tcl_Gets(in, &str)>=0 ) { char *z; lineno++; + zLine = Tcl_DStringValue(&str); azCol[0] = zLine; for(i=0, z=zLine; *z; z++){ if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){ @@ -2655,15 +2659,16 @@ static int SQLITE_TCLAPI DbObjCmd( } sqlite3_step(pStmt); rc = sqlite3_reset(pStmt); - free(zLine); + Tcl_DStringSetLength(&str, 0); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp,"Error: ", sqlite3_errmsg(pDb->db), (char*)0); zCommit = "ROLLBACK"; break; } } + Tcl_DStringFree(&str); free(azCol); - fclose(in); + Tcl_Close(interp, in); sqlite3_finalize(pStmt); (void)sqlite3_exec(pDb->db, zCommit, 0, 0, 0); |