content: counter(section) "." counter(h2counter) "." counter(h3counter) "." counter(h4counter) " ";
}
</style>
+<img class="logo" src="https://sqlite.org/images/sqlite370_banner.gif"
+ alt="SQLite" border="0"/>
<h1>CLI Shell Extensibility</h1>
<hr/>
<h3>New or Revised Import Modes</h3>
<p>The ways in which data may be imported to a DB table
may be augmented or overriden. Once that is done, the .import
- meta-command will either have a new option to specify a new
- import handler or an existing .import option can be used for this.
+ meta-command will either have a new option to specify a new import
+ handler or an existing .import option can be overridden for this.
<h3>New or Revised Query Result Handling</h3>
<p>The display formatting or other disposition of query results
may be augmented or overriden. Once that is done, the .mode
- meta-command will either have a new option to specify a new
- result handler or an existing .mode option can be used for this.
+ meta-command will either have a new option to specify a new result
+ handler or an existing .mode option can be overridden for this.
<h3>Generalized Import Modes and Query Result Handling</h3>
<p>New handlers added via extension are not restricted to
and shell extensions written in C/C++.
Comments in that header tersely summarize these explanations:
- <h3>struct ShellStateX</h3>
- <p>This struct consists of a public portion, which is available and
+ <h3>struct ShellStateX and ShellExState</h3>
+ <p>The ShellStateX object, (maintained by the shell and known as
+ shellState), consists of a public portion, which is available and
stable for use in shell/extension interactions, and a private
portion which may not be stable. Shell extension code used only for
build-time extension might use the private part, (to which it has
access because such code is compiled within the same translation unit
as the core shell code), but such usage generally precludes (or makes
- hazardous) use of a runtime loadable extension built from the same code.
+ hazardous) use of runtime loadable extensions built from such code.
<h3>ExtensionId typedef and eid Member</h3>
<p>An object of this type serves to uniquely identify an extension
by the sqlite3_X_init() function if the extension DLL is ever
to be unloaded during that shell session.
- <h3>extensionDtor member</h3>
+ <h3>ShellExState typedef</h3>
+ <p>An object of this type is passed between the shell core and its
+ import or query result handlers to: (1) convey or keep parameters and
+ data related to formatting or parsing data rows in an external form;
+ (2) keep state associated with the progression of an import or result
+ handling operation from initiation to completion; (3) to facilitate
+ access to exposed shell state generally useful to such handlers or
+ meta-commands; or (4) to provide for abnormal shell exits.
+ <p>The shell core .mode and .import implementations also use the same
+ instance of this type to affect result output and import operations.
+ That instance resides in a ShellStateX object kept by the shell so
+ that extension meta-commands can access it, possibly to change it.
+ Meta-commands or handlers which alter this instance for their own
+ purposes (rather than for intended effect) should take care to
+ restore its prior value as the operation completes.
+
+ <h3>extensionDestruct member</h3>
<p>The function addressed by this member will be called prior to
the extension being unloaded (if the pointer is non-zero.)
This is an out parameter from the sqlite3_X_init() function.
It may perform any cleanup or deallocations necessitated by
- successful initialization (and will never be called after
- failed initialization.)
+ successful initialization generally (and will never be called
+ after failed initialization.)
<h3>Notes Regarding Object Interfaces for C vs C++ Writers</h3>
<p>The objects registered with the shell core to provided extension
functionality may be implemented in C or C++ (or anything else
producing the same ABI.) In the below descriptions of their
interfaces, it should be understood that: C++ implementations
- will not need to explicitly deal with anything like a WhatsitVtable
+ need not explicitly deal with anything like a Whatsit_Vtable
struct and will refer to the object pointer, passed implicitly,
as "this"; and C implementations will need to populate a static
- WhatsitVtable and refer to the initial object pointer as "pThis".
+ Whatsit_Vtable and refer to the initial object pointer as "pThis".
+ <p>All shell extension interfaces have a method, destruct(), which
+ is (or may be) called by the shell core prior to deactivating any
+ registered meta-command, output result or import handler.
+ This call will be made in addition to any automatic (or implicit)
+ takedown that may occur due to atexit() or C++ destructor calls,
+ so destruct()'s responsibility should be limited to reversing
+ the per-registered-object effects of sqlite3_X_init().
+ <p>A registered object is deactivated when either: the extension
+ is immanently going to be unloaded; or the registered object is
+ being overridden by some like-named object (such that it can no
+ longer be reached by the core shell.)
<h3>MetaCommand typedef</h3>
<p>These objects represent an extension meta-command, including a
by extensions and passed to the core shell only by reference.
They are made known to the shell core via registerMetaCommand() calls.
- <h3>MetaCommandVtable typedef</h3>
+ <h3>MetaCommand_Vtable typedef</h3>
<p>These objects represent the dispatch table of a MetaCommand object.
<p>All methods are given the same leading (or lone) argument:<br>
(1) the address of the registered MetaCommand object.
- <h4>destruct_free method</h4>
+ <h4>destruct method</h4>
<p>This method is called prior to unloading a runtime extension
for any registered MetaCommand object, provided its dispatch
table entry is non-zero.
- It should free resources allocated during the sqlite3_X_init() call.
+ It should free resources allocated during the sqlite3_X_init() call
+ associated with creation or preparation of the object.
<h4>name method</h4>
<p>This method returns the name of the meta-command (sans leading '.'.)
from the dispatcher.) If the output error message is set, it will
be issued in lieu of the standard error message for invalid calls.
- <h3>FormatXfrInfo typedef</h3>
- <p>An object of this type is passed between the shell core and its
- import or query result handlers to convey or keep parameters and data
- related to formatting or parsing data rows in an external form,
- or to keep state associated with the progression of an import or result
- handling operation from initiation to completion.
- <p>The shell core .mode and .import implementations also use
- an instance of this type to affect result output and import operations.
- That instance resides in the ShellStateX so that extension meta-commands
- can access it, possibly to change it. Meta-commands which alter this
- instance for their own purposes (rather than for intended effect)
- should take care to restore its value as the meta-command completes.
-
<h3>OutModeHandler typedef</h3>
<p>These objects represent an extension query result handler, including
a dispatch table for the public interface and any accompanying
by extensions and passed to the core shell only by reference.
They are made known to the shell core via registerOutMode() calls.
- <h3>OutModeHandlerVtable typedef</h3>
+ <h3>OutModeHandler_Vtable typedef</h3>
<p>These objects represent the dispatch table of an OutModeHandler object.
All methods in the dispatch table are given at
least this leading argument:<br>
(1) The OutModeHandler address registered via registerOutMode();<br>
- <h4>destruct_free method</h4>
+ <h4>destruct method</h4>
<p>This method is called prior to unloading a runtime extension
for any registered OutModeHandler object, provided its dispatch
table entry is non-zero.
- It should free resources allocated during the sqlite3_X_init() call.
+ It should free resources allocated during the sqlite3_X_init() call
+ associated with creation or preparation of the object.
<h4>name method</h4>
<p>This method returns the name of the OutModeHandler, which users
- specify to the .mode command (as the mode) to designate use of the
- registered OutModeHandler for subsequent query results.
+ specify to the .mode command (as the mode's name) to designate use
+ of the registered OutModeHandler for subsequent query results.
The returned pointer must remain valid throughout the lifetime of
the registered MetaCommand object.
<h4>Common arguments</h4>
<p>The following methods are given these 2 additional arguments:<br>
- (2) A FormatXfrInfo object passed by reference; and<br>
- (3) An error message pointer, passed by reference, to receive errors.<br>
+ (2) A ShellExState object passed by reference; and<br>
+ (3) An error message pointer, passed by reference, to receive errors.
<h4>openResultsOutStream method</h4>
<p>This method is called when a query output is setup,
by extensions and passed to the core shell only by reference.
They are made known to the shell core via registerImporter() calls.
- <h3>ImportHandlerVtable typedef</h3>
+ <h3>ImportHandler_Vtable typedef</h3>
<p>These objects represent the dispatch table of an ImportHandler object.
All methods in the dispatch table are given this 1 leading argument:<br>
(1) The ImportHandler address registered via registerImporter().
- <h4>destruct_free method</h4>
+ <h4>destruct method</h4>
<p>This method is called prior to unloading a runtime extension
for any registered OutModeHandler object, provided its dispatch
table entry is non-zero.
- It should free resources allocated during the sqlite3_X_init() call.
+ It should free resources allocated during the sqlite3_X_init() call
+ associated with creation or preparation of the object.
<h4>name method</h4>
<p>This method returns the name of the importer, which is to
<h4>Common arguments</h4>
<p>The following methods are given these 2 additional arguments:<br>
- (2) A FormatXfrInfo object passed by reference; and<br>
+ (2) A ShellExState object passed by reference; and<br>
(3) An error message pointer, passed by reference, to receive errors.
<h4>openDataInStream method</h4>
by this method specifically for the single import operation.
<p>The prepared statement should, in some manner wholly determined
by the extension handler, incorporate compiled SQL (possibly with
- as-yet unbound parameters) which will produce a result set.
+ as-yet unbound parameters) which will (or may) produce a result set.
(This may be no more than a query such as "SELECT @1 as one, ...",
or could be a SELECT from a temporary table used for buffering.)
<p>The return should be SQLITE_OK upon success, in which case the
This prepared statement can have values bound to it or be reset as
necessary to return some or more data. However, it must remain the
same sqlite3_statement instance returned by prepareDataInput().
- <p>It is given 1 additional argument:<br>
- (4) the prepared statement (pointer) returned by prepareDataInput().
<p>The return should be SQLITE_DONE when no more data is available,
or SQLITE_ROW to indicate that more data is or might be available.
Any other return (including SQLITE_OK) indicates a condition which
<p>It is given 1 additional argument:<br>
(4) the prepared statement (pointer) returned by prepareDataInput().<br>
This prepared statement should be finalized by this method. Other
- cleanup or import closing related to the transfer may also be performed.
+ cleanup or import wrap-up related to the transfer may also be performed.
<h4>closeDataInStream method</h4>
<p>This method is called as a .import command which specified this
a C macro, DEFINE_SHDB_TO_SHEXT_API(function_name),
in the extension source to define a function named per
the macro argument. Then that function may be called with its
- lone argument being the sqlite3 * (db) pointer passed as the
- 1st argument to sqlite3_X_init().
+ lone argument being the sqlite3 * (db) pointer which was passed
+ as the 1st argument to sqlite3_X_init().
<p>Either means will return (or yield) either a null pointer
or a verified ShellExtensionLink pointer. In the former
case, sqlite3_X_init() may return SHELL_INVALID_ARGS to induce
.output and .once commands; the currently open user DB (if any);
the dedicated shell DB; and the data related to formatting
and transfer of data in external forms. This data resides in the
- ShellState object as a FormatXfrInfo struct.
- <p>As shell extensibility evolves, additional data items may need
- to be moved into the publicly exposed portion of ShellState, either
- directly (via exposed data members) or by means of some additional
+ ShellStateX object as a ShellExState struct.
+ <p>As shell extensibility evolves, additional data items may need to
+ move into the publicly exposed portion of the ShellStateX object,
+ either directly (via exposed data members) or by means of additional
extension APIs defined in the ShellExtensionLink object (which has
been defined to accommodate growth of its function pointer list in
a backwards-compatible manner.)
</body>
</html>
-
extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText);
#endif
+/* For an embedded shell, allow the 3 standard streams to be specified.
+** If used, these names will have to refer to something globally reachable.
+**/
+#ifndef STD_IN
+# define STD_IN stdin
+#endif
+#ifndef STD_OUT
+# define STD_OUT stdout
+#endif
+#ifndef STD_ERR
+# define STD_ERR stderr
+#endif
+
/* On Windows, we normally run with output mode of TEXT so that \n characters
** are automatically translated into \r\n. However, this behavior needs
** to be disabled in some cases (ex: when generating CSV output and when
sqlite3_int64 iEnd = timeOfDay();
struct rusage sEnd;
getrusage(RUSAGE_SELF, &sEnd);
- printf("Run Time: real %.3f user %f sys %f\n",
+ fprintf(STD_OUT, "Run Time: real %.3f user %f sys %f\n",
(iEnd - iBegin)*0.001,
timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
sqlite3_int64 ftWallEnd = timeOfDay();
getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
- printf("Run Time: real %.3f user %f sys %f\n",
+ fprintf(STD_OUT, "Run Time: real %.3f user %f sys %f\n",
(ftWallEnd - ftWallBegin)*0.001,
timeDiff(&ftUserBegin, &ftUserEnd),
timeDiff(&ftKernelBegin, &ftKernelEnd));
void utf8_printf(FILE *out, const char *zFormat, ...){
va_list ap;
va_start(ap, zFormat);
- if( stdout_is_console && (out==stdout || out==stderr) ){
+ if( stdout_is_console && (out==STD_OUT || out==STD_ERR) ){
char *z1 = sqlite3_vmprintf(zFormat, ap);
char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0);
sqlite3_free(z1);
/* Indicate out-of-memory and exit. */
static void shell_out_of_memory(void){
- raw_printf(stderr,"Error: out of memory\n");
+ raw_printf(STD_ERR,"Error: out of memory\n");
exit(1);
}
#if defined(_WIN32) || defined(WIN32)
/* For interactive input on Windows systems, translate the
** multi-byte characterset characters into UTF-8. */
- if( stdin_is_interactive && in==stdin ){
+ if( stdin_is_interactive && in==STD_IN ){
char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
if( zTrans ){
int nTrans = strlen30(zTrans)+1;
}else{
zPrompt = isContinuation ? continuePrompt : mainPrompt;
#if SHELL_USE_LOCAL_GETLINE
- printf("%s", zPrompt);
- fflush(stdout);
- zResult = local_getline(zPrior, stdin);
+ fprintf(STD_OUT, "%s", zPrompt);
+ fflush(STD_OUT);
+ zResult = local_getline(zPrior, STD_IN);
#else
free(zPrior);
zResult = shell_readline(zPrompt);
va_start(ap, zErrMsg);
zMsg = sqlite3_vmprintf(zErrMsg, ap);
va_end(ap);
- raw_printf(stderr, "line %d: ", p->lineno);
- utf8_printf(stderr, "%s\n", zMsg);
+ raw_printf(STD_ERR, "line %d: ", p->lineno);
+ utf8_printf(STD_ERR, "%s\n", zMsg);
exit(1);
}
}
"DROP TABLE [_shell$self];"
,0,0,&zErrMsg);
if( zErrMsg ){
- utf8_printf(stderr, "SELFTEST initialization failure: %s\n", zErrMsg);
+ utf8_printf(STD_ERR, "SELFTEST initialization failure: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_exec(p->db, "RELEASE selftest_init",0,0,0);
}
else if( n>=2 && 0==strncmp(z, "-sample", n) ){
if( i==(nArg-1) ){
- raw_printf(stderr, "option requires an argument: %s\n", z);
+ raw_printf(STD_ERR, "option requires an argument: %s\n", z);
rc = SQLITE_ERROR;
}else{
iSample = (int)integerValue(azArg[++i]);
if( iSample<0 || iSample>100 ){
- raw_printf(stderr, "value out of range: %s\n", azArg[i]);
+ raw_printf(STD_ERR, "value out of range: %s\n", azArg[i]);
rc = SQLITE_ERROR;
}
}
}
else{
- raw_printf(stderr, "unknown option: %s\n", z);
+ raw_printf(STD_ERR, "unknown option: %s\n", z);
rc = SQLITE_ERROR;
}
}
if( rc==SQLITE_OK ){
pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
if( pState->expert.pExpert==0 ){
- raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
+ raw_printf(STD_ERR, "sqlite3_expert_new: %s\n", zErr);
rc = SQLITE_ERROR;
}else{
sqlite3_expert_config(
if( zDbFilename ){
in = fopen(zDbFilename, "r");
if( in==0 ){
- utf8_printf(stderr, "cannot open \"%s\" for reading\n", zDbFilename);
+ utf8_printf(STD_ERR, "cannot open \"%s\" for reading\n", zDbFilename);
return 0;
}
nLine = 0;
}else{
in = p->in;
nLine = p->lineno;
- if( in==0 ) in = stdin;
+ if( in==0 ) in = STD_IN;
}
*pnData = 0;
nLine++;
n = (n+pgsz-1)&~(pgsz-1); /* Round n up to the next multiple of pgsz */
a = sqlite3_malloc( n ? n : 1 );
if( a==0 ){
- utf8_printf(stderr, "Out of memory!\n");
+ utf8_printf(STD_ERR, "Out of memory!\n");
goto readHexDb_error;
}
memset(a, 0, n);
if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){
- utf8_printf(stderr, "invalid pagesize\n");
+ utf8_printf(STD_ERR, "invalid pagesize\n");
goto readHexDb_error;
}
for(nLine++; fgets(zLine, sizeof(zLine), in)!=0; nLine++){
p->lineno = nLine;
}
sqlite3_free(a);
- utf8_printf(stderr,"Error on line %d of --hexdb input\n", nLine);
+ utf8_printf(STD_ERR,"Error on line %d of --hexdb input\n", nLine);
return 0;
}
#endif /* SQLITE_OMIT_DESERIALIZE */
}
globalDb = p->db;
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
- utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
+ utf8_printf(STD_ERR,"Error: unable to open database \"%s\": %s\n",
zDbFilename, sqlite3_errmsg(p->db));
if( openFlags & OPEN_DB_KEEPALIVE ){
sqlite3_open(":memory:", &p->db);
SQLITE_DESERIALIZE_RESIZEABLE |
SQLITE_DESERIALIZE_FREEONCLOSE);
if( rc ){
- utf8_printf(stderr, "Error: sqlite3_deserialize() returns %d\n", rc);
+ utf8_printf(STD_ERR, "Error: sqlite3_deserialize() returns %d\n", rc);
}
if( p->szMax>0 ){
sqlite3_file_control(p->db, "main", SQLITE_FCNTL_SIZE_LIMIT, &p->szMax);
void close_db(sqlite3 *db){
int rc = sqlite3_close(db);
if( rc ){
- utf8_printf(stderr, "Error: sqlite3_close() returns %d: %s\n",
+ utf8_printf(STD_ERR, "Error: sqlite3_close() returns %d: %s\n",
rc, sqlite3_errmsg(db));
}
}
if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){
return 0;
}
- utf8_printf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
+ utf8_printf(STD_ERR, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
zArg);
return 0;
}
** Close an output file, assuming it is not stderr or stdout
*/
static void output_file_close(FILE *f){
- if( f && f!=stdout && f!=stderr ) fclose(f);
+ if( f && f!=STD_OUT && f!=STD_ERR ) fclose(f);
}
/*
static FILE *output_file_open(const char *zFile, int bTextMode){
FILE *f;
if( strcmp(zFile,"stdout")==0 ){
- f = stdout;
+ f = STD_OUT;
}else if( strcmp(zFile, "stderr")==0 ){
- f = stderr;
+ f = STD_ERR;
}else if( strcmp(zFile, "off")==0 ){
f = 0;
}else{
f = fopen(zFile, bTextMode ? "w" : "wb");
if( f==0 ){
- utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
+ utf8_printf(STD_ERR, "Error: cannot open \"%s\"\n", zFile);
}
}
return f;
break;
}
if( pc==cQuote && c!='\r' ){
- utf8_printf(stderr, "%s:%d: unescaped %c character\n",
+ utf8_printf(STD_ERR, "%s:%d: unescaped %c character\n",
p->zFile, p->nLine, cQuote);
}
if( c==EOF ){
- utf8_printf(stderr, "%s:%d: unterminated %c-quoted field\n",
+ utf8_printf(STD_ERR, "%s:%d: unterminated %c-quoted field\n",
p->zFile, startLine, cQuote);
p->cTerm = c;
break;
zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
if( rc ){
- utf8_printf(stderr, "Error %d: %s on [%s]\n",
+ utf8_printf(STD_ERR, "Error %d: %s on [%s]\n",
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
zQuery);
goto end_data_xfer;
memcpy(zInsert+i, ");", 3);
rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0);
if( rc ){
- utf8_printf(stderr, "Error %d: %s on [%s]\n",
+ utf8_printf(STD_ERR, "Error %d: %s on [%s]\n",
sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb),
zQuery);
goto end_data_xfer;
} /* End for */
rc = sqlite3_step(pInsert);
if( rc!=SQLITE_OK && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
- utf8_printf(stderr, "Error %d: %s\n", sqlite3_extended_errcode(newDb),
+ utf8_printf(STD_ERR, "Error %d: %s\n", sqlite3_extended_errcode(newDb),
sqlite3_errmsg(newDb));
}
sqlite3_reset(pInsert);
cnt++;
if( (cnt%spinRate)==0 ){
- printf("%c\b", "|/-\\"[(cnt/spinRate)%4]);
- fflush(stdout);
+ fprintf(STD_OUT, "%c\b", "|/-\\"[(cnt/spinRate)%4]);
+ fflush(STD_OUT);
}
} /* End while */
if( rc==SQLITE_DONE ) break;
zTable);
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
if( rc ){
- utf8_printf(stderr, "Warning: cannot step \"%s\" backwards", zTable);
+ utf8_printf(STD_ERR, "Warning: cannot step \"%s\" backwards", zTable);
break;
}
} /* End for(k=0...) */
" WHERE %s", zWhere);
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
if( rc ){
- utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
+ utf8_printf(STD_ERR, "Error: (%d) %s on [%s]\n",
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
zQuery);
goto end_schema_xfer;
while( sqlite3_step(pQuery)==SQLITE_ROW ){
zName = sqlite3_column_text(pQuery, 0);
zSql = sqlite3_column_text(pQuery, 1);
- printf("%s... ", zName); fflush(stdout);
+ fprintf(STD_OUT, "%s... ", zName); fflush(STD_OUT);
sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
if( zErrMsg ){
- utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
+ utf8_printf(STD_ERR, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
sqlite3_free(zErrMsg);
zErrMsg = 0;
}
if( xForEach ){
xForEach(p, newDb, (const char*)zName);
}
- printf("done\n");
+ fprintf(STD_OUT, "done\n");
}
if( rc!=SQLITE_DONE ){
sqlite3_finalize(pQuery);
" WHERE %s ORDER BY rowid DESC", zWhere);
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
if( rc ){
- utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
+ utf8_printf(STD_ERR, "Error: (%d) %s on [%s]\n",
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
zQuery);
goto end_schema_xfer;
while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
zName = sqlite3_column_text(pQuery, 0);
zSql = sqlite3_column_text(pQuery, 1);
- printf("%s... ", zName); fflush(stdout);
+ fprintf(STD_OUT, "%s... ", zName); fflush(STD_OUT);
sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
if( zErrMsg ){
- utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
+ utf8_printf(STD_ERR, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
sqlite3_free(zErrMsg);
zErrMsg = 0;
}
if( xForEach ){
xForEach(p, newDb, (const char*)zName);
}
- printf("done\n");
+ fprintf(STD_OUT, "done\n");
}
}
end_schema_xfer:
int rc;
sqlite3 *newDb = 0;
if( access(zNewDb,0)==0 ){
- utf8_printf(stderr, "File \"%s\" already exists.\n", zNewDb);
+ utf8_printf(STD_ERR, "File \"%s\" already exists.\n", zNewDb);
return;
}
rc = sqlite3_open(zNewDb, &newDb);
if( rc ){
- utf8_printf(stderr, "Cannot create output database: %s\n",
+ utf8_printf(STD_ERR, "Cannot create output database: %s\n",
sqlite3_errmsg(newDb));
}else{
sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0);
char *zCmd;
zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
if( system(zCmd) ){
- utf8_printf(stderr, "Failed: [%s]\n", zCmd);
+ utf8_printf(STD_ERR, "Failed: [%s]\n", zCmd);
}else{
/* Give the start/open/xdg-open command some time to get
** going before we continue, and potential delete the
#endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
}
p->outfile[0] = 0;
- p->out = stdout;
+ p->out = STD_OUT;
}
/*
"SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
-1, &pStmt, 0);
if( rc ){
- utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR, "error: %s\n", sqlite3_errmsg(p->db));
sqlite3_finalize(pStmt);
return 1;
}
memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
sqlite3_finalize(pStmt);
}else{
- raw_printf(stderr, "unable to read database header\n");
+ raw_printf(STD_ERR, "unable to read database header\n");
sqlite3_finalize(pStmt);
return 1;
}
*/
static int shellDatabaseError(sqlite3 *db){
const char *zErr = sqlite3_errmsg(db);
- utf8_printf(stderr, "Error: %s\n", zErr);
+ utf8_printf(STD_ERR, "Error: %s\n", zErr);
return 1;
}
zIndent = " ";
}
else{
- raw_printf(stderr, "Usage: %s %s ?-verbose? ?-groupbyparent?\n",
+ raw_printf(STD_ERR, "Usage: %s %s ?-verbose? ?-groupbyparent?\n",
azArg[0], azArg[1]
);
return SQLITE_ERROR;
if( rc!=SQLITE_OK ) break;
if( res<0 ){
- raw_printf(stderr, "Error: internal error");
+ raw_printf(STD_ERR, "Error: internal error");
break;
}else{
if( bGroupByParent
sqlite3_free(zPrev);
if( rc!=SQLITE_OK ){
- raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
+ raw_printf(STD_ERR, "%s\n", sqlite3_errmsg(db));
}
rc2 = sqlite3_finalize(pSql);
if( rc==SQLITE_OK && rc2!=SQLITE_OK ){
rc = rc2;
- raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
+ raw_printf(STD_ERR, "%s\n", sqlite3_errmsg(db));
}
}else{
- raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
+ raw_printf(STD_ERR, "%s\n", sqlite3_errmsg(db));
}
return rc;
if( *pRc==SQLITE_OK ){
int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
if( rc!=SQLITE_OK ){
- raw_printf(stderr, "sql error: %s (%d)\n",
+ raw_printf(STD_ERR, "sql error: %s (%d)\n",
sqlite3_errmsg(db), sqlite3_errcode(db)
);
*pRc = rc;
int rc = sqlite3_finalize(pStmt);
if( *pRc==SQLITE_OK ){
if( rc!=SQLITE_OK ){
- raw_printf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
+ raw_printf(STD_ERR, "SQL error: %s\n", sqlite3_errmsg(db));
}
*pRc = rc;
}
if( *pRc==SQLITE_OK ){
if( rc!=SQLITE_OK ){
sqlite3 *db = sqlite3_db_handle(pStmt);
- raw_printf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
+ raw_printf(STD_ERR, "SQL error: %s\n", sqlite3_errmsg(db));
}
*pRc = rc;
}
va_start(ap, zFmt);
z = sqlite3_vmprintf(zFmt, ap);
va_end(ap);
- utf8_printf(stderr, "Error: %s\n", z);
+ utf8_printf(STD_ERR, "Error: %s\n", z);
if( pAr->fromCmdLine ){
- utf8_printf(stderr, "Use \"-A\" for more help\n");
+ utf8_printf(STD_ERR, "Use \"-A\" for more help\n");
}else{
- utf8_printf(stderr, "Use \".archive --help\" for more help\n");
+ utf8_printf(STD_ERR, "Use \".archive --help\" for more help\n");
}
sqlite3_free(z);
return SQLITE_ERROR;
struct ArSwitch *pEnd = &aSwitch[nSwitch];
if( nArg<=1 ){
- utf8_printf(stderr, "Wrong number of arguments. Usage:\n");
- return arUsage(stderr);
+ utf8_printf(STD_ERR, "Wrong number of arguments. Usage:\n");
+ return arUsage(STD_ERR);
}else{
char *z = azArg[1];
if( z[0]!='-' ){
}
shellReset(&rc, pTest);
if( rc==SQLITE_OK && bOk==0 ){
- utf8_printf(stderr, "not found in archive: %s\n", z);
+ utf8_printf(STD_ERR, "not found in archive: %s\n", z);
rc = SQLITE_ERROR;
}
}
}
}
if( zErr ){
- utf8_printf(stdout, "ERROR: %s\n", zErr);
+ utf8_printf(STD_OUT, "ERROR: %s\n", zErr);
sqlite3_free(zErr);
}
}
char *zErr = 0;
rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr);
if( zErr ){
- utf8_printf(stdout, "ERROR: %s\n", zErr);
+ utf8_printf(STD_OUT, "ERROR: %s\n", zErr);
sqlite3_free(zErr);
}
}
rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
if( rc!=SQLITE_OK ){
- utf8_printf(stderr, "cannot open file: %s (%s)\n",
+ utf8_printf(STD_ERR, "cannot open file: %s (%s)\n",
cmd.zFile, sqlite3_errmsg(cmd.db)
);
goto end_ar_command;
if( cmd.eCmd!=AR_CMD_CREATE
&& sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0)
){
- utf8_printf(stderr, "database does not contain an 'sqlar' table\n");
+ utf8_printf(STD_ERR, "database does not contain an 'sqlar' table\n");
rc = SQLITE_ERROR;
goto end_ar_command;
}
char *zErr = 0;
rc = sqlite3_exec(db, zSql, 0, 0, &zErr);
if( rc!=SQLITE_OK ){
- raw_printf(stderr, "SQL error: %s\n", zErr);
+ raw_printf(STD_ERR, "SQL error: %s\n", zErr);
}
sqlite3_free(zErr);
*pRc = rc;
bAsync = 1;
}else
{
- utf8_printf(stderr, "unknown option: %s\n", azArg[j]);
+ utf8_printf(STD_ERR, "unknown option: %s\n", azArg[j]);
return INVALID_ARGS;
}
}else if( zDestFile==0 ){
zDb = zDestFile;
zDestFile = azArg[j];
}else{
- raw_printf(stderr, "Usage: .backup ?DB? ?OPTIONS? FILENAME\n");
+ raw_printf(STD_ERR, "Usage: .backup ?DB? ?OPTIONS? FILENAME\n");
return INVALID_ARGS;
}
}
if( zDestFile==0 ){
- raw_printf(stderr, "missing FILENAME argument on .backup\n");
+ raw_printf(STD_ERR, "missing FILENAME argument on .backup\n");
return INVALID_ARGS;
}
if( zDb==0 ) zDb = "main";
rc = sqlite3_open_v2(zDestFile, &pDest,
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
if( rc!=SQLITE_OK ){
- utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
+ utf8_printf(STD_ERR, "Error: cannot open \"%s\"\n", zDestFile);
close_db(pDest);
return 1;
}
open_db(p, 0);
pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
if( pBackup==0 ){
- utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
+ utf8_printf(STD_ERR, "Error: %s\n", sqlite3_errmsg(pDest));
close_db(pDest);
return 1;
}
if( rc==SQLITE_DONE ){
rc = 0;
}else{
- utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
+ utf8_printf(STD_ERR, "Error: %s\n", sqlite3_errmsg(pDest));
rc = 1;
}
close_db(pDest);
bail_on_error = booleanValue(azArg[1]);
return 0;
}else{
- raw_printf(stderr, "Usage: .bail on|off\n");
+ raw_printf(STD_ERR, "Usage: .bail on|off\n");
return 1;
}
}
rc = chdir(azArg[1]);
#endif
if( rc ){
- utf8_printf(stderr, "Cannot change to directory \"%s\"\n", azArg[1]);
+ utf8_printf(STD_ERR, "Cannot change to directory \"%s\"\n", azArg[1]);
rc = 1;
}
return rc;
int rc=0;
output_reset(p);
if( nArg!=2 ){
- raw_printf(stderr, "Usage: .check GLOB-PATTERN\n");
+ raw_printf(STD_ERR, "Usage: .check GLOB-PATTERN\n");
rc = 2;
}else if( (zRes = readFile("testcase-out.txt", 0))==0 ){
- raw_printf(stderr, "Error: cannot read 'testcase-out.txt'\n");
+ raw_printf(STD_ERR, "Error: cannot read 'testcase-out.txt'\n");
rc = 2;
}else if( testcase_glob(azArg[1],zRes)==0 ){
- utf8_printf(stderr,
+ utf8_printf(STD_ERR,
"testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
p->zTestcase, azArg[1], zRes);
rc = 1;
}else{
- utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
+ utf8_printf(STD_OUT, "testcase-%s ok\n", p->zTestcase);
p->nCheck++;
}
sqlite3_free(zRes);
zFile = "(temporary-file)";
}
if( p->pAuxDb == &p->aAuxDb[i] ){
- utf8_printf(stdout, "ACTIVE %d: %s\n", i, zFile);
+ utf8_printf(STD_OUT, "ACTIVE %d: %s\n", i, zFile);
}else if( p->aAuxDb[i].db!=0 ){
- utf8_printf(stdout, " %d: %s\n", i, zFile);
+ utf8_printf(STD_OUT, " %d: %s\n", i, zFile);
}
}
}else if( nArg==2 && IsDigit(azArg[1][0]) && azArg[1][1]==0 ){
if( i<0 || i>=ArraySize(p->aAuxDb) ){
/* No-op */
}else if( p->pAuxDb == &p->aAuxDb[i] ){
- raw_printf(stderr, "cannot close the active database connection\n");
+ raw_printf(STD_ERR, "cannot close the active database connection\n");
return 1;
}else if( p->aAuxDb[i].db ){
session_close_all(p, i);
p->aAuxDb[i].db = 0;
}
}else{
- raw_printf(stderr, "Usage: .connection [close] [CONNECTION-NUMBER]\n");
+ raw_printf(STD_ERR, "Usage: .connection [close] [CONNECTION-NUMBER]\n");
return 1;
}
return 0;
open_db(p, 0);
rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
if( rc ){
- utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR, "Error: %s\n", sqlite3_errmsg(p->db));
rc = 1;
}else{
while( sqlite3_step(pStmt)==SQLITE_ROW ){
if( nArg>1 ) break;
}
if( nArg>1 && ii==ArraySize(aDbConfig) ){
- utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
- utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
+ utf8_printf(STD_ERR, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
+ utf8_printf(STD_ERR, "Enter \".dbconfig\" with no arguments for a list\n");
return 1;
}
return 0;
if( z[0]=='-' ) z++;
if( strcmp(z,"preserve-rowids")==0 ){
#ifdef SQLITE_OMIT_VIRTUALTABLE
- raw_printf(stderr, "The --preserve-rowids option is not compatible"
+ raw_printf(STD_ERR, "The --preserve-rowids option is not compatible"
" with SQLITE_OMIT_VIRTUALTABLE\n");
sqlite3_free(zLike);
return 1;
}else if( strcmp(z,"nosys")==0 ){
ShellSetFlag(p, SHFLG_DumpNoSys);
}else{
- raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
+ raw_printf(STD_ERR, "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
sqlite3_free(zLike);
return 1;
}
p->autoEQP = (u8)booleanValue(azArg[1]);
}
}else{
- raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
+ raw_printf(STD_ERR, "Usage: .eqp off|on|trace|trigger|full\n");
return 1;
}
}
#endif /* SQLITE_NOHAVE_SYSTEM */
if( zFile[0]=='|' ){
#ifdef SQLITE_OMIT_POPEN
- raw_printf(stderr, "Error: pipes are not supported in this OS\n");
+ raw_printf(STD_ERR, "Error: pipes are not supported in this OS\n");
rc = 1;
- p->out = stdout;
+ p->out = STD_OUT;
#else
p->out = popen(zFile + 1, "w");
if( p->out==0 ){
- utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
- p->out = stdout;
+ utf8_printf(STD_ERR,"Error: cannot open pipe \"%s\"\n", zFile + 1);
+ p->out = STD_OUT;
rc = 1;
}else{
if( bBOM ) fprintf(p->out,"\357\273\277");
p->out = output_file_open(zFile, bTxtMode);
if( p->out==0 ){
if( strcmp(zFile,"off")!=0 ){
- utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
+ utf8_printf(STD_ERR,"Error: cannot write to \"%s\"\n", zFile);
}
- p->out = stdout;
+ p->out = STD_OUT;
rc = 1;
} else {
if( bBOM ) fprintf(p->out,"\357\273\277");
filectrl = aCtrl[i].ctrlCode;
iCtrl = i;
}else{
- utf8_printf(stderr, "Error: ambiguous file-control: \"%s\"\n"
+ utf8_printf(STD_ERR, "Error: ambiguous file-control: \"%s\"\n"
"Use \".filectrl --help\" for help\n", zCmd);
return 1;
}
}
}
if( filectrl<0 ){
- utf8_printf(stderr,"Error: unknown file-control: %s\n"
+ utf8_printf(STD_ERR,"Error: unknown file-control: %s\n"
"Use \".filectrl --help\" for help\n", zCmd);
}else{
switch(filectrl){
nArg = 1;
}
if( nArg!=1 ){
- raw_printf(stderr, "Usage: .fullschema ?--indent?\n");
+ raw_printf(STD_ERR, "Usage: .fullschema ?--indent?\n");
return 1;
}
open_db(p, 0);
** the column and row separator characters from the output mode. */
nSep = strlen30(p->colSeparator);
if( nSep==0 ){
- raw_printf(stderr,
+ raw_printf(STD_ERR,
"Error: non-null column separator required for import\n");
return 1;
}
if( nSep>1 ){
- raw_printf(stderr,
+ raw_printf(STD_ERR,
"Error: multi-character or multi-byte column separators"
" not allowed for import\n");
return 1;
}
nSep = strlen30(p->rowSeparator);
if( nSep==0 ){
- raw_printf(stderr,
+ raw_printf(STD_ERR,
"Error: non-null row separator required for import\n");
return 1;
}
nSep = strlen30(p->rowSeparator);
}
if( nSep>1 ){
- raw_printf(stderr, "Error: multi-character row separators not allowed"
+ raw_printf(STD_ERR, "Error: multi-character row separators not allowed"
" for import\n");
return 1;
}
sCtx.nLine = 1;
if( sCtx.zFile[0]=='|' ){
#ifdef SQLITE_OMIT_POPEN
- raw_printf(stderr, "Error: pipes are not supported in this OS\n");
+ raw_printf(STD_ERR, "Error: pipes are not supported in this OS\n");
return 1;
#else
sCtx.in = popen(sCtx.zFile+1, "r");
sCtx.xCloser = fclose;
}
if( sCtx.in==0 ){
- utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
+ utf8_printf(STD_ERR, "Error: cannot open \"%s\"\n", zFile);
import_cleanup(&sCtx);
return 1;
}
if( cSep=='(' ){
sqlite3_free(zCreate);
import_cleanup(&sCtx);
- utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
+ utf8_printf(STD_ERR,"%s: empty file\n", sCtx.zFile);
return 1;
}
zCreate = sqlite3_mprintf("%z\n)", zCreate);
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
sqlite3_free(zCreate);
if( rc ){
- utf8_printf(stderr, "CREATE TABLE \"%s\"(...) failed: %s\n", zTable,
+ utf8_printf(STD_ERR, "CREATE TABLE \"%s\"(...) failed: %s\n", zTable,
sqlite3_errmsg(p->db));
import_cleanup(&sCtx);
return 1;
sqlite3_free(zSql);
if( rc ){
if (pStmt) sqlite3_finalize(pStmt);
- utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR,"Error: %s\n", sqlite3_errmsg(p->db));
import_cleanup(&sCtx);
return 1;
}
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
sqlite3_free(zSql);
if( rc ){
- utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR, "Error: %s\n", sqlite3_errmsg(p->db));
if (pStmt) sqlite3_finalize(pStmt);
import_cleanup(&sCtx);
return 1;
if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
- utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "
+ utf8_printf(STD_ERR, "%s:%d: expected %d columns but found %d - "
"filling the rest with NULL\n",
sCtx.zFile, startLine, nCol, i+1);
i += 2;
xRead(&sCtx);
i++;
}while( sCtx.cTerm==sCtx.cColSep );
- utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "
+ utf8_printf(STD_ERR, "%s:%d: expected %d columns but found %d - "
"extras ignored\n",
sCtx.zFile, startLine, nCol, i);
}
sqlite3_step(pStmt);
rc = sqlite3_reset(pStmt);
if( rc!=SQLITE_OK ){
- utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile,
+ utf8_printf(STD_ERR, "%s:%d: INSERT failed: %s\n", sCtx.zFile,
startLine, sqlite3_errmsg(p->db));
sCtx.nErr++;
}else{
int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
int i;
if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
- utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
+ utf8_printf(STD_ERR, "Usage: .imposter INDEX IMPOSTER\n"
" .imposter off\n");
/* Also allowed, but not documented:
**
}
sqlite3_finalize(pStmt);
if( i==0 || tnum==0 ){
- utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
+ utf8_printf(STD_ERR, "no such index: \"%s\"\n", azArg[1]);
sqlite3_free(zCollist);
return 1;
}
rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
if( rc ){
- utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
}else{
- utf8_printf(stdout, "%s;\n", zSql);
- raw_printf(stdout,
+ utf8_printf(STD_OUT, "%s;\n", zSql);
+ raw_printf(STD_OUT,
"WARNING: writing to an imposter table will corrupt the \"%s\" %s!\n",
azArg[1], isWO ? "table" : "index"
);
}
}else{
- raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
+ raw_printf(STD_ERR, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
}
sqlite3_free(zSql);
return rc != 0;
}
DISPATCHABLE_COMMAND( iotrace ? 2 2 ){
SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...);
- if( iotrace && iotrace!=stdout ) fclose(iotrace);
+ if( iotrace && iotrace!=STD_OUT ) fclose(iotrace);
iotrace = 0;
if( nArg<2 ){
sqlite3IoTrace = 0;
}else if( strcmp(azArg[1], "-")==0 ){
sqlite3IoTrace = iotracePrintf;
- iotrace = stdout;
+ iotrace = STD_OUT;
}else{
iotrace = fopen(azArg[1], "w");
if( iotrace==0 ){
- utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
+ utf8_printf(STD_ERR, "Error: cannot open \"%s\"\n", azArg[1]);
sqlite3IoTrace = 0;
return 1;
}else{
open_db(p, 0);
if( nArg==1 ){
for(i=0; i<ArraySize(aLimit); i++){
- printf("%20s %d\n", aLimit[i].zLimitName,
+ fprintf(STD_OUT, "%20s %d\n", aLimit[i].zLimitName,
sqlite3_limit(p->db, aLimit[i].limitCode, -1));
}
}else if( nArg>3 ){
- raw_printf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
+ raw_printf(STD_ERR, "Usage: .limit NAME ?NEW-VALUE?\n");
return 1;
}else{
int iLimit = -1;
if( iLimit<0 ){
iLimit = i;
}else{
- utf8_printf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
+ utf8_printf(STD_ERR, "ambiguous limit: \"%s\"\n", azArg[1]);
return 1;
}
}
}
if( iLimit<0 ){
- utf8_printf(stderr, "unknown limit: \"%s\"\n"
+ utf8_printf(STD_ERR, "unknown limit: \"%s\"\n"
"enter \".limits\" with no arguments for a list.\n",
azArg[1]);
return 1;
sqlite3_limit(p->db, aLimit[iLimit].limitCode,
(int)integerValue(azArg[2]));
}
- printf("%20s %d\n", aLimit[iLimit].zLimitName,
+ fprintf(STD_OUT, "%20s %d\n", aLimit[iLimit].zLimitName,
sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
}
return 0;
if( n>0 && !sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ){
return lintFkeyIndexes(p, azArg, nArg);
}
- raw_printf(stderr,
+ raw_printf(STD_ERR,
"Usage %s sub-command ?switches...?\n"
"Where sub-commands are:\n"
" fkey-indexes\n", azArg[0]);
zProc = nArg>=3 ? azArg[2] : 0;
open_db(p, 0);
if( SQLITE_OK!=sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg)){
- utf8_printf(stderr, "Error: %s\n", zErrMsg);
+ utf8_printf(STD_ERR, "Error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
return 1;
}
}else if( nArg==1 ){
raw_printf(p->out, "current output mode: %s\n", modeDescr[p->mode]);
}else{
- raw_printf(stderr, "Error: mode should be one of: "
+ raw_printf(STD_ERR, "Error: mode should be one of: "
"ascii box column csv html insert json line\n"
" list markdown quote table tabs tcl\n");
return 1;
p->szMax = integerValue(azArg[++iName]);
#endif /* SQLITE_OMIT_DESERIALIZE */
}else if( z[0]=='-' ){
- utf8_printf(stderr, "unknown option: %s\n", z);
+ utf8_printf(STD_ERR, "unknown option: %s\n", z);
return 1;
}else if( zNewFilename ){
- utf8_printf(stderr, "extra argument: \"%s\"\n", z);
+ utf8_printf(STD_ERR, "extra argument: \"%s\"\n", z);
return 1;
}else{
zNewFilename = sqlite3_mprintf("%s", z);
p->pAuxDb->zDbFilename = zNewFilename;
open_db(p, OPEN_DB_KEEPALIVE);
if( p->db==0 ){
- utf8_printf(stderr, "Error: cannot open '%s'\n", zNewFilename);
+ utf8_printf(STD_ERR, "Error: cannot open '%s'\n", zNewFilename);
sqlite3_free(zNewFilename);
}else{
p->pAuxDb->zFreeOnClose = zNewFilename;
DISPATCHABLE_COMMAND( nonce ? 2 2 ){
if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
- raw_printf(stderr, "line %d: incorrect nonce: \"%s\"\n",
+ raw_printf(STD_ERR, "line %d: incorrect nonce: \"%s\"\n",
p->lineno, azArg[1]);
exit(1);
}
}
if( strcmp(z,"limit")==0 ){
if( i+1>=nArg ){
- utf8_printf(stderr, "Error: missing argument on --limit\n");
+ utf8_printf(STD_ERR, "Error: missing argument on --limit\n");
return 1;
}else{
p->mxProgress = (int)integerValue(azArg[++i]);
}
continue;
}
- utf8_printf(stderr, "Error: unknown option: \"%s\"\n", azArg[i]);
+ utf8_printf(STD_ERR, "Error: unknown option: \"%s\"\n", azArg[i]);
return 1;
}else{
nn = (int)integerValue(z);
failIfSafeMode(p, "cannot run .read in safe mode");
if( azArg[1][0]=='|' ){
#ifdef SQLITE_OMIT_POPEN
- raw_printf(stderr, "Error: pipes are not supported in this OS\n");
+ raw_printf(STD_ERR, "Error: pipes are not supported in this OS\n");
rc = 1;
- p->out = stdout;
+ p->out = STD_OUT;
#else
p->in = popen(azArg[1]+1, "r");
if( p->in==0 ){
- utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
+ utf8_printf(STD_ERR, "Error: cannot open \"%s\"\n", azArg[1]);
rc = 1;
}else{
rc = process_input(p);
}
#endif
}else if( (p->in = openChrSource(azArg[1]))==0 ){
- utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
+ utf8_printf(STD_ERR,"Error: cannot open \"%s\"\n", azArg[1]);
rc = 1;
}else{
rc = process_input(p);
bRowids = 0;
}
else{
- utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
+ utf8_printf(STD_ERR, "unexpected option: %s\n", azArg[i]);
showHelp(p->out, azArg[0]);
return 1;
}
zSrcFile = azArg[2];
zDb = azArg[1];
}else{
- raw_printf(stderr, "Usage: .restore ?DB? FILE\n");
+ raw_printf(STD_ERR, "Usage: .restore ?DB? FILE\n");
return 1;
}
rc = sqlite3_open(zSrcFile, &pSrc);
if( rc!=SQLITE_OK ){
- utf8_printf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
+ utf8_printf(STD_ERR, "Error: cannot open \"%s\"\n", zSrcFile);
close_db(pSrc);
return 1;
}
open_db(p, 0);
pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
if( pBackup==0 ){
- utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR, "Error: %s\n", sqlite3_errmsg(p->db));
close_db(pSrc);
return 1;
}
if( rc==SQLITE_DONE ){
rc = 0;
}else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
- raw_printf(stderr, "Error: source database is busy\n");
+ raw_printf(STD_ERR, "Error: source database is busy\n");
rc = 1;
}else{
- utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR, "Error: %s\n", sqlite3_errmsg(p->db));
rc = 1;
}
close_db(pSrc);
DISPATCHABLE_COMMAND( scanstats ? 2 2 ){
p->scanstatsOn = (u8)booleanValue(azArg[1]);
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
- raw_printf(stderr, "Warning: .scanstats not available in this build.\n");
+ raw_printf(STD_ERR, "Warning: .scanstats not available in this build.\n");
#endif
return 0;
}
}else if( optionMatch(azArg[ii],"nosys") ){
bNoSystemTabs = 1;
}else if( azArg[ii][0]=='-' ){
- utf8_printf(stderr, "Unknown option: \"%s\"\n", azArg[ii]);
+ utf8_printf(STD_ERR, "Unknown option: \"%s\"\n", azArg[ii]);
return 1;
}else if( zName==0 ){
zName = azArg[ii];
}else{
- raw_printf(stderr, "Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n");
+ raw_printf(STD_ERR, "Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n");
return 1;
}
}
rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list",
-1, &pStmt, 0);
if( rc ){
- utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR, "Error: %s\n", sqlite3_errmsg(p->db));
sqlite3_finalize(pStmt);
return 1;
}
freeText(&sSelect);
}
if( zErrMsg ){
- utf8_printf(stderr,"Error: %s\n", zErrMsg);
+ utf8_printf(STD_ERR,"Error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
rc = 1;
}else if( rc != SQLITE_OK ){
- raw_printf(stderr,"Error: querying schema information\n");
+ raw_printf(STD_ERR,"Error: querying schema information\n");
rc = 1;
}else{
rc = 0;
if( nCmd!=2 ) goto session_syntax_error;
if( pSession->p==0 ){
session_not_open:
- raw_printf(stderr, "ERROR: No sessions are open\n");
+ raw_printf(STD_ERR, "ERROR: No sessions are open\n");
}else{
rc = sqlite3session_attach(pSession->p, azCmd[1]);
if( rc ){
- raw_printf(stderr, "ERROR: sqlite3session_attach() returns %d\n", rc);
+ raw_printf(STD_ERR, "ERROR: sqlite3session_attach() returns %d\n", rc);
rc = 0;
}
}
if( pSession->p==0 ) goto session_not_open;
out = fopen(azCmd[1], "wb");
if( out==0 ){
- utf8_printf(stderr, "ERROR: cannot open \"%s\" for writing\n",
+ utf8_printf(STD_ERR, "ERROR: cannot open \"%s\" for writing\n",
azCmd[1]);
}else{
int szChng;
rc = sqlite3session_patchset(pSession->p, &szChng, &pChng);
}
if( rc ){
- printf("Error: error code %d\n", rc);
+ fprintf(STD_OUT, "Error: error code %d\n", rc);
rc = 0;
}
if( pChng
&& fwrite(pChng, szChng, 1, out)!=1 ){
- raw_printf(stderr, "ERROR: Failed to write entire %d-byte output\n",
+ raw_printf(STD_ERR, "ERROR: Failed to write entire %d-byte output\n",
szChng);
}
sqlite3_free(pChng);
nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
pSession->azFilter = sqlite3_malloc( nByte );
if( pSession->azFilter==0 ){
- raw_printf(stderr, "Error: out or memory\n");
+ raw_printf(STD_ERR, "Error: out or memory\n");
exit(1);
}
for(ii=1; ii<nCmd; ii++){
if( zName[0]==0 ) goto session_syntax_error;
for(i=0; i<pAuxDb->nSession; i++){
if( strcmp(pAuxDb->aSession[i].zName,zName)==0 ){
- utf8_printf(stderr, "Session \"%s\" already exists\n", zName);
+ utf8_printf(STD_ERR, "Session \"%s\" already exists\n", zName);
return rc;
}
}
if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){
- raw_printf(stderr, "Maximum of %d sessions\n",
+ raw_printf(STD_ERR, "Maximum of %d sessions\n",
ArraySize(pAuxDb->aSession));
return rc;
}
pSession = &pAuxDb->aSession[pAuxDb->nSession];
rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
if( rc ){
- raw_printf(stderr, "Cannot open session: error code=%d\n", rc);
+ raw_printf(STD_ERR, "Cannot open session: error code=%d\n", rc);
return rc;
}
pSession->nFilter = 0;
bDebug = 1;
}else
{
- utf8_printf(stderr, "Unknown option \"%s\" on \"%s\"\n",
+ utf8_printf(STD_ERR, "Unknown option \"%s\" on \"%s\"\n",
azArg[i], azArg[0]);
showHelp(p->out, azArg[0]);
return 1;
}
}else if( zLike ){
- raw_printf(stderr, "Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n");
+ raw_printf(STD_ERR, "Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n");
return 1;
}else{
zLike = z;
bVerbose++;
}else
{
- utf8_printf(stderr, "Unknown option \"%s\" on \"%s\"\n",
+ utf8_printf(STD_ERR, "Unknown option \"%s\" on \"%s\"\n",
azArg[i], azArg[0]);
- raw_printf(stderr, "Should be one of: --init -v\n");
+ raw_printf(STD_ERR, "Should be one of: --init -v\n");
return 1;
}
}
-1, &pStmt, 0);
}
if( rc ){
- raw_printf(stderr, "Error querying the selftest table\n");
+ raw_printf(STD_ERR, "Error querying the selftest table\n");
sqlite3_finalize(pStmt);
return 1;
}
k = 0;
if( bVerbose>0 ){
char *zQuote = sqlite3_mprintf("%q", zSql);
- printf("%d: %s %s\n", tno, zOp, zSql);
+ fprintf(STD_OUT, "%d: %s %s\n", tno, zOp, zSql);
sqlite3_free(zQuote);
}
if( strcmp(zOp,"memo")==0 ){
}
}else
{
- utf8_printf(stderr,
+ utf8_printf(STD_ERR,
"Unknown operation \"%s\" on selftest line %d\n", zOp, tno);
rc = 1;
break;
}
x = system(zCmd);
sqlite3_free(zCmd);
- if( x ) raw_printf(stderr, "%s command returns %d\n", azArg[0], x);
+ if( x ) raw_printf(STD_ERR, "%s command returns %d\n", azArg[0], x);
return 0;
}
#endif
}else if( nArg==1 ){
display_stats(p->db, p, 0);
}else{
- raw_printf(stderr, "Usage: .stats ?on|off|stmt|vmstep?\n");
+ raw_printf(STD_ERR, "Usage: .stats ?on|off|stmt|vmstep?\n");
return 1;
}
return 0;
/* It is an historical accident that the .indexes command shows an error
** when called with the wrong number of arguments whereas the .tables
** command does not. */
- raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
+ raw_printf(STD_ERR, "Usage: .indexes ?LIKE-PATTERN?\n");
sqlite3_finalize(pStmt);
return 1;
}
output_reset(p);
p->out = output_file_open("testcase-out.txt", 0);
if( p->out==0 ){
- raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
+ raw_printf(STD_ERR, "Error: cannot open 'testcase-out.txt'\n");
}
if( nArg>=2 ){
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
testctrl = aCtrl[i].ctrlCode;
iCtrl = i;
}else{
- utf8_printf(stderr, "Error: ambiguous test-control: \"%s\"\n"
+ utf8_printf(STD_ERR, "Error: ambiguous test-control: \"%s\"\n"
"Use \".testctrl --help\" for help\n", zCmd);
return 1;
}
}
}
if( testctrl<0 ){
- utf8_printf(stderr,"Error: unknown test-control: %s\n"
+ utf8_printf(STD_ERR,"Error: unknown test-control: %s\n"
"Use \".testctrl --help\" for help\n", zCmd);
}else if( aCtrl[iCtrl].unSafe && p->bSafeMode ){
- utf8_printf(stderr,
+ utf8_printf(STD_ERR,
"line %d: \".testctrl %s\" may not be used in safe mode\n",
p->lineno, aCtrl[iCtrl].zCtrlName);
exit(1);
sqlite3 *db;
if( ii==0 && strcmp(azArg[2],"random")==0 ){
sqlite3_randomness(sizeof(ii),&ii);
- printf("-- random seed: %d\n", ii);
+ fprintf(STD_OUT, "-- random seed: %d\n", ii);
}
if( nArg==3 ){
db = 0;
DISPATCHABLE_COMMAND( timer ? 2 2 ){
enableTimer = booleanValue(azArg[1]);
if( enableTimer && !HAS_TIMER ){
- raw_printf(stderr, "Error: timer not available on this system.\n");
+ raw_printf(STD_ERR, "Error: timer not available on this system.\n");
enableTimer = 0;
}
return 0;
mType |= SQLITE_TRACE_CLOSE;
}
else {
- raw_printf(stderr, "Unknown option \"%s\" on \".trace\"\n", z);
+ raw_printf(STD_ERR, "Unknown option \"%s\" on \".trace\"\n", z);
return 1;
}
}else{
;
if( nArg<2 ){
teach_fail:
- raw_printf(stderr, usage);
+ raw_printf(STD_ERR, usage);
return 1;
}
open_db(p, 0);
if( strcmp(azArg[1],"login")==0 ){
if( nArg!=4 ){
- raw_printf(stderr, usage);
+ raw_printf(STD_ERR, usage);
return 1;
}
rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
strlen30(azArg[3]));
if( rc ){
- utf8_printf(stderr, "Authentication failed for user %s\n", azArg[2]);
+ utf8_printf(STD_ERR, "Authentication failed for user %s\n", azArg[2]);
return 1;
}
}else if( strcmp(azArg[1],"add")==0 ){
rc = sqlite3_user_add(p->db, azArg[2], azArg[3], strlen30(azArg[3]),
booleanValue(azArg[4]));
if( rc ){
- raw_printf(stderr, "User-Add failed: %d\n", rc);
+ raw_printf(STD_ERR, "User-Add failed: %d\n", rc);
return 1;
}
}else if( strcmp(azArg[1],"edit")==0 ){
rc = sqlite3_user_change(p->db, azArg[2], azArg[3], strlen30(azArg[3]),
booleanValue(azArg[4]));
if( rc ){
- raw_printf(stderr, "User-Edit failed: %d\n", rc);
+ raw_printf(STD_ERR, "User-Edit failed: %d\n", rc);
return 1;
}
}else if( strcmp(azArg[1],"delete")==0 ){
}
rc = sqlite3_user_delete(p->db, azArg[2]);
if( rc ){
- raw_printf(stderr, "User-Delete failed: %d\n", rc);
+ raw_printf(STD_ERR, "User-Delete failed: %d\n", rc);
return 1;
}
}else{
{
int dispatchResult = dispatchCommand(azArg, nArg, p);
if( NO_SUCH_COMMAND==dispatchResult ){
- utf8_printf(stderr, "Error: unknown command: \"%s\"\n"
+ utf8_printf(STD_ERR, "Error: unknown command: \"%s\"\n"
" Enter \".help\" for a list of commands.\n", azArg[0]);
rc = 1;
}
if( INVALID_ARGS==dispatchResult ){
- utf8_printf(stderr, "Error: invalid arguments for \".%s\"\n"
+ utf8_printf(STD_ERR, "Error: invalid arguments for \".%s\"\n"
" Enter \".help %s\" for help on it.\n", azArg[0],azArg[0]);
rc = 1;
}
sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
}
if( zErrMsg!=0 ){
- utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
+ utf8_printf(STD_ERR, "%s %s\n", zPrefix, zErrMsg);
sqlite3_free(zErrMsg);
zErrMsg = 0;
}else{
- utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
+ utf8_printf(STD_ERR, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
}
return 1;
}else if( ShellHasFlag(p, SHFLG_CountChanges) ){
zLine = one_input_line(p->in, zLine, nSql>0);
if( zLine==0 ){
/* End of input */
- if( p->in==0 && stdin_is_interactive ) printf("\n");
+ if( p->in==0 && stdin_is_interactive ) fprintf(STD_OUT, "\n");
break;
}
if( seenInterrupt ){
qss = quickscan(zLine, qss);
if( QSS_PLAINWHITE(qss) && nSql==0 ){
if( ShellHasFlag(p, SHFLG_Echo) )
- printf("%s\n", zLine);
+ fprintf(STD_OUT, "%s\n", zLine);
/* Just swallow single-line whitespace */
qss = QSS_Start;
continue;
}
if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
- if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
+ if( ShellHasFlag(p, SHFLG_Echo) ) fprintf(STD_OUT, "%s\n", zLine);
if( zLine[0]=='.' ){
rc = do_meta_command(zLine, p);
if( rc==2 ){ /* exit requested */
p->bSafeMode = p->bSafeModeFuture!=1;
qss = QSS_Start;
}else if( nSql && QSS_PLAINWHITE(qss) ){
- if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
+ if( ShellHasFlag(p, SHFLG_Echo) ) fprintf(STD_OUT, "%s\n", zSql);
nSql = 0;
qss = QSS_Start;
}
if (sqliterc == NULL) {
home_dir = find_home_dir(0);
if( home_dir==0 ){
- raw_printf(stderr, "-- warning: cannot find home directory;"
+ raw_printf(STD_ERR, "-- warning: cannot find home directory;"
" cannot read ~/.sqliterc\n");
return;
}
p->in = fopen(sqliterc,"rb");
if( p->in ){
if( stdin_is_interactive ){
- utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc);
+ utf8_printf(STD_ERR,"-- Loading resources from %s\n",sqliterc);
}
if( process_input(p) && bail_on_error ) exit(1);
fclose(p->in);
}else if( sqliterc_override!=0 ){
- utf8_printf(stderr,"cannot open: \"%s\"\n", sqliterc);
+ utf8_printf(STD_ERR,"cannot open: \"%s\"\n", sqliterc);
if( bail_on_error ) exit(1);
}
p->in = inSaved;
#endif
;
static void usage(int showDetail){
- utf8_printf(stderr,
+ utf8_printf(STD_ERR,
"Usage: %s [OPTIONS] FILENAME [SQL]\n"
"FILENAME is the name of an SQLite database. A new database is created\n"
"if the file does not previously exist.\n", Argv0);
if( showDetail ){
- utf8_printf(stderr, "OPTIONS include:\n%s", zOptions);
+ utf8_printf(STD_ERR, "OPTIONS include:\n%s", zOptions);
}else{
- raw_printf(stderr, "Use the -help option for additional information\n");
+ raw_printf(STD_ERR, "Use the -help option for additional information\n");
}
exit(1);
}
*/
static void verify_uninitialized(void){
if( sqlite3_config(-1)==SQLITE_MISUSE ){
- utf8_printf(stdout, "WARNING: attempt to configure SQLite after"
+ utf8_printf(STD_OUT, "WARNING: attempt to configure SQLite after"
" initialization.\n");
}
}
FOREGROUND_RED|FOREGROUND_INTENSITY
);
#endif
- printf("%s", zText);
+ fprintf(STD_OUT, "%s", zText);
#if !SQLITE_OS_WINRT
SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
#endif
}
#else
static void printBold(const char *zText){
- printf("\033[1m%s\033[0m", zText);
+ fprintf(STD_OUT, "\033[1m%s\033[0m", zText);
}
#endif
*/
static char *cmdline_option_value(int argc, char **argv, int i){
if( i==argc ){
- utf8_printf(stderr, "%s: Error: missing argument to %s\n",
+ utf8_printf(STD_ERR, "%s: Error: missing argument to %s\n",
argv[0], argv[argc-1]);
exit(1);
}
# endif
#endif
+#ifndef SHELL_MAIN
+# if SQLITE_SHELL_IS_UTF8
+# define SHELL_MAIN main
+# else
+# define SHELL_MAIN wmain
+# endif
+#endif
+
#if SQLITE_SHELL_IS_UTF8
-int SQLITE_CDECL main(int argc, char **argv){
+int SQLITE_CDECL SHELL_MAIN(int argc, char **argv){
#else
-int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
+int SQLITE_CDECL SHELL_MAIN(int argc, wchar_t **wargv){
char **argv;
#endif
char *zErrMsg = 0;
int argcToFree = 0;
#endif
- setBinaryMode(stdin, 0);
- setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
+ setBinaryMode(STD_IN, 0);
+ setvbuf(STD_ERR, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
stdin_is_interactive = isatty(0);
stdout_is_console = isatty(1);
#if !defined(_WIN32_WCE)
if( getenv("SQLITE_DEBUG_BREAK") ){
if( isatty(0) && isatty(2) ){
- fprintf(stderr,
+ fprintf(STD_ERR,
"attach debugger to process %d and press any key to continue.\n",
GETPID());
- fgetc(stdin);
+ fgetc(STD_IN);
}else{
#if defined(_WIN32) || defined(WIN32)
#if SQLITE_OS_WINRT
#if USE_SYSTEM_SQLITE+0!=1
if( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
- utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
+ utf8_printf(STD_ERR, "SQLite header and source version mismatch\n%s\n%s\n",
sqlite3_sourceid(), SQLITE_SOURCE_ID);
exit(1);
}
void *pOutArg,
int makeDefault
);
- vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
+ vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,STD_ERR,1);
#endif
#ifdef SQLITE_ENABLE_MULTIPLEX
}else if( strcmp(z,"-multiplex")==0 ){
break;
#endif
}else if( strcmp(z, "-memtrace")==0 ){
- sqlite3MemTraceActivate(stderr);
+ sqlite3MemTraceActivate(STD_ERR);
}else if( strcmp(z,"-bail")==0 ){
bail_on_error = 1;
}else if( strcmp(z,"-nonce")==0 ){
if( pVfs ){
sqlite3_vfs_register(pVfs, 1);
}else{
- utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
+ utf8_printf(STD_ERR, "no such VFS: \"%s\"\n", argv[i]);
exit(1);
}
}
data.pAuxDb->zDbFilename = ":memory:";
warnInmemoryDb = argc==1;
#else
- utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
+ utf8_printf(STD_ERR,"%s: Error: no database filename specified\n", Argv0);
return 1;
#endif
}
- data.out = stdout;
+ data.out = STD_OUT;
sqlite3_appendvfs_init(0,0,0);
/* Go ahead and open the database file if it already exists. If the
}else if( strcmp(z,"-bail")==0 ){
/* No-op. The bail_on_error flag should already be set. */
}else if( strcmp(z,"-version")==0 ){
- printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
+ fprintf(STD_OUT, "%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
return 0;
}else if( strcmp(z,"-interactive")==0 ){
stdin_is_interactive = 1;
open_db(&data, 0);
rc = shell_exec(&data, z, &zErrMsg);
if( zErrMsg!=0 ){
- utf8_printf(stderr,"Error: %s\n", zErrMsg);
+ utf8_printf(STD_ERR,"Error: %s\n", zErrMsg);
if( bail_on_error ) return rc!=0 ? rc : 1;
}else if( rc!=0 ){
- utf8_printf(stderr,"Error: unable to process SQL \"%s\"\n", z);
+ utf8_printf(STD_ERR,"Error: unable to process SQL \"%s\"\n", z);
if( bail_on_error ) return rc;
}
}
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
}else if( strncmp(z, "-A", 2)==0 ){
if( nCmd>0 ){
- utf8_printf(stderr, "Error: cannot mix regular SQL or dot-commands"
+ utf8_printf(STD_ERR, "Error: cannot mix regular SQL or dot-commands"
" with \"%s\"\n", z);
return 1;
}
}else if( strcmp(z,"-safe")==0 ){
data.bSafeMode = data.bSafeModeFuture = 1;
}else{
- utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
- raw_printf(stderr,"Use -help for a list of options.\n");
+ utf8_printf(STD_ERR,"%s: Error: unknown option: %s\n", Argv0, z);
+ raw_printf(STD_ERR,"Use -help for a list of options.\n");
return 1;
}
data.cMode = data.mode;
rc = shell_exec(&data, azCmd[i], &zErrMsg);
if( zErrMsg || rc ){
if( zErrMsg!=0 ){
- utf8_printf(stderr,"Error: %s\n", zErrMsg);
+ utf8_printf(STD_ERR,"Error: %s\n", zErrMsg);
}else{
- utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
+ utf8_printf(STD_ERR,"Error: unable to process SQL: %s\n", azCmd[i]);
}
sqlite3_free(zErrMsg);
free(azCmd);
char *zHome;
char *zHistory;
int nHistory;
- printf(
+ fprintf(STD_OUT,
"SQLite version %s %.19s\n" /*extra-version-info*/
"Enter \".help\" for usage hints.\n",
sqlite3_libversion(), sqlite3_sourceid()
);
if( warnInmemoryDb ){
- printf("Connected to a ");
+ fprintf(STD_OUT, "Connected to a ");
printBold("transient in-memory database");
- printf(".\nUse \".open FILENAME\" to reopen on a "
+ fprintf(STD_OUT, ".\nUse \".open FILENAME\" to reopen on a "
"persistent database.\n");
}
zHistory = getenv("SQLITE_HISTORY");
free(zHistory);
}
}else{
- data.in = stdin;
+ data.in = STD_IN;
rc = process_input(&data);
}
}