Deleted Added
full compact
shell.c (361456) shell.c (362190)
1/* DO NOT EDIT!
2** This file is automatically generated by the script in the canonical
3** SQLite source tree at tool/mkshellc.tcl. That script combines source
4** code from various constituent source files of SQLite into this single
5** "shell.c" file used to implement the SQLite command-line shell.
6**
7** Most of the code found below comes from the "src/shell.c.in" file in
8** the canonical SQLite source tree. That main file contains "INCLUDE"

--- 22 unchanged lines hidden (view full) ---

31** utility for accessing SQLite databases.
32*/
33#if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
34/* This needs to come before any includes for MSVC compiler */
35#define _CRT_SECURE_NO_WARNINGS
36#endif
37
38/*
1/* DO NOT EDIT!
2** This file is automatically generated by the script in the canonical
3** SQLite source tree at tool/mkshellc.tcl. That script combines source
4** code from various constituent source files of SQLite into this single
5** "shell.c" file used to implement the SQLite command-line shell.
6**
7** Most of the code found below comes from the "src/shell.c.in" file in
8** the canonical SQLite source tree. That main file contains "INCLUDE"

--- 22 unchanged lines hidden (view full) ---

31** utility for accessing SQLite databases.
32*/
33#if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
34/* This needs to come before any includes for MSVC compiler */
35#define _CRT_SECURE_NO_WARNINGS
36#endif
37
38/*
39** Determine if we are dealing with WinRT, which provides only a subset of
40** the full Win32 API.
41*/
42#if !defined(SQLITE_OS_WINRT)
43# define SQLITE_OS_WINRT 0
44#endif
45
46/*
39** Warning pragmas copied from msvc.h in the core.
40*/
41#if defined(_MSC_VER)
42#pragma warning(disable : 4054)
43#pragma warning(disable : 4055)
44#pragma warning(disable : 4100)
45#pragma warning(disable : 4127)
46#pragma warning(disable : 4130)

--- 95 unchanged lines hidden (view full) ---

142# define shell_write_history(X)
143# define shell_stifle_history(X)
144
145# define SHELL_USE_LOCAL_GETLINE 1
146#endif
147
148
149#if defined(_WIN32) || defined(WIN32)
47** Warning pragmas copied from msvc.h in the core.
48*/
49#if defined(_MSC_VER)
50#pragma warning(disable : 4054)
51#pragma warning(disable : 4055)
52#pragma warning(disable : 4100)
53#pragma warning(disable : 4127)
54#pragma warning(disable : 4130)

--- 95 unchanged lines hidden (view full) ---

150# define shell_write_history(X)
151# define shell_stifle_history(X)
152
153# define SHELL_USE_LOCAL_GETLINE 1
154#endif
155
156
157#if defined(_WIN32) || defined(WIN32)
150# include <io.h>
151# include <fcntl.h>
152# define isatty(h) _isatty(h)
153# ifndef access
154# define access(f,m) _access((f),(m))
158# if SQLITE_OS_WINRT
159# define SQLITE_OMIT_POPEN 1
160# else
161# include <io.h>
162# include <fcntl.h>
163# define isatty(h) _isatty(h)
164# ifndef access
165# define access(f,m) _access((f),(m))
166# endif
167# ifndef unlink
168# define unlink _unlink
169# endif
170# ifndef strdup
171# define strdup _strdup
172# endif
173# undef popen
174# define popen _popen
175# undef pclose
176# define pclose _pclose
155# endif
177# endif
156# ifndef unlink
157# define unlink _unlink
158# endif
159# ifndef strdup
160# define strdup _strdup
161# endif
162# undef popen
163# define popen _popen
164# undef pclose
165# define pclose _pclose
166#else
167 /* Make sure isatty() has a prototype. */
168 extern int isatty(int);
169
170# if !defined(__RTP__) && !defined(_WRS_KERNEL)
171 /* popen and pclose are not C89 functions and so are
172 ** sometimes omitted from the <stdio.h> header */
173 extern FILE *popen(const char*,const char*);

--- 12 unchanged lines hidden (view full) ---

186#endif
187
188/* ctype macros that work with signed characters */
189#define IsSpace(X) isspace((unsigned char)X)
190#define IsDigit(X) isdigit((unsigned char)X)
191#define ToLower(X) (char)tolower((unsigned char)X)
192
193#if defined(_WIN32) || defined(WIN32)
178#else
179 /* Make sure isatty() has a prototype. */
180 extern int isatty(int);
181
182# if !defined(__RTP__) && !defined(_WRS_KERNEL)
183 /* popen and pclose are not C89 functions and so are
184 ** sometimes omitted from the <stdio.h> header */
185 extern FILE *popen(const char*,const char*);

--- 12 unchanged lines hidden (view full) ---

198#endif
199
200/* ctype macros that work with signed characters */
201#define IsSpace(X) isspace((unsigned char)X)
202#define IsDigit(X) isdigit((unsigned char)X)
203#define ToLower(X) (char)tolower((unsigned char)X)
204
205#if defined(_WIN32) || defined(WIN32)
206#if SQLITE_OS_WINRT
207#include <intrin.h>
208#endif
194#include <windows.h>
195
196/* string conversion routines only needed on Win32 */
197extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
198extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int);
199extern char *sqlite3_win32_utf8_to_mbcs_v2(const char *, int);
200extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText);
201#endif
202
203/* On Windows, we normally run with output mode of TEXT so that \n characters
204** are automatically translated into \r\n. However, this behavior needs
205** to be disabled in some cases (ex: when generating CSV output and when
206** rendering quoted strings that contain \n characters). The following
207** routines take care of that.
208*/
209#include <windows.h>
210
211/* string conversion routines only needed on Win32 */
212extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
213extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int);
214extern char *sqlite3_win32_utf8_to_mbcs_v2(const char *, int);
215extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText);
216#endif
217
218/* On Windows, we normally run with output mode of TEXT so that \n characters
219** are automatically translated into \r\n. However, this behavior needs
220** to be disabled in some cases (ex: when generating CSV output and when
221** rendering quoted strings that contain \n characters). The following
222** routines take care of that.
223*/
209#if defined(_WIN32) || defined(WIN32)
224#if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
210static void setBinaryMode(FILE *file, int isOutput){
211 if( isOutput ) fflush(file);
212 _setmode(_fileno(file), _O_BINARY);
213}
214static void setTextMode(FILE *file, int isOutput){
215 if( isOutput ) fflush(file);
216 _setmode(_fileno(file), _O_TEXT);
217}

--- 87 unchanged lines hidden (view full) ---

305/*
306** Check to see if we have timer support. Return 1 if necessary
307** support found (or found previously).
308*/
309static int hasTimer(void){
310 if( getProcessTimesAddr ){
311 return 1;
312 } else {
225static void setBinaryMode(FILE *file, int isOutput){
226 if( isOutput ) fflush(file);
227 _setmode(_fileno(file), _O_BINARY);
228}
229static void setTextMode(FILE *file, int isOutput){
230 if( isOutput ) fflush(file);
231 _setmode(_fileno(file), _O_TEXT);
232}

--- 87 unchanged lines hidden (view full) ---

320/*
321** Check to see if we have timer support. Return 1 if necessary
322** support found (or found previously).
323*/
324static int hasTimer(void){
325 if( getProcessTimesAddr ){
326 return 1;
327 } else {
328#if !SQLITE_OS_WINRT
313 /* GetProcessTimes() isn't supported in WIN95 and some other Windows
314 ** versions. See if the version we are running on has it, and if it
315 ** does, save off a pointer to it and the current process handle.
316 */
317 hProcess = GetCurrentProcess();
318 if( hProcess ){
319 HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
320 if( NULL != hinstLib ){
321 getProcessTimesAddr =
322 (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
323 if( NULL != getProcessTimesAddr ){
324 return 1;
325 }
326 FreeLibrary(hinstLib);
327 }
328 }
329 /* GetProcessTimes() isn't supported in WIN95 and some other Windows
330 ** versions. See if the version we are running on has it, and if it
331 ** does, save off a pointer to it and the current process handle.
332 */
333 hProcess = GetCurrentProcess();
334 if( hProcess ){
335 HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
336 if( NULL != hinstLib ){
337 getProcessTimesAddr =
338 (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
339 if( NULL != getProcessTimesAddr ){
340 return 1;
341 }
342 FreeLibrary(hinstLib);
343 }
344 }
345#endif
329 }
330 return 0;
331}
332
333/*
334** Begin timing an operation
335*/
336static void beginTimer(void){

--- 73 unchanged lines hidden (view full) ---

410*/
411static sqlite3 *globalDb = 0;
412
413/*
414** True if an interrupt (Control-C) has been received.
415*/
416static volatile int seenInterrupt = 0;
417
346 }
347 return 0;
348}
349
350/*
351** Begin timing an operation
352*/
353static void beginTimer(void){

--- 73 unchanged lines hidden (view full) ---

427*/
428static sqlite3 *globalDb = 0;
429
430/*
431** True if an interrupt (Control-C) has been received.
432*/
433static volatile int seenInterrupt = 0;
434
435#ifdef SQLITE_DEBUG
418/*
436/*
437** Out-of-memory simulator variables
438*/
439static unsigned int oomCounter = 0; /* Simulate OOM when equals 1 */
440static unsigned int oomRepeat = 0; /* Number of OOMs in a row */
441static void*(*defaultMalloc)(int) = 0; /* The low-level malloc routine */
442#endif /* SQLITE_DEBUG */
443
444/*
419** This is the name of our program. It is set in main(), used
420** in a number of other places, mostly for error messages.
421*/
422static char *Argv0;
423
424/*
425** Prompt strings. Initialized in main. Settable with
426** .prompt main continue

--- 34 unchanged lines hidden (view full) ---

461#endif
462
463/* Indicate out-of-memory and exit. */
464static void shell_out_of_memory(void){
465 raw_printf(stderr,"Error: out of memory\n");
466 exit(1);
467}
468
445** This is the name of our program. It is set in main(), used
446** in a number of other places, mostly for error messages.
447*/
448static char *Argv0;
449
450/*
451** Prompt strings. Initialized in main. Settable with
452** .prompt main continue

--- 34 unchanged lines hidden (view full) ---

487#endif
488
489/* Indicate out-of-memory and exit. */
490static void shell_out_of_memory(void){
491 raw_printf(stderr,"Error: out of memory\n");
492 exit(1);
493}
494
495#ifdef SQLITE_DEBUG
496/* This routine is called when a simulated OOM occurs. It is broken
497** out as a separate routine to make it easy to set a breakpoint on
498** the OOM
499*/
500void shellOomFault(void){
501 if( oomRepeat>0 ){
502 oomRepeat--;
503 }else{
504 oomCounter--;
505 }
506}
507#endif /* SQLITE_DEBUG */
508
509#ifdef SQLITE_DEBUG
510/* This routine is a replacement malloc() that is used to simulate
511** Out-Of-Memory (OOM) errors for testing purposes.
512*/
513static void *oomMalloc(int nByte){
514 if( oomCounter ){
515 if( oomCounter==1 ){
516 shellOomFault();
517 return 0;
518 }else{
519 oomCounter--;
520 }
521 }
522 return defaultMalloc(nByte);
523}
524#endif /* SQLITE_DEBUG */
525
526#ifdef SQLITE_DEBUG
527/* Register the OOM simulator. This must occur before any memory
528** allocations */
529static void registerOomSimulator(void){
530 sqlite3_mem_methods mem;
531 sqlite3_config(SQLITE_CONFIG_GETMALLOC, &mem);
532 defaultMalloc = mem.xMalloc;
533 mem.xMalloc = oomMalloc;
534 sqlite3_config(SQLITE_CONFIG_MALLOC, &mem);
535}
536#endif
537
469/*
470** Write I/O traces to the following stream.
471*/
472#ifdef SQLITE_ENABLE_IOTRACE
473static FILE *iotrace = 0;
474#endif
475
476/*

--- 1944 unchanged lines hidden (view full) ---

2421 }
2422 if( rc ) return 2;
2423 sqlite3_result_int64(pCtx, nWrite);
2424 }
2425 }
2426
2427 if( mtime>=0 ){
2428#if defined(_WIN32)
538/*
539** Write I/O traces to the following stream.
540*/
541#ifdef SQLITE_ENABLE_IOTRACE
542static FILE *iotrace = 0;
543#endif
544
545/*

--- 1944 unchanged lines hidden (view full) ---

2490 }
2491 if( rc ) return 2;
2492 sqlite3_result_int64(pCtx, nWrite);
2493 }
2494 }
2495
2496 if( mtime>=0 ){
2497#if defined(_WIN32)
2498#if !SQLITE_OS_WINRT
2429 /* Windows */
2430 FILETIME lastAccess;
2431 FILETIME lastWrite;
2432 SYSTEMTIME currentTime;
2433 LONGLONG intervals;
2434 HANDLE hFile;
2435 LPWSTR zUnicodeName;
2436 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);

--- 14 unchanged lines hidden (view full) ---

2451 sqlite3_free(zUnicodeName);
2452 if( hFile!=INVALID_HANDLE_VALUE ){
2453 BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
2454 CloseHandle(hFile);
2455 return !bResult;
2456 }else{
2457 return 1;
2458 }
2499 /* Windows */
2500 FILETIME lastAccess;
2501 FILETIME lastWrite;
2502 SYSTEMTIME currentTime;
2503 LONGLONG intervals;
2504 HANDLE hFile;
2505 LPWSTR zUnicodeName;
2506 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);

--- 14 unchanged lines hidden (view full) ---

2521 sqlite3_free(zUnicodeName);
2522 if( hFile!=INVALID_HANDLE_VALUE ){
2523 BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
2524 CloseHandle(hFile);
2525 return !bResult;
2526 }else{
2527 return 1;
2528 }
2529#endif
2459#elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
2460 /* Recent unix */
2461 struct timespec times[2];
2462 times[0].tv_nsec = times[1].tv_nsec = 0;
2463 times[0].tv_sec = time(0);
2464 times[1].tv_sec = mtime;
2465 if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
2466 return 1;

--- 1741 unchanged lines hidden (view full) ---

4208 memset(&memtraceBase, 0, sizeof(memtraceBase));
4209 }
4210 }
4211 memtraceOut = 0;
4212 return rc;
4213}
4214
4215/************************* End ../ext/misc/memtrace.c ********************/
2530#elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
2531 /* Recent unix */
2532 struct timespec times[2];
2533 times[0].tv_nsec = times[1].tv_nsec = 0;
2534 times[0].tv_sec = time(0);
2535 times[1].tv_sec = mtime;
2536 if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
2537 return 1;

