mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
tclsqlite3 patch from Christian Werner: replace FILE handles with TCL channels for the db copy command.
FossilOrigin-Name: ea1f7f8de4abb80fe41a115c9f601ff27cd728493640c6d47d868913feec28dc
This commit is contained in:
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user