--- 1741 unchanged lines hidden (view full) ---

4279 memset(&memtraceBase, 0, sizeof(memtraceBase));
4280 }
4281 }
4282 memtraceOut = 0;
4283 return rc;
4284}
4285
4286/************************* End ../ext/misc/memtrace.c ********************/
4287/************************* Begin ../ext/misc/uint.c ******************/
4288/*
4289** 2020-04-14
4290**
4291** The author disclaims copyright to this source code. In place of
4292** a legal notice, here is a blessing:
4293**
4294** May you do good and not evil.
4295** May you find forgiveness for yourself and forgive others.
4296** May you share freely, never taking more than you give.
4297**
4298******************************************************************************
4299**
4300** This SQLite extension implements the UINT collating sequence.
4301**
4302** UINT works like BINARY for text, except that embedded strings
4303** of digits compare in numeric order.
4304**
4305** * Leading zeros are handled properly, in the sense that
4306** they do not mess of the maginitude comparison of embedded
4307** strings of digits. "x00123y" is equal to "x123y".
4308**
4309** * Only unsigned integers are recognized. Plus and minus
4310** signs are ignored. Decimal points and exponential notation
4311** are ignored.
4312**
4313** * Embedded integers can be of arbitrary length. Comparison
4314** is *not* limited integers that can be expressed as a
4315** 64-bit machine integer.
4316*/
4317/* #include "sqlite3ext.h" */
4318SQLITE_EXTENSION_INIT1
4319#include <assert.h>
4320#include <string.h>
4321#include <ctype.h>
4322
4323/*
4324** Compare text in lexicographic order, except strings of digits
4325** compare in numeric order.
4326*/
4327static int uintCollFunc(
4328 void *notUsed,
4329 int nKey1, const void *pKey1,
4330 int nKey2, const void *pKey2
4331){
4332 const unsigned char *zA = (const unsigned char*)pKey1;
4333 const unsigned char *zB = (const unsigned char*)pKey2;
4334 int i=0, j=0, x;
4335 (void)notUsed;
4336 while( i<nKey1 && j<nKey2 ){
4337 x = zA[i] - zB[j];
4338 if( isdigit(zA[i]) ){
4339 int k;
4340 if( !isdigit(zB[j]) ) return x;
4341 while( i<nKey1 && zA[i]=='0' ){ i++; }
4342 while( j<nKey2 && zB[j]=='0' ){ j++; }
4343 k = 0;
4344 while( i+k<nKey1 && isdigit(zA[i+k])
4345 && j+k<nKey2 && isdigit(zB[j+k]) ){
4346 k++;
4347 }
4348 if( i+k<nKey1 && isdigit(zA[i+k]) ){
4349 return +1;
4350 }else if( j+k<nKey2 && isdigit(zB[j+k]) ){
4351 return -1;
4352 }else{
4353 x = memcmp(zA+i, zB+j, k);
4354 if( x ) return x;
4355 i += k;
4356 j += k;
4357 }
4358 }else if( x ){
4359 return x;
4360 }else{
4361 i++;
4362 j++;
4363 }
4364 }
4365 return (nKey1 - i) - (nKey2 - j);
4366}
4367
4368#ifdef _WIN32
4369
4370#endif
4371int sqlite3_uint_init(
4372 sqlite3 *db,
4373 char **pzErrMsg,
4374 const sqlite3_api_routines *pApi
4375){
4376 SQLITE_EXTENSION_INIT2(pApi);
4377 (void)pzErrMsg; /* Unused parameter */
4378 return sqlite3_create_collation(db, "uint", SQLITE_UTF8, 0, uintCollFunc);
4379}
4380
4381/************************* End ../ext/misc/uint.c ********************/
4216#ifdef SQLITE_HAVE_ZLIB
4217/************************* Begin ../ext/misc/zipfile.c ******************/
4218/*
4219** 2017-12-26
4220**
4221** The author disclaims copyright to this source code. In place of
4222** a legal notice, here is a blessing:
4223**

--- 2196 unchanged lines hidden (view full) ---

6420**
6421** Utility functions sqlar_compress() and sqlar_uncompress(). Useful
6422** for working with sqlar archives and used by the shell tool's built-in
6423** sqlar support.
6424*/
6425/* #include "sqlite3ext.h" */
6426SQLITE_EXTENSION_INIT1
6427#include <zlib.h>
4382#ifdef SQLITE_HAVE_ZLIB
4383/************************* Begin ../ext/misc/zipfile.c ******************/
4384/*
4385** 2017-12-26
4386**
4387** The author disclaims copyright to this source code. In place of
4388** a legal notice, here is a blessing:
4389**

--- 2196 unchanged lines hidden (view full) ---

6586**
6587** Utility functions sqlar_compress() and sqlar_uncompress(). Useful
6588** for working with sqlar archives and used by the shell tool's built-in
6589** sqlar support.
6590*/
6591/* #include "sqlite3ext.h" */
6592SQLITE_EXTENSION_INIT1
6593#include <zlib.h>
6594#include <assert.h>
6428
6429/*
6430** Implementation of the "sqlar_compress(X)" SQL function.
6431**
6432** If the type of X is SQLITE_BLOB, and compressing that blob using
6433** zlib utility function compress() yields a smaller blob, return the
6434** compressed blob. Otherwise, return a copy of X.
6435**

--- 1393 unchanged lines hidden (view full) ---

7829 rc = idxPrintfPrepareStmt(dbm, &pExplain, pzErr,
7830 "EXPLAIN QUERY PLAN %s", pStmt->zSql
7831 );
7832 while( rc==SQLITE_OK && sqlite3_step(pExplain)==SQLITE_ROW ){
7833 /* int iId = sqlite3_column_int(pExplain, 0); */
7834 /* int iParent = sqlite3_column_int(pExplain, 1); */
7835 /* int iNotUsed = sqlite3_column_int(pExplain, 2); */
7836 const char *zDetail = (const char*)sqlite3_column_text(pExplain, 3);
6595
6596/*
6597** Implementation of the "sqlar_compress(X)" SQL function.
6598**
6599** If the type of X is SQLITE_BLOB, and compressing that blob using
6600** zlib utility function compress() yields a smaller blob, return the
6601** compressed blob. Otherwise, return a copy of X.
6602**

--- 1393 unchanged lines hidden (view full) ---

7996 rc = idxPrintfPrepareStmt(dbm, &pExplain, pzErr,
7997 "EXPLAIN QUERY PLAN %s", pStmt->zSql
7998 );
7999 while( rc==SQLITE_OK && sqlite3_step(pExplain)==SQLITE_ROW ){
8000 /* int iId = sqlite3_column_int(pExplain, 0); */
8001 /* int iParent = sqlite3_column_int(pExplain, 1); */
8002 /* int iNotUsed = sqlite3_column_int(pExplain, 2); */
8003 const char *zDetail = (const char*)sqlite3_column_text(pExplain, 3);
7837 int nDetail = STRLEN(zDetail);
8004 int nDetail;
7838 int i;
7839
8005 int i;
8006
8007 if( !zDetail ) continue;
8008 nDetail = STRLEN(zDetail);
8009
7840 for(i=0; i<nDetail; i++){
7841 const char *zIdx = 0;
8010 for(i=0; i<nDetail; i++){
8011 const char *zIdx = 0;
7842 if( memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
8012 if( i+13<nDetail && memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
7843 zIdx = &zDetail[i+13];
8013 zIdx = &zDetail[i+13];
7844 }else if( memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0 ){
8014 }else if( i+22<nDetail
8015 && memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0
8016 ){
7845 zIdx = &zDetail[i+22];
7846 }
7847 if( zIdx ){
7848 const char *zSql;
7849 int nIdx = 0;
7850 while( zIdx[nIdx]!='\0' && (zIdx[nIdx]!=' ' || zIdx[nIdx+1]!='(') ){
7851 nIdx++;
7852 }

--- 798 unchanged lines hidden (view full) ---

8651 idxTableFree(p->pTable);
8652 idxWriteFree(p->pWrite);
8653 idxHashClear(&p->hIdx);
8654 sqlite3_free(p->zCandidates);
8655 sqlite3_free(p);
8656 }
8657}
8658
8017 zIdx = &zDetail[i+22];
8018 }
8019 if( zIdx ){
8020 const char *zSql;
8021 int nIdx = 0;
8022 while( zIdx[nIdx]!='\0' && (zIdx[nIdx]!=' ' || zIdx[nIdx+1]!='(') ){
8023 nIdx++;
8024 }

--- 798 unchanged lines hidden (view full) ---

8823 idxTableFree(p->pTable);
8824 idxWriteFree(p->pWrite);
8825 idxHashClear(&p->hIdx);
8826 sqlite3_free(p->zCandidates);
8827 sqlite3_free(p);
8828 }
8829}
8830
8659#endif /* ifndef SQLITE_OMIT_VIRTUAL_TABLE */
8831#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
8660
8661/************************* End ../ext/expert/sqlite3expert.c ********************/
8662
8663#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
8664/************************* Begin ../ext/misc/dbdata.c ******************/
8665/*
8666** 2019-04-17
8667**

--- 929 unchanged lines hidden (view full) ---

9597 int normalMode; /* Output mode before ".explain on" */
9598 int writableSchema; /* True if PRAGMA writable_schema=ON */
9599 int showHeader; /* True to show column names in List or Column mode */
9600 int nCheck; /* Number of ".check" commands run */
9601 unsigned nProgress; /* Number of progress callbacks encountered */
9602 unsigned mxProgress; /* Maximum progress callbacks before failing */
9603 unsigned flgProgress; /* Flags for the progress callback */
9604 unsigned shellFlgs; /* Various flags */
8832
8833/************************* End ../ext/expert/sqlite3expert.c ********************/
8834
8835#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
8836/************************* Begin ../ext/misc/dbdata.c ******************/
8837/*
8838** 2019-04-17
8839**

--- 929 unchanged lines hidden (view full) ---

9769 int normalMode; /* Output mode before ".explain on" */
9770 int writableSchema; /* True if PRAGMA writable_schema=ON */
9771 int showHeader; /* True to show column names in List or Column mode */
9772 int nCheck; /* Number of ".check" commands run */
9773 unsigned nProgress; /* Number of progress callbacks encountered */
9774 unsigned mxProgress; /* Maximum progress callbacks before failing */
9775 unsigned flgProgress; /* Flags for the progress callback */
9776 unsigned shellFlgs; /* Various flags */
9777 unsigned priorShFlgs; /* Saved copy of flags */
9605 sqlite3_int64 szMax; /* --maxsize argument to .open */
9606 char *zDestTable; /* Name of destination table when MODE_Insert */
9607 char *zTempFile; /* Temporary file that might need deleting */
9608 char zTestcase[30]; /* Name of current test case */
9609 char colSeparator[20]; /* Column separator character for several modes */
9610 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
9611 char colSepPrior[20]; /* Saved column separator */
9612 char rowSepPrior[20]; /* Saved row separator */

--- 284 unchanged lines hidden (view full) ---

9897}
9898#endif /* SQLITE_NOHAVE_SYSTEM */
9899
9900/*
9901** Save or restore the current output mode
9902*/
9903static void outputModePush(ShellState *p){
9904 p->modePrior = p->mode;
9778 sqlite3_int64 szMax; /* --maxsize argument to .open */
9779 char *zDestTable; /* Name of destination table when MODE_Insert */
9780 char *zTempFile; /* Temporary file that might need deleting */
9781 char zTestcase[30]; /* Name of current test case */
9782 char colSeparator[20]; /* Column separator character for several modes */
9783 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
9784 char colSepPrior[20]; /* Saved column separator */
9785 char rowSepPrior[20]; /* Saved row separator */

--- 284 unchanged lines hidden (view full) ---

10070}
10071#endif /* SQLITE_NOHAVE_SYSTEM */
10072
10073/*
10074** Save or restore the current output mode
10075*/
10076static void outputModePush(ShellState *p){
10077 p->modePrior = p->mode;
10078 p->priorShFlgs = p->shellFlgs;
9905 memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));
9906 memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator));
9907}
9908static void outputModePop(ShellState *p){
9909 p->mode = p->modePrior;
10079 memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));
10080 memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator));
10081}
10082static void outputModePop(ShellState *p){
10083 p->mode = p->modePrior;
10084 p->shellFlgs = p->priorShFlgs;
9910 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
9911 memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
9912}
9913
9914/*
9915** Output the given string as a hex-encoded blob (eg. X'1234' )
9916*/
9917static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){

--- 948 unchanged lines hidden (view full) ---

10866**
10867** If the number of columns is 1 and that column contains text "--"
10868** then write the semicolon on a separate line. That way, if a
10869** "--" comment occurs at the end of the statement, the comment
10870** won't consume the semicolon terminator.
10871*/
10872static int run_table_dump_query(
10873 ShellState *p, /* Query context */
10085 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
10086 memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
10087}
10088
10089/*
10090** Output the given string as a hex-encoded blob (eg. X'1234' )
10091*/
10092static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){

--- 948 unchanged lines hidden (view full) ---

11041**
11042** If the number of columns is 1 and that column contains text "--"
11043** then write the semicolon on a separate line. That way, if a
11044** "--" comment occurs at the end of the statement, the comment
11045** won't consume the semicolon terminator.
11046*/
11047static int run_table_dump_query(
11048 ShellState *p, /* Query context */
10874 const char *zSelect, /* SELECT statement to extract content */
10875 const char *zFirstRow /* Print before first row, if not NULL */
11049 const char *zSelect /* SELECT statement to extract content */
10876){
10877 sqlite3_stmt *pSelect;
10878 int rc;
10879 int nResult;
10880 int i;
10881 const char *z;
10882 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
10883 if( rc!=SQLITE_OK || !pSelect ){
10884 utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
10885 sqlite3_errmsg(p->db));
10886 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
10887 return rc;
10888 }
10889 rc = sqlite3_step(pSelect);
10890 nResult = sqlite3_column_count(pSelect);
10891 while( rc==SQLITE_ROW ){
11050){
11051 sqlite3_stmt *pSelect;
11052 int rc;
11053 int nResult;
11054 int i;
11055 const char *z;
11056 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
11057 if( rc!=SQLITE_OK || !pSelect ){
11058 utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
11059 sqlite3_errmsg(p->db));
11060 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
11061 return rc;
11062 }
11063 rc = sqlite3_step(pSelect);
11064 nResult = sqlite3_column_count(pSelect);
11065 while( rc==SQLITE_ROW ){
10892 if( zFirstRow ){
10893 utf8_printf(p->out, "%s", zFirstRow);
10894 zFirstRow = 0;
10895 }
10896 z = (const char*)sqlite3_column_text(pSelect, 0);
10897 utf8_printf(p->out, "%s", z);
10898 for(i=1; i<nResult; i++){
10899 utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
10900 }
10901 if( z==0 ) z = "";
10902 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
10903 if( z[0] ){

--- 440 unchanged lines hidden (view full) ---

11344/*
11345** Bind parameters on a prepared statement.
11346**
11347** Parameter bindings are taken from a TEMP table of the form:
11348**
11349** CREATE TEMP TABLE sqlite_parameters(key TEXT PRIMARY KEY, value)
11350** WITHOUT ROWID;
11351**
11066 z = (const char*)sqlite3_column_text(pSelect, 0);
11067 utf8_printf(p->out, "%s", z);
11068 for(i=1; i<nResult; i++){
11069 utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
11070 }
11071 if( z==0 ) z = "";
11072 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
11073 if( z[0] ){

--- 440 unchanged lines hidden (view full) ---

11514/*
11515** Bind parameters on a prepared statement.
11516**
11517** Parameter bindings are taken from a TEMP table of the form:
11518**
11519** CREATE TEMP TABLE sqlite_parameters(key TEXT PRIMARY KEY, value)
11520** WITHOUT ROWID;
11521**
11352** No bindings occur if this table does not exist. The special character '$'
11353** is included in the table name to help prevent collisions with actual tables.
11354** The table must be in the TEMP schema.
11522** No bindings occur if this table does not exist. The name of the table
11523** begins with "sqlite_" so that it will not collide with ordinary application
11524** tables. The table must be in the TEMP schema.
11355*/
11356static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
11357 int nVar;
11358 int i;
11359 int rc;
11360 sqlite3_stmt *pQ = 0;
11361
11362 nVar = sqlite3_bind_parameter_count(pStmt);

--- 287 unchanged lines hidden (view full) ---

11650 }
11651 zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
11652 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
11653 if( rc==SQLITE_OK ){
11654 while( sqlite3_step(pExplain)==SQLITE_ROW ){
11655 const char *zEQPLine = (const char*)sqlite3_column_text(pExplain,3);
11656 int iEqpId = sqlite3_column_int(pExplain, 0);
11657 int iParentId = sqlite3_column_int(pExplain, 1);
11525*/
11526static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
11527 int nVar;
11528 int i;
11529 int rc;
11530 sqlite3_stmt *pQ = 0;
11531
11532 nVar = sqlite3_bind_parameter_count(pStmt);

--- 287 unchanged lines hidden (view full) ---

11820 }
11821 zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
11822 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
11823 if( rc==SQLITE_OK ){
11824 while( sqlite3_step(pExplain)==SQLITE_ROW ){
11825 const char *zEQPLine = (const char*)sqlite3_column_text(pExplain,3);
11826 int iEqpId = sqlite3_column_int(pExplain, 0);
11827 int iParentId = sqlite3_column_int(pExplain, 1);
11828 if( zEQPLine==0 ) zEQPLine = "";
11658 if( zEQPLine[0]=='-' ) eqp_render(pArg);
11659 eqp_append(pArg, iEqpId, iParentId, zEQPLine);
11660 }
11661 eqp_render(pArg);
11662 }
11663 sqlite3_finalize(pExplain);
11664 sqlite3_free(zEQP);
11665 if( pArg->autoEQP>=AUTOEQP_full ){

--- 394 unchanged lines hidden (view full) ---

12060 ".binary on|off Turn binary output on or off. Default OFF",
12061 ".cd DIRECTORY Change the working directory to DIRECTORY",
12062 ".changes on|off Show number of rows changed by SQL",
12063 ".check GLOB Fail if output since .testcase does not match",
12064 ".clone NEWDB Clone data into NEWDB from the existing database",
12065 ".databases List names and files of attached databases",
12066 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
12067 ".dbinfo ?DB? Show status information about the database",
11829 if( zEQPLine[0]=='-' ) eqp_render(pArg);
11830 eqp_append(pArg, iEqpId, iParentId, zEQPLine);
11831 }
11832 eqp_render(pArg);
11833 }
11834 sqlite3_finalize(pExplain);
11835 sqlite3_free(zEQP);
11836 if( pArg->autoEQP>=AUTOEQP_full ){

--- 394 unchanged lines hidden (view full) ---

12231 ".binary on|off Turn binary output on or off. Default OFF",
12232 ".cd DIRECTORY Change the working directory to DIRECTORY",
12233 ".changes on|off Show number of rows changed by SQL",
12234 ".check GLOB Fail if output since .testcase does not match",
12235 ".clone NEWDB Clone data into NEWDB from the existing database",
12236 ".databases List names and files of attached databases",
12237 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
12238 ".dbinfo ?DB? Show status information about the database",
12068 ".dump ?TABLE? ... Render all database content as SQL",
12239 ".dump ?TABLE? Render database content as SQL",
12069 " Options:",
12070 " --preserve-rowids Include ROWID values in the output",
12071 " --newlines Allow unescaped newline characters in output",
12072 " TABLE is a LIKE pattern for the tables to dump",
12240 " Options:",
12241 " --preserve-rowids Include ROWID values in the output",
12242 " --newlines Allow unescaped newline characters in output",
12243 " TABLE is a LIKE pattern for the tables to dump",
12244 " Additional LIKE patterns can be given in subsequent arguments",
12073 ".echo on|off Turn command echo on or off",
12074 ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
12075 " Other Modes:",
12076#ifdef SQLITE_DEBUG
12077 " test Show raw EXPLAIN QUERY PLAN output",
12078 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
12079#endif
12080 " trigger Like \"full\" but also show trigger bytecode",
12081 ".excel Display the output of next command in spreadsheet",
12245 ".echo on|off Turn command echo on or off",
12246 ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
12247 " Other Modes:",
12248#ifdef SQLITE_DEBUG
12249 " test Show raw EXPLAIN QUERY PLAN output",
12250 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
12251#endif
12252 " trigger Like \"full\" but also show trigger bytecode",
12253 ".excel Display the output of next command in spreadsheet",
12254 " --bom Put a UTF8 byte-order mark on intermediate file",
12082 ".exit ?CODE? Exit this program with return-code CODE",
12083 ".expert EXPERIMENTAL. Suggest indexes for queries",
12084 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
12085 ".filectrl CMD ... Run various sqlite3_file_control() operations",
12255 ".exit ?CODE? Exit this program with return-code CODE",
12256 ".expert EXPERIMENTAL. Suggest indexes for queries",
12257 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
12258 ".filectrl CMD ... Run various sqlite3_file_control() operations",
12086 " Run \".filectrl\" with no arguments for details",
12259 " --schema SCHEMA Use SCHEMA instead of \"main\"",
12260 " --help Show CMD details",
12087 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
12088 ".headers on|off Turn display of headers on or off",
12089 ".help ?-all? ?PATTERN? Show help text for PATTERN",
12090 ".import FILE TABLE Import data from FILE into TABLE",
12261 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
12262 ".headers on|off Turn display of headers on or off",
12263 ".help ?-all? ?PATTERN? Show help text for PATTERN",
12264 ".import FILE TABLE Import data from FILE into TABLE",
12265 " Options:",
12266 " --ascii Use \\037 and \\036 as column and row separators",
12267 " --csv Use , and \\n as column and row separators",
12268 " --skip N Skip the first N rows of input",
12269 " -v \"Verbose\" - increase auxiliary output",
12270 " Notes:",
12271 " * If TABLE does not exist, it is created. The first row of input",
12272 " determines the column names.",
12273 " * If neither --csv or --ascii are used, the input mode is derived",
12274 " from the \".mode\" output mode",
12275 " * If FILE begins with \"|\" then it is a command that generates the",
12276 " input text.",
12091#ifndef SQLITE_OMIT_TEST_CONTROL
12092 ".imposter INDEX TABLE Create imposter table TABLE on index INDEX",
12093#endif
12094 ".indexes ?TABLE? Show names of indexes",
12095 " If TABLE is specified, only show indexes for",
12096 " tables matching TABLE using the LIKE operator.",
12097#ifdef SQLITE_ENABLE_IOTRACE
12098 ".iotrace FILE Enable I/O diagnostic logging to FILE",

--- 14 unchanged lines hidden (view full) ---

12113 " html HTML <table> code",
12114 " insert SQL insert statements for TABLE",
12115 " line One value per line",
12116 " list Values delimited by \"|\"",
12117 " quote Escape answers as for SQL",
12118 " tabs Tab-separated values",
12119 " tcl TCL list elements",
12120 ".nullvalue STRING Use STRING in place of NULL values",
12277#ifndef SQLITE_OMIT_TEST_CONTROL
12278 ".imposter INDEX TABLE Create imposter table TABLE on index INDEX",
12279#endif
12280 ".indexes ?TABLE? Show names of indexes",
12281 " If TABLE is specified, only show indexes for",
12282 " tables matching TABLE using the LIKE operator.",
12283#ifdef SQLITE_ENABLE_IOTRACE
12284 ".iotrace FILE Enable I/O diagnostic logging to FILE",

--- 14 unchanged lines hidden (view full) ---

12299 " html HTML <table> code",
12300 " insert SQL insert statements for TABLE",
12301 " line One value per line",
12302 " list Values delimited by \"|\"",
12303 " quote Escape answers as for SQL",
12304 " tabs Tab-separated values",
12305 " tcl TCL list elements",
12306 ".nullvalue STRING Use STRING in place of NULL values",
12121 ".once (-e|-x|FILE) Output for the next SQL command only to FILE",
12307 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
12122 " If FILE begins with '|' then open as a pipe",
12308 " If FILE begins with '|' then open as a pipe",
12123 " Other options:",
12124 " -e Invoke system text editor",
12125 " -x Open in a spreadsheet",
12309 " --bom Put a UTF8 byte-order mark at the beginning",
12310 " -e Send output to the system text editor",
12311 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
12312#ifdef SQLITE_DEBUG
12313 ".oom [--repeat M] [N] Simulate an OOM error on the N-th allocation",
12314#endif
12126 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
12127 " Options:",
12128 " --append Use appendvfs to append database to the end of FILE",
12129#ifdef SQLITE_ENABLE_DESERIALIZE
12130 " --deserialize Load into memory useing sqlite3_deserialize()",
12131 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
12132 " --maxsize N Maximum size for --hexdb or --deserialized database",
12133#endif
12134 " --new Initialize FILE to an empty database",
12135 " --nofollow Do not follow symbolic links",
12136 " --readonly Open FILE readonly",
12137 " --zip FILE is a ZIP archive",
12138 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12315 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
12316 " Options:",
12317 " --append Use appendvfs to append database to the end of FILE",
12318#ifdef SQLITE_ENABLE_DESERIALIZE
12319 " --deserialize Load into memory useing sqlite3_deserialize()",
12320 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
12321 " --maxsize N Maximum size for --hexdb or --deserialized database",
12322#endif
12323 " --new Initialize FILE to an empty database",
12324 " --nofollow Do not follow symbolic links",
12325 " --readonly Open FILE readonly",
12326 " --zip FILE is a ZIP archive",
12327 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12139 " If FILE begins with '|' then open it as a pipe.",
12328 " If FILE begins with '|' then open it as a pipe.",
12329 " Options:",
12330 " --bom Prefix output with a UTF8 byte-order mark",
12331 " -e Send output to the system text editor",
12332 " -x Send output as CSV to a spreadsheet",
12140 ".parameter CMD ... Manage SQL parameter bindings",
12141 " clear Erase all bindings",
12142 " init Initialize the TEMP table that holds bindings",
12143 " list List the current parameter bindings",
12144 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
12145 " PARAMETER should start with one of: $ : @ ?",
12146 " unset PARAMETER Remove PARAMETER from the binding table",
12147 ".print STRING... Print literal STRING",

--- 103 unchanged lines hidden (view full) ---

12251 int i = 0;
12252 int j = 0;
12253 int n = 0;
12254 char *zPat;
12255 if( zPattern==0
12256 || zPattern[0]=='0'
12257 || strcmp(zPattern,"-a")==0
12258 || strcmp(zPattern,"-all")==0
12333 ".parameter CMD ... Manage SQL parameter bindings",
12334 " clear Erase all bindings",
12335 " init Initialize the TEMP table that holds bindings",
12336 " list List the current parameter bindings",
12337 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
12338 " PARAMETER should start with one of: $ : @ ?",
12339 " unset PARAMETER Remove PARAMETER from the binding table",
12340 ".print STRING... Print literal STRING",

--- 103 unchanged lines hidden (view full) ---

12444 int i = 0;
12445 int j = 0;
12446 int n = 0;
12447 char *zPat;
12448 if( zPattern==0
12449 || zPattern[0]=='0'
12450 || strcmp(zPattern,"-a")==0
12451 || strcmp(zPattern,"-all")==0
12452 || strcmp(zPattern,"--all")==0
12259 ){
12260 /* Show all commands, but only one line per command */
12261 if( zPattern==0 ) zPattern = "";
12262 for(i=0; i<ArraySize(azHelp); i++){
12263 if( azHelp[i][0]=='.' || zPattern[0] ){
12264 utf8_printf(out, "%s\n", azHelp[i]);
12265 n++;
12266 }

--- 465 unchanged lines hidden (view full) ---

12732 exit(1);
12733 }
12734#ifndef SQLITE_OMIT_LOAD_EXTENSION
12735 sqlite3_enable_load_extension(p->db, 1);
12736#endif
12737 sqlite3_fileio_init(p->db, 0, 0);
12738 sqlite3_shathree_init(p->db, 0, 0);
12739 sqlite3_completion_init(p->db, 0, 0);
12453 ){
12454 /* Show all commands, but only one line per command */
12455 if( zPattern==0 ) zPattern = "";
12456 for(i=0; i<ArraySize(azHelp); i++){
12457 if( azHelp[i][0]=='.' || zPattern[0] ){
12458 utf8_printf(out, "%s\n", azHelp[i]);
12459 n++;
12460 }

--- 465 unchanged lines hidden (view full) ---

12926 exit(1);
12927 }
12928#ifndef SQLITE_OMIT_LOAD_EXTENSION
12929 sqlite3_enable_load_extension(p->db, 1);
12930#endif
12931 sqlite3_fileio_init(p->db, 0, 0);
12932 sqlite3_shathree_init(p->db, 0, 0);
12933 sqlite3_completion_init(p->db, 0, 0);
12934 sqlite3_uint_init(p->db, 0, 0);
12740#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
12741 sqlite3_dbdata_init(p->db, 0, 0);
12742#endif
12743#ifdef SQLITE_HAVE_ZLIB
12744 sqlite3_zipfile_init(p->db, 0, 0);
12745 sqlite3_sqlar_init(p->db, 0, 0);
12746#endif
12747 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,

--- 320 unchanged lines hidden (view full) ---

13068typedef struct ImportCtx ImportCtx;
13069struct ImportCtx {
13070 const char *zFile; /* Name of the input file */
13071 FILE *in; /* Read the CSV text from this input stream */
13072 char *z; /* Accumulated text for a field */
13073 int n; /* Number of bytes in z */
13074 int nAlloc; /* Space allocated for z[] */
13075 int nLine; /* Current line number */
12935#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
12936 sqlite3_dbdata_init(p->db, 0, 0);
12937#endif
12938#ifdef SQLITE_HAVE_ZLIB
12939 sqlite3_zipfile_init(p->db, 0, 0);
12940 sqlite3_sqlar_init(p->db, 0, 0);
12941#endif
12942 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,

--- 320 unchanged lines hidden (view full) ---

13263typedef struct ImportCtx ImportCtx;
13264struct ImportCtx {
13265 const char *zFile; /* Name of the input file */
13266 FILE *in; /* Read the CSV text from this input stream */
13267 char *z; /* Accumulated text for a field */
13268 int n; /* Number of bytes in z */
13269 int nAlloc; /* Space allocated for z[] */
13270 int nLine; /* Current line number */
13271 int nRow; /* Number of rows imported */
13272 int nErr; /* Number of errors encountered */
13076 int bNotFirst; /* True if one or more bytes already read */
13077 int cTerm; /* Character that terminated the most recent field */
13078 int cColSep; /* The column separator character. (Usually ",") */
13079 int cRowSep; /* The row separator character. (Usually "\n") */
13080};
13081
13082/* Append a single byte to z[] */
13083static void import_append_char(ImportCtx *p, int c){

--- 365 unchanged lines hidden (view full) ---

13449 "open";
13450#else
13451 "xdg-open";
13452#endif
13453 char *zCmd;
13454 zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
13455 if( system(zCmd) ){
13456 utf8_printf(stderr, "Failed: [%s]\n", zCmd);
13273 int bNotFirst; /* True if one or more bytes already read */
13274 int cTerm; /* Character that terminated the most recent field */
13275 int cColSep; /* The column separator character. (Usually ",") */
13276 int cRowSep; /* The row separator character. (Usually "\n") */
13277};
13278
13279/* Append a single byte to z[] */
13280static void import_append_char(ImportCtx *p, int c){

--- 365 unchanged lines hidden (view full) ---

13646 "open";
13647#else
13648 "xdg-open";
13649#endif
13650 char *zCmd;
13651 zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
13652 if( system(zCmd) ){
13653 utf8_printf(stderr, "Failed: [%s]\n", zCmd);
13654 }else{
13655 /* Give the start/open/xdg-open command some time to get
13656 ** going before we continue, and potential delete the
13657 ** p->zTempFile data file out from under it */
13658 sqlite3_sleep(2000);
13457 }
13458 sqlite3_free(zCmd);
13459 outputModePop(p);
13460 p->doXdgOpen = 0;
13659 }
13660 sqlite3_free(zCmd);
13661 outputModePop(p);
13662 p->doXdgOpen = 0;
13461 sqlite3_sleep(100);
13462 }
13463#endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
13464 }
13465 p->outfile[0] = 0;
13466 p->out = stdout;
13467}
13468
13469/*

--- 59 unchanged lines hidden (view full) ---

13529 sqlite3_stmt *pStmt = 0;
13530 unsigned char aHdr[100];
13531 open_db(p, 0);
13532 if( p->db==0 ) return 1;
13533 rc = sqlite3_prepare_v2(p->db,
13534 "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
13535 -1, &pStmt, 0);
13536 if( rc ){
13663 }
13664#endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
13665 }
13666 p->outfile[0] = 0;
13667 p->out = stdout;
13668}
13669
13670/*

--- 59 unchanged lines hidden (view full) ---

13730 sqlite3_stmt *pStmt = 0;
13731 unsigned char aHdr[100];
13732 open_db(p, 0);
13733 if( p->db==0 ) return 1;
13734 rc = sqlite3_prepare_v2(p->db,
13735 "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
13736 -1, &pStmt, 0);
13737 if( rc ){
13537 if( !sqlite3_compileoption_used("ENABLE_DBPAGE_VTAB") ){
13538 utf8_printf(stderr, "the \".dbinfo\" command requires the "
13539 "-DSQLITE_ENABLE_DBPAGE_VTAB compile-time options\n");
13540 }else{
13541 utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
13542 }
13738 utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
13543 sqlite3_finalize(pStmt);
13544 return 1;
13545 }
13546 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
13547 if( sqlite3_step(pStmt)==SQLITE_ROW
13548 && sqlite3_column_bytes(pStmt,0)>100
13549 ){
13550 memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);

--- 192 unchanged lines hidden (view full) ---

13743static void newTempFile(ShellState *p, const char *zSuffix){
13744 clearTempFile(p);
13745 sqlite3_free(p->zTempFile);
13746 p->zTempFile = 0;
13747 if( p->db ){
13748 sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile);
13749 }
13750 if( p->zTempFile==0 ){
13739 sqlite3_finalize(pStmt);
13740 return 1;
13741 }
13742 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
13743 if( sqlite3_step(pStmt)==SQLITE_ROW
13744 && sqlite3_column_bytes(pStmt,0)>100
13745 ){
13746 memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);

--- 192 unchanged lines hidden (view full) ---

13939static void newTempFile(ShellState *p, const char *zSuffix){
13940 clearTempFile(p);
13941 sqlite3_free(p->zTempFile);
13942 p->zTempFile = 0;
13943 if( p->db ){
13944 sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile);
13945 }
13946 if( p->zTempFile==0 ){
13947 /* If p->db is an in-memory database then the TEMPFILENAME file-control
13948 ** will not work and we will need to fallback to guessing */
13949 char *zTemp;
13751 sqlite3_uint64 r;
13752 sqlite3_randomness(sizeof(r), &r);
13950 sqlite3_uint64 r;
13951 sqlite3_randomness(sizeof(r), &r);
13753 p->zTempFile = sqlite3_mprintf("temp%llx.%s", r, zSuffix);
13952 zTemp = getenv("TEMP");
13953 if( zTemp==0 ) zTemp = getenv("TMP");
13954 if( zTemp==0 ){
13955#ifdef _WIN32
13956 zTemp = "\\tmp";
13957#else
13958 zTemp = "/tmp";
13959#endif
13960 }
13961 p->zTempFile = sqlite3_mprintf("%s/temp%llx.%s", zTemp, r, zSuffix);
13754 }else{
13755 p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
13756 }
13757 if( p->zTempFile==0 ){
13758 raw_printf(stderr, "out of memory\n");
13759 exit(1);
13760 }
13761}

--- 2007 unchanged lines hidden (view full) ---

15769#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
15770 if( c=='r' && strncmp(azArg[0], "recover", n)==0 ){
15771 open_db(p, 0);
15772 rc = recoverDatabaseCmd(p, nArg, azArg);
15773 }else
15774#endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
15775
15776 if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
13962 }else{
13963 p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
13964 }
13965 if( p->zTempFile==0 ){
13966 raw_printf(stderr, "out of memory\n");
13967 exit(1);
13968 }
13969}

--- 2007 unchanged lines hidden (view full) ---

15977#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
15978 if( c=='r' && strncmp(azArg[0], "recover", n)==0 ){
15979 open_db(p, 0);
15980 rc = recoverDatabaseCmd(p, nArg, azArg);
15981 }else
15982#endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
15983
15984 if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
15777 const char *zLike = 0;
15985 char *zLike = 0;
15986 char *zSql;
15778 int i;
15779 int savedShowHeader = p->showHeader;
15780 int savedShellFlags = p->shellFlgs;
15781 ShellClearFlag(p, SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo);
15782 for(i=1; i<nArg; i++){
15783 if( azArg[i][0]=='-' ){
15784 const char *z = azArg[i]+1;
15785 if( z[0]=='-' ) z++;

--- 11 unchanged lines hidden (view full) ---

15797 ShellSetFlag(p, SHFLG_Newlines);
15798 }else
15799 {
15800 raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
15801 rc = 1;
15802 goto meta_command_exit;
15803 }
15804 }else if( zLike ){
15987 int i;
15988 int savedShowHeader = p->showHeader;
15989 int savedShellFlags = p->shellFlgs;
15990 ShellClearFlag(p, SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo);
15991 for(i=1; i<nArg; i++){
15992 if( azArg[i][0]=='-' ){
15993 const char *z = azArg[i]+1;
15994 if( z[0]=='-' ) z++;

--- 11 unchanged lines hidden (view full) ---

16006 ShellSetFlag(p, SHFLG_Newlines);
16007 }else
16008 {
16009 raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
16010 rc = 1;
16011 goto meta_command_exit;
16012 }
16013 }else if( zLike ){
15805 raw_printf(stderr, "Usage: .dump ?--preserve-rowids? "
15806 "?--newlines? ?LIKE-PATTERN?\n");
15807 rc = 1;
15808 goto meta_command_exit;
16014 zLike = sqlite3_mprintf("%z OR name LIKE %Q ESCAPE '\\'",
16015 zLike, azArg[i]);
15809 }else{
16016 }else{
15810 zLike = azArg[i];
16017 zLike = sqlite3_mprintf("name LIKE %Q ESCAPE '\\'", azArg[i]);
15811 }
15812 }
15813
15814 open_db(p, 0);
15815
15816 /* When playing back a "dump", the content might appear in an order
15817 ** which causes immediate foreign key constraints to be violated.
15818 ** So disable foreign-key constraint enforcement to prevent problems. */
15819 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
15820 raw_printf(p->out, "BEGIN TRANSACTION;\n");
15821 p->writableSchema = 0;
15822 p->showHeader = 0;
15823 /* Set writable_schema=ON since doing so forces SQLite to initialize
15824 ** as much of the schema as it can even if the sqlite_master table is
15825 ** corrupt. */
15826 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
15827 p->nErr = 0;
16018 }
16019 }
16020
16021 open_db(p, 0);
16022
16023 /* When playing back a "dump", the content might appear in an order
16024 ** which causes immediate foreign key constraints to be violated.
16025 ** So disable foreign-key constraint enforcement to prevent problems. */
16026 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
16027 raw_printf(p->out, "BEGIN TRANSACTION;\n");
16028 p->writableSchema = 0;
16029 p->showHeader = 0;
16030 /* Set writable_schema=ON since doing so forces SQLite to initialize
16031 ** as much of the schema as it can even if the sqlite_master table is
16032 ** corrupt. */
16033 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
16034 p->nErr = 0;
15828 if( zLike==0 ){
15829 run_schema_dump_query(p,
15830 "SELECT name, type, sql FROM sqlite_master "
15831 "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'"
15832 );
15833 run_schema_dump_query(p,
15834 "SELECT name, type, sql FROM sqlite_master "
15835 "WHERE name=='sqlite_sequence'"
15836 );
15837 run_table_dump_query(p,
15838 "SELECT sql FROM sqlite_master "
15839 "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
15840 );
15841 }else{
15842 char *zSql;
15843 zSql = sqlite3_mprintf(
15844 "SELECT name, type, sql FROM sqlite_master "
15845 "WHERE tbl_name LIKE %Q AND type=='table'"
15846 " AND sql NOT NULL", zLike);
15847 run_schema_dump_query(p,zSql);
15848 sqlite3_free(zSql);
15849 zSql = sqlite3_mprintf(
15850 "SELECT sql FROM sqlite_master "
15851 "WHERE sql NOT NULL"
15852 " AND type IN ('index','trigger','view')"
15853 " AND tbl_name LIKE %Q", zLike);
15854 run_table_dump_query(p, zSql, 0);
15855 sqlite3_free(zSql);
15856 }
16035 if( zLike==0 ) zLike = sqlite3_mprintf("true");
16036 zSql = sqlite3_mprintf(
16037 "SELECT name, type, sql FROM sqlite_master "
16038 "WHERE (%s) AND type=='table'"
16039 " AND sql NOT NULL"
16040 " ORDER BY tbl_name='sqlite_sequence', rowid",
16041 zLike
16042 );
16043 run_schema_dump_query(p,zSql);
16044 sqlite3_free(zSql);
16045 zSql = sqlite3_mprintf(
16046 "SELECT sql FROM sqlite_master "
16047 "WHERE (%s) AND sql NOT NULL"
16048 " AND type IN ('index','trigger','view')",
16049 zLike
16050 );
16051 run_table_dump_query(p, zSql);
16052 sqlite3_free(zSql);
16053 sqlite3_free(zLike);
15857 if( p->writableSchema ){
15858 raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
15859 p->writableSchema = 0;
15860 }
15861 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
15862 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
15863 raw_printf(p->out, p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n");
15864 p->showHeader = savedShowHeader;

--- 86 unchanged lines hidden (view full) ---

15951 { "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
15952 /* { "win32_av_retry", SQLITE_FCNTL_WIN32_AV_RETRY, "COUNT DELAY" },*/
15953 { "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
15954 { "psow", SQLITE_FCNTL_POWERSAFE_OVERWRITE, "[BOOLEAN]" },
15955 /* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
15956 { "tempfilename", SQLITE_FCNTL_TEMPFILENAME, "" },
15957 { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
15958 { "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
16054 if( p->writableSchema ){
16055 raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
16056 p->writableSchema = 0;
16057 }
16058 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
16059 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
16060 raw_printf(p->out, p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n");
16061 p->showHeader = savedShowHeader;

--- 86 unchanged lines hidden (view full) ---

16148 { "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
16149 /* { "win32_av_retry", SQLITE_FCNTL_WIN32_AV_RETRY, "COUNT DELAY" },*/
16150 { "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
16151 { "psow", SQLITE_FCNTL_POWERSAFE_OVERWRITE, "[BOOLEAN]" },
16152 /* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
16153 { "tempfilename", SQLITE_FCNTL_TEMPFILENAME, "" },
16154 { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
16155 { "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
16156 { "reserve_bytes", SQLITE_FCNTL_RESERVE_BYTES, "[N]" },
15959 };
15960 int filectrl = -1;
15961 int iCtrl = -1;
15962 sqlite3_int64 iRes = 0; /* Integer result to display if rc2==1 */
15963 int isOk = 0; /* 0: usage 1: %lld 2: no-result */
15964 int n2, i;
15965 const char *zCmd = 0;
16157 };
16158 int filectrl = -1;
16159 int iCtrl = -1;
16160 sqlite3_int64 iRes = 0; /* Integer result to display if rc2==1 */
16161 int isOk = 0; /* 0: usage 1: %lld 2: no-result */
16162 int n2, i;
16163 const char *zCmd = 0;
16164 const char *zSchema = 0;
15966
15967 open_db(p, 0);
15968 zCmd = nArg>=2 ? azArg[1] : "help";
15969
16165
16166 open_db(p, 0);
16167 zCmd = nArg>=2 ? azArg[1] : "help";
16168
16169 if( zCmd[0]=='-'
16170 && (strcmp(zCmd,"--schema")==0 || strcmp(zCmd,"-schema")==0)
16171 && nArg>=4
16172 ){
16173 zSchema = azArg[2];
16174 for(i=3; i<nArg; i++) azArg[i-2] = azArg[i];
16175 nArg -= 2;
16176 zCmd = azArg[1];
16177 }
16178
15970 /* The argument can optionally begin with "-" or "--" */
15971 if( zCmd[0]=='-' && zCmd[1] ){
15972 zCmd++;
15973 if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
15974 }
15975
15976 /* --help lists all file-controls */
15977 if( strcmp(zCmd,"help")==0 ){

--- 25 unchanged lines hidden (view full) ---

16003 if( filectrl<0 ){
16004 utf8_printf(stderr,"Error: unknown file-control: %s\n"
16005 "Use \".filectrl --help\" for help\n", zCmd);
16006 }else{
16007 switch(filectrl){
16008 case SQLITE_FCNTL_SIZE_LIMIT: {
16009 if( nArg!=2 && nArg!=3 ) break;
16010 iRes = nArg==3 ? integerValue(azArg[2]) : -1;
16179 /* The argument can optionally begin with "-" or "--" */
16180 if( zCmd[0]=='-' && zCmd[1] ){
16181 zCmd++;
16182 if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
16183 }
16184
16185 /* --help lists all file-controls */
16186 if( strcmp(zCmd,"help")==0 ){

--- 25 unchanged lines hidden (view full) ---

16212 if( filectrl<0 ){
16213 utf8_printf(stderr,"Error: unknown file-control: %s\n"
16214 "Use \".filectrl --help\" for help\n", zCmd);
16215 }else{
16216 switch(filectrl){
16217 case SQLITE_FCNTL_SIZE_LIMIT: {
16218 if( nArg!=2 && nArg!=3 ) break;
16219 iRes = nArg==3 ? integerValue(azArg[2]) : -1;
16011 sqlite3_file_control(p->db, 0, SQLITE_FCNTL_SIZE_LIMIT, &iRes);
16220 sqlite3_file_control(p->db, zSchema, SQLITE_FCNTL_SIZE_LIMIT, &iRes);
16012 isOk = 1;
16013 break;
16014 }
16015 case SQLITE_FCNTL_LOCK_TIMEOUT:
16016 case SQLITE_FCNTL_CHUNK_SIZE: {
16017 int x;
16018 if( nArg!=3 ) break;
16019 x = (int)integerValue(azArg[2]);
16221 isOk = 1;
16222 break;
16223 }
16224 case SQLITE_FCNTL_LOCK_TIMEOUT:
16225 case SQLITE_FCNTL_CHUNK_SIZE: {
16226 int x;
16227 if( nArg!=3 ) break;
16228 x = (int)integerValue(azArg[2]);
16020 sqlite3_file_control(p->db, 0, filectrl, &x);
16229 sqlite3_file_control(p->db, zSchema, filectrl, &x);
16021 isOk = 2;
16022 break;
16023 }
16024 case SQLITE_FCNTL_PERSIST_WAL:
16025 case SQLITE_FCNTL_POWERSAFE_OVERWRITE: {
16026 int x;
16027 if( nArg!=2 && nArg!=3 ) break;
16028 x = nArg==3 ? booleanValue(azArg[2]) : -1;
16230 isOk = 2;
16231 break;
16232 }
16233 case SQLITE_FCNTL_PERSIST_WAL:
16234 case SQLITE_FCNTL_POWERSAFE_OVERWRITE: {
16235 int x;
16236 if( nArg!=2 && nArg!=3 ) break;
16237 x = nArg==3 ? booleanValue(azArg[2]) : -1;
16029 sqlite3_file_control(p->db, 0, filectrl, &x);
16238 sqlite3_file_control(p->db, zSchema, filectrl, &x);
16030 iRes = x;
16031 isOk = 1;
16032 break;
16033 }
16034 case SQLITE_FCNTL_HAS_MOVED: {
16035 int x;
16036 if( nArg!=2 ) break;
16239 iRes = x;
16240 isOk = 1;
16241 break;
16242 }
16243 case SQLITE_FCNTL_HAS_MOVED: {
16244 int x;
16245 if( nArg!=2 ) break;
16037 sqlite3_file_control(p->db, 0, filectrl, &x);
16246 sqlite3_file_control(p->db, zSchema, filectrl, &x);
16038 iRes = x;
16039 isOk = 1;
16040 break;
16041 }
16042 case SQLITE_FCNTL_TEMPFILENAME: {
16043 char *z = 0;
16044 if( nArg!=2 ) break;
16247 iRes = x;
16248 isOk = 1;
16249 break;
16250 }
16251 case SQLITE_FCNTL_TEMPFILENAME: {
16252 char *z = 0;
16253 if( nArg!=2 ) break;
16045 sqlite3_file_control(p->db, 0, filectrl, &z);
16254 sqlite3_file_control(p->db, zSchema, filectrl, &z);
16046 if( z ){
16047 utf8_printf(p->out, "%s\n", z);
16048 sqlite3_free(z);
16049 }
16050 isOk = 2;
16051 break;
16052 }
16255 if( z ){
16256 utf8_printf(p->out, "%s\n", z);
16257 sqlite3_free(z);
16258 }
16259 isOk = 2;
16260 break;
16261 }
16262 case SQLITE_FCNTL_RESERVE_BYTES: {
16263 int x;
16264 if( nArg>=3 ){
16265 x = atoi(azArg[2]);
16266 sqlite3_file_control(p->db, zSchema, filectrl, &x);
16267 }
16268 x = -1;
16269 sqlite3_file_control(p->db, zSchema, filectrl, &x);
16270 utf8_printf(p->out,"%d\n", x);
16271 isOk = 2;
16272 break;
16273 }
16053 }
16054 }
16055 if( isOk==0 && iCtrl>=0 ){
16056 utf8_printf(p->out, "Usage: .filectrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
16057 rc = 1;
16058 }else if( isOk==1 ){
16059 char zBuf[100];
16060 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", iRes);

--- 67 unchanged lines hidden (view full) ---

16128 utf8_printf(p->out, "Nothing matches '%s'\n", azArg[1]);
16129 }
16130 }else{
16131 showHelp(p->out, 0);
16132 }
16133 }else
16134
16135 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
16274 }
16275 }
16276 if( isOk==0 && iCtrl>=0 ){
16277 utf8_printf(p->out, "Usage: .filectrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
16278 rc = 1;
16279 }else if( isOk==1 ){
16280 char zBuf[100];
16281 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", iRes);

--- 67 unchanged lines hidden (view full) ---

16349 utf8_printf(p->out, "Nothing matches '%s'\n", azArg[1]);
16350 }
16351 }else{
16352 showHelp(p->out, 0);
16353 }
16354 }else
16355
16356 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
16136 char *zTable; /* Insert data into this table */
16137 char *zFile; /* Name of file to extra content from */
16357 char *zTable = 0; /* Insert data into this table */
16358 char *zFile = 0; /* Name of file to extra content from */
16138 sqlite3_stmt *pStmt = NULL; /* A statement */
16139 int nCol; /* Number of columns in the table */
16140 int nByte; /* Number of bytes in an SQL string */
16141 int i, j; /* Loop counters */
16142 int needCommit; /* True to COMMIT or ROLLBACK at end */
16143 int nSep; /* Number of bytes in p->colSeparator[] */
16144 char *zSql; /* An SQL statement */
16145 ImportCtx sCtx; /* Reader context */
16146 char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
16147 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */
16359 sqlite3_stmt *pStmt = NULL; /* A statement */
16360 int nCol; /* Number of columns in the table */
16361 int nByte; /* Number of bytes in an SQL string */
16362 int i, j; /* Loop counters */
16363 int needCommit; /* True to COMMIT or ROLLBACK at end */
16364 int nSep; /* Number of bytes in p->colSeparator[] */
16365 char *zSql; /* An SQL statement */
16366 ImportCtx sCtx; /* Reader context */
16367 char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
16368 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */
16369 int eVerbose = 0; /* Larger for more console output */
16370 int nSkip = 0; /* Initial lines to skip */
16371 int useOutputMode = 1; /* Use output mode to determine separators */
16148
16372
16149 if( nArg!=3 ){
16150 raw_printf(stderr, "Usage: .import FILE TABLE\n");
16151 goto meta_command_exit;
16152 }
16153 zFile = azArg[1];
16154 zTable = azArg[2];
16155 seenInterrupt = 0;
16156 memset(&sCtx, 0, sizeof(sCtx));
16373 memset(&sCtx, 0, sizeof(sCtx));
16157 open_db(p, 0);
16158 nSep = strlen30(p->colSeparator);
16159 if( nSep==0 ){
16160 raw_printf(stderr,
16161 "Error: non-null column separator required for import\n");
16162 return 1;
16374 if( p->mode==MODE_Ascii ){
16375 xRead = ascii_read_one_field;
16376 }else{
16377 xRead = csv_read_one_field;
16163 }
16378 }
16164 if( nSep>1 ){
16165 raw_printf(stderr, "Error: multi-character column separators not allowed"
16166 " for import\n");
16167 return 1;
16379 for(i=1; i<nArg; i++){
16380 char *z = azArg[i];
16381 if( z[0]=='-' && z[1]=='-' ) z++;
16382 if( z[0]!='-' ){
16383 if( zFile==0 ){
16384 zFile = z;
16385 }else if( zTable==0 ){
16386 zTable = z;
16387 }else{
16388 utf8_printf(p->out, "ERROR: extra argument: \"%s\". Usage:\n", z);
16389 showHelp(p->out, "import");
16390 rc = 1;
16391 goto meta_command_exit;
16392 }
16393 }else if( strcmp(z,"-v")==0 ){
16394 eVerbose++;
16395 }else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
16396 nSkip = integerValue(azArg[++i]);
16397 }else if( strcmp(z,"-ascii")==0 ){
16398 sCtx.cColSep = SEP_Unit[0];
16399 sCtx.cRowSep = SEP_Record[0];
16400 xRead = ascii_read_one_field;
16401 useOutputMode = 0;
16402 }else if( strcmp(z,"-csv")==0 ){
16403 sCtx.cColSep = ',';
16404 sCtx.cRowSep = '\n';
16405 xRead = csv_read_one_field;
16406 useOutputMode = 0;
16407 }else{
16408 utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", z);
16409 showHelp(p->out, "import");
16410 rc = 1;
16411 goto meta_command_exit;
16412 }
16168 }
16413 }
16169 nSep = strlen30(p->rowSeparator);
16170 if( nSep==0 ){
16171 raw_printf(stderr, "Error: non-null row separator required for import\n");
16172 return 1;
16414 if( zTable==0 ){
16415 utf8_printf(p->out, "ERROR: missing %s argument. Usage:\n",
16416 zFile==0 ? "FILE" : "TABLE");
16417 showHelp(p->out, "import");
16418 rc = 1;
16419 goto meta_command_exit;
16173 }
16420 }
16174 if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
16175 /* When importing CSV (only), if the row separator is set to the
16176 ** default output row separator, change it to the default input
16177 ** row separator. This avoids having to maintain different input
16178 ** and output row separators. */
16179 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
16421 seenInterrupt = 0;
16422 open_db(p, 0);
16423 if( useOutputMode ){
16424 /* If neither the --csv or --ascii options are specified, then set
16425 ** the column and row separator characters from the output mode. */
16426 nSep = strlen30(p->colSeparator);
16427 if( nSep==0 ){
16428 raw_printf(stderr,
16429 "Error: non-null column separator required for import\n");
16430 rc = 1;
16431 goto meta_command_exit;
16432 }
16433 if( nSep>1 ){
16434 raw_printf(stderr,
16435 "Error: multi-character column separators not allowed"
16436 " for import\n");
16437 rc = 1;
16438 goto meta_command_exit;
16439 }
16180 nSep = strlen30(p->rowSeparator);
16440 nSep = strlen30(p->rowSeparator);
16441 if( nSep==0 ){
16442 raw_printf(stderr,
16443 "Error: non-null row separator required for import\n");
16444 rc = 1;
16445 goto meta_command_exit;
16446 }
16447 if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator,SEP_CrLf)==0 ){
16448 /* When importing CSV (only), if the row separator is set to the
16449 ** default output row separator, change it to the default input
16450 ** row separator. This avoids having to maintain different input
16451 ** and output row separators. */
16452 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
16453 nSep = strlen30(p->rowSeparator);
16454 }
16455 if( nSep>1 ){
16456 raw_printf(stderr, "Error: multi-character row separators not allowed"
16457 " for import\n");
16458 rc = 1;
16459 goto meta_command_exit;
16460 }
16461 sCtx.cColSep = p->colSeparator[0];
16462 sCtx.cRowSep = p->rowSeparator[0];
16181 }
16463 }
16182 if( nSep>1 ){
16183 raw_printf(stderr, "Error: multi-character row separators not allowed"
16184 " for import\n");
16185 return 1;
16186 }
16187 sCtx.zFile = zFile;
16188 sCtx.nLine = 1;
16189 if( sCtx.zFile[0]=='|' ){
16190#ifdef SQLITE_OMIT_POPEN
16191 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
16464 sCtx.zFile = zFile;
16465 sCtx.nLine = 1;
16466 if( sCtx.zFile[0]=='|' ){
16467#ifdef SQLITE_OMIT_POPEN
16468 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
16192 return 1;
16469 rc = 1;
16470 goto meta_command_exit;
16193#else
16194 sCtx.in = popen(sCtx.zFile+1, "r");
16195 sCtx.zFile = "<pipe>";
16196 xCloser = pclose;
16197#endif
16198 }else{
16199 sCtx.in = fopen(sCtx.zFile, "rb");
16200 xCloser = fclose;
16201 }
16471#else
16472 sCtx.in = popen(sCtx.zFile+1, "r");
16473 sCtx.zFile = "<pipe>";
16474 xCloser = pclose;
16475#endif
16476 }else{
16477 sCtx.in = fopen(sCtx.zFile, "rb");
16478 xCloser = fclose;
16479 }
16202 if( p->mode==MODE_Ascii ){
16203 xRead = ascii_read_one_field;
16204 }else{
16205 xRead = csv_read_one_field;
16206 }
16207 if( sCtx.in==0 ){
16208 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
16480 if( sCtx.in==0 ){
16481 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
16209 return 1;
16482 rc = 1;
16483 goto meta_command_exit;
16210 }
16484 }
16211 sCtx.cColSep = p->colSeparator[0];
16212 sCtx.cRowSep = p->rowSeparator[0];
16485 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
16486 char zSep[2];
16487 zSep[1] = 0;
16488 zSep[0] = sCtx.cColSep;
16489 utf8_printf(p->out, "Column separator ");
16490 output_c_string(p->out, zSep);
16491 utf8_printf(p->out, ", row separator ");
16492 zSep[0] = sCtx.cRowSep;
16493 output_c_string(p->out, zSep);
16494 utf8_printf(p->out, "\n");
16495 }
16496 while( (nSkip--)>0 ){
16497 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
16498 sCtx.nLine++;
16499 }
16213 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
16214 if( zSql==0 ){
16215 xCloser(sCtx.in);
16216 shell_out_of_memory();
16217 }
16218 nByte = strlen30(zSql);
16219 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16220 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */

--- 5 unchanged lines hidden (view full) ---

16226 cSep = ',';
16227 if( sCtx.cTerm!=sCtx.cColSep ) break;
16228 }
16229 if( cSep=='(' ){
16230 sqlite3_free(zCreate);
16231 sqlite3_free(sCtx.z);
16232 xCloser(sCtx.in);
16233 utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
16500 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
16501 if( zSql==0 ){
16502 xCloser(sCtx.in);
16503 shell_out_of_memory();
16504 }
16505 nByte = strlen30(zSql);
16506 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16507 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */

--- 5 unchanged lines hidden (view full) ---

16513 cSep = ',';
16514 if( sCtx.cTerm!=sCtx.cColSep ) break;
16515 }
16516 if( cSep=='(' ){
16517 sqlite3_free(zCreate);
16518 sqlite3_free(sCtx.z);
16519 xCloser(sCtx.in);
16520 utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
16234 return 1;
16521 rc = 1;
16522 goto meta_command_exit;
16235 }
16236 zCreate = sqlite3_mprintf("%z\n)", zCreate);
16523 }
16524 zCreate = sqlite3_mprintf("%z\n)", zCreate);
16525 if( eVerbose>=1 ){
16526 utf8_printf(p->out, "%s\n", zCreate);
16527 }
16237 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
16238 sqlite3_free(zCreate);
16239 if( rc ){
16240 utf8_printf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
16241 sqlite3_errmsg(p->db));
16242 sqlite3_free(sCtx.z);
16243 xCloser(sCtx.in);
16528 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
16529 sqlite3_free(zCreate);
16530 if( rc ){
16531 utf8_printf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
16532 sqlite3_errmsg(p->db));
16533 sqlite3_free(sCtx.z);
16534 xCloser(sCtx.in);
16244 return 1;
16535 rc = 1;
16536 goto meta_command_exit;
16245 }
16246 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16247 }
16248 sqlite3_free(zSql);
16249 if( rc ){
16250 if (pStmt) sqlite3_finalize(pStmt);
16251 utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
16252 xCloser(sCtx.in);
16537 }
16538 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16539 }
16540 sqlite3_free(zSql);
16541 if( rc ){
16542 if (pStmt) sqlite3_finalize(pStmt);
16543 utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
16544 xCloser(sCtx.in);
16253 return 1;
16545 rc = 1;
16546 goto meta_command_exit;
16254 }
16255 nCol = sqlite3_column_count(pStmt);
16256 sqlite3_finalize(pStmt);
16257 pStmt = 0;
16258 if( nCol==0 ) return 0; /* no columns, no error */
16259 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
16260 if( zSql==0 ){
16261 xCloser(sCtx.in);
16262 shell_out_of_memory();
16263 }
16264 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
16265 j = strlen30(zSql);
16266 for(i=1; i<nCol; i++){
16267 zSql[j++] = ',';
16268 zSql[j++] = '?';
16269 }
16270 zSql[j++] = ')';
16271 zSql[j] = 0;
16547 }
16548 nCol = sqlite3_column_count(pStmt);
16549 sqlite3_finalize(pStmt);
16550 pStmt = 0;
16551 if( nCol==0 ) return 0; /* no columns, no error */
16552 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
16553 if( zSql==0 ){
16554 xCloser(sCtx.in);
16555 shell_out_of_memory();
16556 }
16557 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
16558 j = strlen30(zSql);
16559 for(i=1; i<nCol; i++){
16560 zSql[j++] = ',';
16561 zSql[j++] = '?';
16562 }
16563 zSql[j++] = ')';
16564 zSql[j] = 0;
16565 if( eVerbose>=2 ){
16566 utf8_printf(p->out, "Insert using: %s\n", zSql);
16567 }
16272 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16273 sqlite3_free(zSql);
16274 if( rc ){
16275 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
16276 if (pStmt) sqlite3_finalize(pStmt);
16277 xCloser(sCtx.in);
16568 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16569 sqlite3_free(zSql);
16570 if( rc ){
16571 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
16572 if (pStmt) sqlite3_finalize(pStmt);
16573 xCloser(sCtx.in);
16278 return 1;
16574 rc = 1;
16575 goto meta_command_exit;
16279 }
16280 needCommit = sqlite3_get_autocommit(p->db);
16281 if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
16282 do{
16283 int startLine = sCtx.nLine;
16284 for(i=0; i<nCol; i++){
16285 char *z = xRead(&sCtx);
16286 /*

--- 26 unchanged lines hidden (view full) ---

16313 sCtx.zFile, startLine, nCol, i);
16314 }
16315 if( i>=nCol ){
16316 sqlite3_step(pStmt);
16317 rc = sqlite3_reset(pStmt);
16318 if( rc!=SQLITE_OK ){
16319 utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile,
16320 startLine, sqlite3_errmsg(p->db));
16576 }
16577 needCommit = sqlite3_get_autocommit(p->db);
16578 if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
16579 do{
16580 int startLine = sCtx.nLine;
16581 for(i=0; i<nCol; i++){
16582 char *z = xRead(&sCtx);
16583 /*

--- 26 unchanged lines hidden (view full) ---

16610 sCtx.zFile, startLine, nCol, i);
16611 }
16612 if( i>=nCol ){
16613 sqlite3_step(pStmt);
16614 rc = sqlite3_reset(pStmt);
16615 if( rc!=SQLITE_OK ){
16616 utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile,
16617 startLine, sqlite3_errmsg(p->db));
16618 sCtx.nErr++;
16619 }else{
16620 sCtx.nRow++;
16321 }
16322 }
16323 }while( sCtx.cTerm!=EOF );
16324
16325 xCloser(sCtx.in);
16326 sqlite3_free(sCtx.z);
16327 sqlite3_finalize(pStmt);
16328 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
16621 }
16622 }
16623 }while( sCtx.cTerm!=EOF );
16624
16625 xCloser(sCtx.in);
16626 sqlite3_free(sCtx.z);
16627 sqlite3_finalize(pStmt);
16628 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
16629 if( eVerbose>0 ){
16630 utf8_printf(p->out,
16631 "Added %d rows with %d errors using %d lines of input\n",
16632 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
16633 }
16329 }else
16330
16331#ifndef SQLITE_UNTESTABLE
16332 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
16333 char *zSql;
16334 char *zCollist = 0;
16335 sqlite3_stmt *pStmt;
16336 int tnum = 0;

--- 262 unchanged lines hidden (view full) ---

16599 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
16600 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
16601 }else{
16602 raw_printf(stderr, "Usage: .nullvalue STRING\n");
16603 rc = 1;
16604 }
16605 }else
16606
16634 }else
16635
16636#ifndef SQLITE_UNTESTABLE
16637 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
16638 char *zSql;
16639 char *zCollist = 0;
16640 sqlite3_stmt *pStmt;
16641 int tnum = 0;

--- 262 unchanged lines hidden (view full) ---

16904 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
16905 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
16906 }else{
16907 raw_printf(stderr, "Usage: .nullvalue STRING\n");
16908 rc = 1;
16909 }
16910 }else
16911
16912#ifdef SQLITE_DEBUG
16913 if( c=='o' && strcmp(azArg[0],"oom")==0 ){
16914 int i;
16915 for(i=1; i<nArg; i++){
16916 const char *z = azArg[i];
16917 if( z[0]=='-' && z[1]=='-' ) z++;
16918 if( strcmp(z,"-repeat")==0 ){
16919 if( i==nArg-1 ){
16920 raw_printf(p->out, "missing argument on \"%s\"\n", azArg[i]);
16921 rc = 1;
16922 }else{
16923 oomRepeat = (int)integerValue(azArg[++i]);
16924 }
16925 }else if( IsDigit(z[0]) ){
16926 oomCounter = (int)integerValue(azArg[i]);
16927 }else{
16928 raw_printf(p->out, "unknown argument: \"%s\"\n", azArg[i]);
16929 raw_printf(p->out, "Usage: .oom [--repeat N] [M]\n");
16930 rc = 1;
16931 }
16932 }
16933 if( rc==0 ){
16934 raw_printf(p->out, "oomCounter = %d\n", oomCounter);
16935 raw_printf(p->out, "oomRepeat = %d\n", oomRepeat);
16936 }
16937 }else
16938#endif /* SQLITE_DEBUG */
16939
16607 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
16608 char *zNewFilename; /* Name of the database file to open */
16609 int iName = 1; /* Index in azArg[] of the filename */
16610 int newFlag = 0; /* True to delete file before opening */
16611 /* Close the existing database */
16612 session_close_all(p);
16613 close_db(p->db);
16614 p->db = 0;

--- 51 unchanged lines hidden (view full) ---

16666 open_db(p, 0);
16667 }
16668 }else
16669
16670 if( (c=='o'
16671 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
16672 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
16673 ){
16940 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
16941 char *zNewFilename; /* Name of the database file to open */
16942 int iName = 1; /* Index in azArg[] of the filename */
16943 int newFlag = 0; /* True to delete file before opening */
16944 /* Close the existing database */
16945 session_close_all(p);
16946 close_db(p->db);
16947 p->db = 0;

--- 51 unchanged lines hidden (view full) ---

16999 open_db(p, 0);
17000 }
17001 }else
17002
17003 if( (c=='o'
17004 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
17005 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
17006 ){
16674 const char *zFile = nArg>=2 ? azArg[1] : "stdout";
17007 const char *zFile = 0;
16675 int bTxtMode = 0;
17008 int bTxtMode = 0;
16676 if( azArg[0][0]=='e' ){
16677 /* Transform the ".excel" command into ".once -x" */
16678 nArg = 2;
16679 azArg[0] = "once";
16680 zFile = azArg[1] = "-x";
16681 n = 4;
17009 int i;
17010 int eMode = 0;
17011 int bBOM = 0;
17012 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */
17013
17014 if( c=='e' ){
17015 eMode = 'x';
17016 bOnce = 2;
17017 }else if( strncmp(azArg[0],"once",n)==0 ){
17018 bOnce = 1;
16682 }
17019 }
16683 if( nArg>2 ){
16684 utf8_printf(stderr, "Usage: .%s [-e|-x|FILE]\n", azArg[0]);
16685 rc = 1;
16686 goto meta_command_exit;
16687 }
16688 if( n>1 && strncmp(azArg[0], "once", n)==0 ){
16689 if( nArg<2 ){
16690 raw_printf(stderr, "Usage: .once (-e|-x|FILE)\n");
17020 for(i=1; i<nArg; i++){
17021 char *z = azArg[i];
17022 if( z[0]=='-' ){
17023 if( z[1]=='-' ) z++;
17024 if( strcmp(z,"-bom")==0 ){
17025 bBOM = 1;
17026 }else if( c!='e' && strcmp(z,"-x")==0 ){
17027 eMode = 'x'; /* spreadsheet */
17028 }else if( c!='e' && strcmp(z,"-e")==0 ){
17029 eMode = 'e'; /* text editor */
17030 }else{
17031 utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n",
17032 azArg[i]);
17033 showHelp(p->out, azArg[0]);
17034 rc = 1;
17035 goto meta_command_exit;
17036 }
17037 }else if( zFile==0 ){
17038 zFile = z;
17039 }else{
17040 utf8_printf(p->out,"ERROR: extra parameter: \"%s\". Usage:\n",
17041 azArg[i]);
17042 showHelp(p->out, azArg[0]);
16691 rc = 1;
16692 goto meta_command_exit;
16693 }
17043 rc = 1;
17044 goto meta_command_exit;
17045 }
17046 }
17047 if( zFile==0 ) zFile = "stdout";
17048 if( bOnce ){
16694 p->outCount = 2;
16695 }else{
16696 p->outCount = 0;
16697 }
16698 output_reset(p);
17049 p->outCount = 2;
17050 }else{
17051 p->outCount = 0;
17052 }
17053 output_reset(p);
16699 if( zFile[0]=='-' && zFile[1]=='-' ) zFile++;
16700#ifndef SQLITE_NOHAVE_SYSTEM
17054#ifndef SQLITE_NOHAVE_SYSTEM
16701 if( strcmp(zFile, "-e")==0 || strcmp(zFile, "-x")==0 ){
17055 if( eMode=='e' || eMode=='x' ){
16702 p->doXdgOpen = 1;
16703 outputModePush(p);
17056 p->doXdgOpen = 1;
17057 outputModePush(p);
16704 if( zFile[1]=='x' ){
17058 if( eMode=='x' ){
17059 /* spreadsheet mode. Output as CSV. */
16705 newTempFile(p, "csv");
17060 newTempFile(p, "csv");
17061 ShellClearFlag(p, SHFLG_Echo);
16706 p->mode = MODE_Csv;
16707 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
16708 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
16709 }else{
17062 p->mode = MODE_Csv;
17063 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
17064 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
17065 }else{
17066 /* text editor mode */
16710 newTempFile(p, "txt");
16711 bTxtMode = 1;
16712 }
16713 zFile = p->zTempFile;
16714 }
16715#endif /* SQLITE_NOHAVE_SYSTEM */
16716 if( zFile[0]=='|' ){
16717#ifdef SQLITE_OMIT_POPEN
16718 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
16719 rc = 1;
16720 p->out = stdout;
16721#else
16722 p->out = popen(zFile + 1, "w");
16723 if( p->out==0 ){
16724 utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
16725 p->out = stdout;
16726 rc = 1;
16727 }else{
17067 newTempFile(p, "txt");
17068 bTxtMode = 1;
17069 }
17070 zFile = p->zTempFile;
17071 }
17072#endif /* SQLITE_NOHAVE_SYSTEM */
17073 if( zFile[0]=='|' ){
17074#ifdef SQLITE_OMIT_POPEN
17075 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
17076 rc = 1;
17077 p->out = stdout;
17078#else
17079 p->out = popen(zFile + 1, "w");
17080 if( p->out==0 ){
17081 utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
17082 p->out = stdout;
17083 rc = 1;
17084 }else{
17085 if( bBOM ) fprintf(p->out,"\357\273\277");
16728 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
16729 }
16730#endif
16731 }else{
16732 p->out = output_file_open(zFile, bTxtMode);
16733 if( p->out==0 ){
16734 if( strcmp(zFile,"off")!=0 ){
16735 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
16736 }
16737 p->out = stdout;
16738 rc = 1;
16739 } else {
17086 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
17087 }
17088#endif
17089 }else{
17090 p->out = output_file_open(zFile, bTxtMode);
17091 if( p->out==0 ){
17092 if( strcmp(zFile,"off")!=0 ){
17093 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
17094 }
17095 p->out = stdout;
17096 rc = 1;
17097 } else {
17098 if( bBOM ) fprintf(p->out,"\357\273\277");
16740 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
16741 }
16742 }
16743 }else
16744
16745 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
16746 open_db(p,0);
16747 if( nArg<=1 ) goto parameter_syntax_error;

--- 1047 unchanged lines hidden (view full) ---

17795 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
17796#ifdef YYCOVERAGE
17797 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
17798#endif
17799 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
17800 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
17801 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
17802 { "prng_seed", SQLITE_TESTCTRL_PRNG_SEED, "SEED ?db?" },
17099 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
17100 }
17101 }
17102 }else
17103
17104 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
17105 open_db(p,0);
17106 if( nArg<=1 ) goto parameter_syntax_error;

--- 1047 unchanged lines hidden (view full) ---

18154 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
18155#ifdef YYCOVERAGE
18156 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
18157#endif
18158 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
18159 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
18160 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
18161 { "prng_seed", SQLITE_TESTCTRL_PRNG_SEED, "SEED ?db?" },
17803 { "reserve", SQLITE_TESTCTRL_RESERVE, "BYTES-OF-RESERVE"},
17804 };
17805 int testctrl = -1;
17806 int iCtrl = -1;
17807 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
17808 int isOk = 0;
17809 int i, n2;
17810 const char *zCmd = 0;
17811

--- 36 unchanged lines hidden (view full) ---

17848 if( testctrl<0 ){
17849 utf8_printf(stderr,"Error: unknown test-control: %s\n"
17850 "Use \".testctrl --help\" for help\n", zCmd);
17851 }else{
17852 switch(testctrl){
17853
17854 /* sqlite3_test_control(int, db, int) */
17855 case SQLITE_TESTCTRL_OPTIMIZATIONS:
18162 };
18163 int testctrl = -1;
18164 int iCtrl = -1;
18165 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
18166 int isOk = 0;
18167 int i, n2;
18168 const char *zCmd = 0;
18169

--- 36 unchanged lines hidden (view full) ---

18206 if( testctrl<0 ){
18207 utf8_printf(stderr,"Error: unknown test-control: %s\n"
18208 "Use \".testctrl --help\" for help\n", zCmd);
18209 }else{
18210 switch(testctrl){
18211
18212 /* sqlite3_test_control(int, db, int) */
18213 case SQLITE_TESTCTRL_OPTIMIZATIONS:
17856 case SQLITE_TESTCTRL_RESERVE:
17857 if( nArg==3 ){
17858 int opt = (int)strtol(azArg[2], 0, 0);
17859 rc2 = sqlite3_test_control(testctrl, p->db, opt);
17860 isOk = 3;
17861 }
17862 break;
17863
17864 /* sqlite3_test_control(int) */

--- 755 unchanged lines hidden (view full) ---

18620 sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
18621}
18622
18623/*
18624** Output text to the console in a font that attracts extra attention.
18625*/
18626#ifdef _WIN32
18627static void printBold(const char *zText){
18214 if( nArg==3 ){
18215 int opt = (int)strtol(azArg[2], 0, 0);
18216 rc2 = sqlite3_test_control(testctrl, p->db, opt);
18217 isOk = 3;
18218 }
18219 break;
18220
18221 /* sqlite3_test_control(int) */

--- 755 unchanged lines hidden (view full) ---

18977 sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
18978}
18979
18980/*
18981** Output text to the console in a font that attracts extra attention.
18982*/
18983#ifdef _WIN32
18984static void printBold(const char *zText){
18985#if !SQLITE_OS_WINRT
18628 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
18629 CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
18630 GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
18631 SetConsoleTextAttribute(out,
18632 FOREGROUND_RED|FOREGROUND_INTENSITY
18633 );
18986 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
18987 CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
18988 GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
18989 SetConsoleTextAttribute(out,
18990 FOREGROUND_RED|FOREGROUND_INTENSITY
18991 );
18992#endif
18634 printf("%s", zText);
18993 printf("%s", zText);
18994#if !SQLITE_OS_WINRT
18635 SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
18995 SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
18996#endif
18636}
18637#else
18638static void printBold(const char *zText){
18639 printf("\033[1m%s\033[0m", zText);
18640}
18641#endif
18642
18643/*

--- 38 unchanged lines hidden (view full) ---

18682 int argcToFree = 0;
18683#endif
18684
18685 setBinaryMode(stdin, 0);
18686 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
18687 stdin_is_interactive = isatty(0);
18688 stdout_is_console = isatty(1);
18689
18997}
18998#else
18999static void printBold(const char *zText){
19000 printf("\033[1m%s\033[0m", zText);
19001}
19002#endif
19003
19004/*

--- 38 unchanged lines hidden (view full) ---

19043 int argcToFree = 0;
19044#endif
19045
19046 setBinaryMode(stdin, 0);
19047 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
19048 stdin_is_interactive = isatty(0);
19049 stdout_is_console = isatty(1);
19050
19051#ifdef SQLITE_DEBUG
19052 registerOomSimulator();
19053#endif
19054
18690#if !defined(_WIN32_WCE)
18691 if( getenv("SQLITE_DEBUG_BREAK") ){
18692 if( isatty(0) && isatty(2) ){
18693 fprintf(stderr,
18694 "attach debugger to process %d and press any key to continue.\n",
18695 GETPID());
18696 fgetc(stdin);
18697 }else{
18698#if defined(_WIN32) || defined(WIN32)
19055#if !defined(_WIN32_WCE)
19056 if( getenv("SQLITE_DEBUG_BREAK") ){
19057 if( isatty(0) && isatty(2) ){
19058 fprintf(stderr,
19059 "attach debugger to process %d and press any key to continue.\n",
19060 GETPID());
19061 fgetc(stdin);
19062 }else{
19063#if defined(_WIN32) || defined(WIN32)
19064#if SQLITE_OS_WINRT
19065 __debugbreak();
19066#else
18699 DebugBreak();
19067 DebugBreak();
19068#endif
18700#elif defined(SIGTRAP)
18701 raise(SIGTRAP);
18702#endif
18703 }
18704 }
18705#endif
18706
18707#if USE_SYSTEM_SQLITE+0!=1

--- 474 unchanged lines hidden ---
19069#elif defined(SIGTRAP)
19070 raise(SIGTRAP);
19071#endif
19072 }
19073 }
19074#endif
19075
19076#if USE_SYSTEM_SQLITE+0!=1

--- 474 unchanged lines hidden ---