| | @@ -250,33 +250,1023 @@ |
| 250 | 250 | #define WIN32_LEAN_AND_MEAN |
| 251 | 251 | #include <windows.h> |
| 252 | 252 | |
| 253 | 253 | /* string conversion routines only needed on Win32 */ |
| 254 | 254 | extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR); |
| 255 | | -extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int); |
| 256 | | -extern char *sqlite3_win32_utf8_to_mbcs_v2(const char *, int); |
| 257 | 255 | extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText); |
| 258 | 256 | #endif |
| 259 | 257 | |
| 260 | | -/* On Windows, we normally run with output mode of TEXT so that \n characters |
| 261 | | -** are automatically translated into \r\n. However, this behavior needs |
| 262 | | -** to be disabled in some cases (ex: when generating CSV output and when |
| 263 | | -** rendering quoted strings that contain \n characters). The following |
| 264 | | -** routines take care of that. |
| 265 | | -*/ |
| 266 | | -#if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT |
| 267 | | -static void setBinaryMode(FILE *file, int isOutput){ |
| 268 | | - if( isOutput ) fflush(file); |
| 269 | | - _setmode(_fileno(file), _O_BINARY); |
| 270 | | -} |
| 271 | | -static void setTextMode(FILE *file, int isOutput){ |
| 272 | | - if( isOutput ) fflush(file); |
| 273 | | - _setmode(_fileno(file), _O_TEXT); |
| 274 | | -} |
| 258 | +/* Use console I/O package as a direct INCLUDE. */ |
| 259 | +#define SQLITE_INTERNAL_LINKAGE static |
| 260 | + |
| 261 | +#ifdef SQLITE_SHELL_FIDDLE |
| 262 | +/* Deselect most features from the console I/O package for Fiddle. */ |
| 263 | +# define SQLITE_CIO_NO_REDIRECT |
| 264 | +# define SQLITE_CIO_NO_CLASSIFY |
| 265 | +# define SQLITE_CIO_NO_TRANSLATE |
| 266 | +# define SQLITE_CIO_NO_SETMODE |
| 267 | +#endif |
| 268 | +/************************* Begin ../ext/consio/console_io.h ******************/ |
| 269 | +/* |
| 270 | +** 2023 November 1 |
| 271 | +** |
| 272 | +** The author disclaims copyright to this source code. In place of |
| 273 | +** a legal notice, here is a blessing: |
| 274 | +** |
| 275 | +** May you do good and not evil. |
| 276 | +** May you find forgiveness for yourself and forgive others. |
| 277 | +** May you share freely, never taking more than you give. |
| 278 | +** |
| 279 | +******************************************************************************** |
| 280 | +** This file exposes various interfaces used for console and other I/O |
| 281 | +** by the SQLite project command-line tools. These interfaces are used |
| 282 | +** at either source conglomeration time, compilation time, or run time. |
| 283 | +** This source provides for either inclusion into conglomerated, |
| 284 | +** "single-source" forms or separate compilation then linking. |
| 285 | +** |
| 286 | +** Platform dependencies are "hidden" here by various stratagems so |
| 287 | +** that, provided certain conditions are met, the programs using this |
| 288 | +** source or object code compiled from it need no explicit conditional |
| 289 | +** compilation in their source for their console and stream I/O. |
| 290 | +** |
| 291 | +** The symbols and functionality exposed here are not a public API. |
| 292 | +** This code may change in tandem with other project code as needed. |
| 293 | +** |
| 294 | +** When this .h file and its companion .c are directly incorporated into |
| 295 | +** a source conglomeration (such as shell.c), the preprocessor symbol |
| 296 | +** CIO_WIN_WC_XLATE is defined as 0 or 1, reflecting whether console I/O |
| 297 | +** translation for Windows is effected for the build. |
| 298 | +*/ |
| 299 | + |
| 300 | +#ifndef SQLITE_INTERNAL_LINKAGE |
| 301 | +# define SQLITE_INTERNAL_LINKAGE extern /* external to translation unit */ |
| 302 | +# include <stdio.h> |
| 303 | +#else |
| 304 | +# define SHELL_NO_SYSINC /* Better yet, modify mkshellc.tcl for this. */ |
| 305 | +#endif |
| 306 | + |
| 307 | +#ifndef SQLITE3_H |
| 308 | +/* # include "sqlite3.h" */ |
| 309 | +#endif |
| 310 | + |
| 311 | +#ifndef SQLITE_CIO_NO_CLASSIFY |
| 312 | + |
| 313 | +/* Define enum for use with following function. */ |
| 314 | +typedef enum StreamsAreConsole { |
| 315 | + SAC_NoConsole = 0, |
| 316 | + SAC_InConsole = 1, SAC_OutConsole = 2, SAC_ErrConsole = 4, |
| 317 | + SAC_AnyConsole = 0x7 |
| 318 | +} StreamsAreConsole; |
| 319 | + |
| 320 | +/* |
| 321 | +** Classify the three standard I/O streams according to whether |
| 322 | +** they are connected to a console attached to the process. |
| 323 | +** |
| 324 | +** Returns the bit-wise OR of SAC_{In,Out,Err}Console values, |
| 325 | +** or SAC_NoConsole if none of the streams reaches a console. |
| 326 | +** |
| 327 | +** This function should be called before any I/O is done with |
| 328 | +** the given streams. As a side-effect, the given inputs are |
| 329 | +** recorded so that later I/O operations on them may be done |
| 330 | +** differently than the C library FILE* I/O would be done, |
| 331 | +** iff the stream is used for the I/O functions that follow, |
| 332 | +** and to support the ones that use an implicit stream. |
| 333 | +** |
| 334 | +** On some platforms, stream or console mode alteration (aka |
| 335 | +** "Setup") may be made which is undone by consoleRestore(). |
| 336 | +*/ |
| 337 | +SQLITE_INTERNAL_LINKAGE StreamsAreConsole |
| 338 | +consoleClassifySetup( FILE *pfIn, FILE *pfOut, FILE *pfErr ); |
| 339 | +/* A usual call for convenience: */ |
| 340 | +#define SQLITE_STD_CONSOLE_INIT() consoleClassifySetup(stdin,stdout,stderr) |
| 341 | + |
| 342 | +/* |
| 343 | +** After an initial call to consoleClassifySetup(...), renew |
| 344 | +** the same setup it effected. (A call not after is an error.) |
| 345 | +** This will restore state altered by consoleRestore(); |
| 346 | +** |
| 347 | +** Applications which run an inferior (child) process which |
| 348 | +** inherits the same I/O streams may call this function after |
| 349 | +** such a process exits to guard against console mode changes. |
| 350 | +*/ |
| 351 | +SQLITE_INTERNAL_LINKAGE void consoleRenewSetup(void); |
| 352 | + |
| 353 | +/* |
| 354 | +** Undo any side-effects left by consoleClassifySetup(...). |
| 355 | +** |
| 356 | +** This should be called after consoleClassifySetup() and |
| 357 | +** before the process terminates normally. It is suitable |
| 358 | +** for use with the atexit() C library procedure. After |
| 359 | +** this call, no console I/O should be done until one of |
| 360 | +** console{Classify or Renew}Setup(...) is called again. |
| 361 | +** |
| 362 | +** Applications which run an inferior (child) process that |
| 363 | +** inherits the same I/O streams might call this procedure |
| 364 | +** before so that said process will have a console setup |
| 365 | +** however users have configured it or come to expect. |
| 366 | +*/ |
| 367 | +SQLITE_INTERNAL_LINKAGE void SQLITE_CDECL consoleRestore( void ); |
| 368 | + |
| 369 | +#else /* defined(SQLITE_CIO_NO_CLASSIFY) */ |
| 370 | +# define consoleClassifySetup(i,o,e) |
| 371 | +# define consoleRenewSetup() |
| 372 | +# define consoleRestore() |
| 373 | +#endif /* defined(SQLITE_CIO_NO_CLASSIFY) */ |
| 374 | + |
| 375 | +#ifndef SQLITE_CIO_NO_REDIRECT |
| 376 | +/* |
| 377 | +** Set stream to be used for the functions below which write |
| 378 | +** to "the designated X stream", where X is Output or Error. |
| 379 | +** Returns the previous value. |
| 380 | +** |
| 381 | +** Alternatively, pass the special value, invalidFileStream, |
| 382 | +** to get the designated stream value without setting it. |
| 383 | +** |
| 384 | +** Before the designated streams are set, they default to |
| 385 | +** those passed to consoleClassifySetup(...), and before |
| 386 | +** that is called they default to stdout and stderr. |
| 387 | +** |
| 388 | +** It is error to close a stream so designated, then, without |
| 389 | +** designating another, use the corresponding {o,e}Emit(...). |
| 390 | +*/ |
| 391 | +SQLITE_INTERNAL_LINKAGE FILE *invalidFileStream; |
| 392 | +SQLITE_INTERNAL_LINKAGE FILE *setOutputStream(FILE *pf); |
| 393 | +# ifdef CONSIO_SET_ERROR_STREAM |
| 394 | +SQLITE_INTERNAL_LINKAGE FILE *setErrorStream(FILE *pf); |
| 395 | +# endif |
| 396 | +#else |
| 397 | +# define setOutputStream(pf) |
| 398 | +# define setErrorStream(pf) |
| 399 | +#endif /* !defined(SQLITE_CIO_NO_REDIRECT) */ |
| 400 | + |
| 401 | +#ifndef SQLITE_CIO_NO_TRANSLATE |
| 402 | +/* |
| 403 | +** Emit output like fprintf(). If the output is going to the |
| 404 | +** console and translation from UTF-8 is necessary, perform |
| 405 | +** the needed translation. Otherwise, write formatted output |
| 406 | +** to the provided stream almost as-is, possibly with newline |
| 407 | +** translation as specified by set{Binary,Text}Mode(). |
| 408 | +*/ |
| 409 | +SQLITE_INTERNAL_LINKAGE int fPrintfUtf8(FILE *pfO, const char *zFormat, ...); |
| 410 | +/* Like fPrintfUtf8 except stream is always the designated output. */ |
| 411 | +SQLITE_INTERNAL_LINKAGE int oPrintfUtf8(const char *zFormat, ...); |
| 412 | +/* Like fPrintfUtf8 except stream is always the designated error. */ |
| 413 | +SQLITE_INTERNAL_LINKAGE int ePrintfUtf8(const char *zFormat, ...); |
| 414 | + |
| 415 | +/* |
| 416 | +** Emit output like fputs(). If the output is going to the |
| 417 | +** console and translation from UTF-8 is necessary, perform |
| 418 | +** the needed translation. Otherwise, write given text to the |
| 419 | +** provided stream almost as-is, possibly with newline |
| 420 | +** translation as specified by set{Binary,Text}Mode(). |
| 421 | +*/ |
| 422 | +SQLITE_INTERNAL_LINKAGE int fPutsUtf8(const char *z, FILE *pfO); |
| 423 | +/* Like fPutsUtf8 except stream is always the designated output. */ |
| 424 | +SQLITE_INTERNAL_LINKAGE int oPutsUtf8(const char *z); |
| 425 | +/* Like fPutsUtf8 except stream is always the designated error. */ |
| 426 | +SQLITE_INTERNAL_LINKAGE int ePutsUtf8(const char *z); |
| 427 | + |
| 428 | +/* |
| 429 | +** Emit output like fPutsUtf8(), except that the length of the |
| 430 | +** accepted char or character sequence is limited by nAccept. |
| 431 | +** |
| 432 | +** Returns the number of accepted char values. |
| 433 | +*/ |
| 434 | +#ifdef CONSIO_SPUTB |
| 435 | +SQLITE_INTERNAL_LINKAGE int |
| 436 | +fPutbUtf8(FILE *pfOut, const char *cBuf, int nAccept); |
| 437 | +#endif |
| 438 | +/* Like fPutbUtf8 except stream is always the designated output. */ |
| 439 | +SQLITE_INTERNAL_LINKAGE int |
| 440 | +oPutbUtf8(const char *cBuf, int nAccept); |
| 441 | +/* Like fPutbUtf8 except stream is always the designated error. */ |
| 442 | +#ifdef CONSIO_EPUTB |
| 443 | +SQLITE_INTERNAL_LINKAGE int |
| 444 | +ePutbUtf8(const char *cBuf, int nAccept); |
| 445 | +#endif |
| 446 | + |
| 447 | +/* |
| 448 | +** Collect input like fgets(...) with special provisions for input |
| 449 | +** from the console on platforms that require same. Defers to the |
| 450 | +** C library fgets() when input is not from the console. Newline |
| 451 | +** translation may be done as set by set{Binary,Text}Mode(). As a |
| 452 | +** convenience, pfIn==NULL is treated as stdin. |
| 453 | +*/ |
| 454 | +SQLITE_INTERNAL_LINKAGE char* fGetsUtf8(char *cBuf, int ncMax, FILE *pfIn); |
| 455 | +/* Like fGetsUtf8 except stream is always the designated input. */ |
| 456 | +/* SQLITE_INTERNAL_LINKAGE char* iGetsUtf8(char *cBuf, int ncMax); */ |
| 457 | + |
| 458 | +#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */ |
| 459 | + |
| 460 | +#ifndef SQLITE_CIO_NO_SETMODE |
| 461 | +/* |
| 462 | +** Set given stream for binary mode, where newline translation is |
| 463 | +** not done, or for text mode where, for some platforms, newlines |
| 464 | +** are translated to the platform's conventional char sequence. |
| 465 | +** If bFlush true, flush the stream. |
| 466 | +** |
| 467 | +** An additional side-effect is that if the stream is one passed |
| 468 | +** to consoleClassifySetup() as an output, it is flushed first. |
| 469 | +** |
| 470 | +** Note that binary/text mode has no effect on console I/O |
| 471 | +** translation. On all platforms, newline to the console starts |
| 472 | +** a new line and CR,LF chars from the console become a newline. |
| 473 | +*/ |
| 474 | +SQLITE_INTERNAL_LINKAGE void setBinaryMode(FILE *, short bFlush); |
| 475 | +SQLITE_INTERNAL_LINKAGE void setTextMode(FILE *, short bFlush); |
| 476 | +#endif |
| 477 | + |
| 478 | +#ifdef SQLITE_CIO_PROMPTED_IN |
| 479 | +typedef struct Prompts { |
| 480 | + int numPrompts; |
| 481 | + const char **azPrompts; |
| 482 | +} Prompts; |
| 483 | + |
| 484 | +/* |
| 485 | +** Macros for use of a line editor. |
| 486 | +** |
| 487 | +** The following macros define operations involving use of a |
| 488 | +** line-editing library or simple console interaction. |
| 489 | +** A "T" argument is a text (char *) buffer or filename. |
| 490 | +** A "N" argument is an integer. |
| 491 | +** |
| 492 | +** SHELL_ADD_HISTORY(T) // Record text as line(s) of history. |
| 493 | +** SHELL_READ_HISTORY(T) // Read history from file named by T. |
| 494 | +** SHELL_WRITE_HISTORY(T) // Write history to file named by T. |
| 495 | +** SHELL_STIFLE_HISTORY(N) // Limit history to N entries. |
| 496 | +** |
| 497 | +** A console program which does interactive console input is |
| 498 | +** expected to call: |
| 499 | +** SHELL_READ_HISTORY(T) before collecting such input; |
| 500 | +** SHELL_ADD_HISTORY(T) as record-worthy input is taken; |
| 501 | +** SHELL_STIFLE_HISTORY(N) after console input ceases; then |
| 502 | +** SHELL_WRITE_HISTORY(T) before the program exits. |
| 503 | +*/ |
| 504 | + |
| 505 | +/* |
| 506 | +** Retrieve a single line of input text from an input stream. |
| 507 | +** |
| 508 | +** If pfIn is the input stream passed to consoleClassifySetup(), |
| 509 | +** and azPrompt is not NULL, then a prompt is issued before the |
| 510 | +** line is collected, as selected by the isContinuation flag. |
| 511 | +** Array azPrompt[{0,1}] holds the {main,continuation} prompt. |
| 512 | +** |
| 513 | +** If zBufPrior is not NULL then it is a buffer from a prior |
| 514 | +** call to this routine that can be reused, or will be freed. |
| 515 | +** |
| 516 | +** The result is stored in space obtained from malloc() and |
| 517 | +** must either be freed by the caller or else passed back to |
| 518 | +** this function as zBufPrior for reuse. |
| 519 | +** |
| 520 | +** This function may call upon services of a line-editing |
| 521 | +** library to interactively collect line edited input. |
| 522 | +*/ |
| 523 | +SQLITE_INTERNAL_LINKAGE char * |
| 524 | +shellGetLine(FILE *pfIn, char *zBufPrior, int nLen, |
| 525 | + short isContinuation, Prompts azPrompt); |
| 526 | +#endif /* defined(SQLITE_CIO_PROMPTED_IN) */ |
| 527 | +/* |
| 528 | +** TBD: Define an interface for application(s) to generate |
| 529 | +** completion candidates for use by the line-editor. |
| 530 | +** |
| 531 | +** This may be premature; the CLI is the only application |
| 532 | +** that does this. Yet, getting line-editing melded into |
| 533 | +** console I/O is desirable because a line-editing library |
| 534 | +** may have to establish console operating mode, possibly |
| 535 | +** in a way that interferes with the above functionality. |
| 536 | +*/ |
| 537 | + |
| 538 | +#if !(defined(SQLITE_CIO_NO_UTF8SCAN)&&defined(SQLITE_CIO_NO_TRANSLATE)) |
| 539 | +/* Skip over as much z[] input char sequence as is valid UTF-8, |
| 540 | +** limited per nAccept char's or whole characters and containing |
| 541 | +** no char cn such that ((1<<cn) & ccm)!=0. On return, the |
| 542 | +** sequence z:return (inclusive:exclusive) is validated UTF-8. |
| 543 | +** Limit: nAccept>=0 => char count, nAccept<0 => character |
| 544 | + */ |
| 545 | +SQLITE_INTERNAL_LINKAGE const char* |
| 546 | +zSkipValidUtf8(const char *z, int nAccept, long ccm); |
| 547 | + |
| 548 | +#endif |
| 549 | + |
| 550 | +/************************* End ../ext/consio/console_io.h ********************/ |
| 551 | +/************************* Begin ../ext/consio/console_io.c ******************/ |
| 552 | +/* |
| 553 | +** 2023 November 4 |
| 554 | +** |
| 555 | +** The author disclaims copyright to this source code. In place of |
| 556 | +** a legal notice, here is a blessing: |
| 557 | +** |
| 558 | +** May you do good and not evil. |
| 559 | +** May you find forgiveness for yourself and forgive others. |
| 560 | +** May you share freely, never taking more than you give. |
| 561 | +** |
| 562 | +******************************************************************************** |
| 563 | +** This file implements various interfaces used for console and stream I/O |
| 564 | +** by the SQLite project command-line tools, as explained in console_io.h . |
| 565 | +** Functions prefixed by "SQLITE_INTERNAL_LINKAGE" behave as described there. |
| 566 | +*/ |
| 567 | + |
| 568 | +#ifndef SQLITE_CDECL |
| 569 | +# define SQLITE_CDECL |
| 570 | +#endif |
| 571 | + |
| 572 | +#ifndef SHELL_NO_SYSINC |
| 573 | +# include <stdarg.h> |
| 574 | +# include <string.h> |
| 575 | +# include <stdlib.h> |
| 576 | +# include <limits.h> |
| 577 | +# include <assert.h> |
| 578 | +# include "console_io.h" |
| 579 | +/* # include "sqlite3.h" */ |
| 580 | +#endif |
| 581 | + |
| 582 | +#ifndef SQLITE_CIO_NO_TRANSLATE |
| 583 | +# if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT |
| 584 | +# ifndef SHELL_NO_SYSINC |
| 585 | +# include <io.h> |
| 586 | +# include <fcntl.h> |
| 587 | +# undef WIN32_LEAN_AND_MEAN |
| 588 | +# define WIN32_LEAN_AND_MEAN |
| 589 | +# include <windows.h> |
| 590 | +# endif |
| 591 | +# define CIO_WIN_WC_XLATE 1 /* Use WCHAR Windows APIs for console I/O */ |
| 592 | +# else |
| 593 | +# ifndef SHELL_NO_SYSINC |
| 594 | +# include <unistd.h> |
| 595 | +# endif |
| 596 | +# define CIO_WIN_WC_XLATE 0 /* Use plain C library stream I/O at console */ |
| 597 | +# endif |
| 598 | +#else |
| 599 | +# define CIO_WIN_WC_XLATE 0 /* Not exposing translation routines at all */ |
| 600 | +#endif |
| 601 | + |
| 602 | +#if CIO_WIN_WC_XLATE |
| 603 | +/* Character used to represent a known-incomplete UTF-8 char group (�) */ |
| 604 | +static WCHAR cBadGroup = 0xfffd; |
| 605 | +#endif |
| 606 | + |
| 607 | +#if CIO_WIN_WC_XLATE |
| 608 | +static HANDLE handleOfFile(FILE *pf){ |
| 609 | + int fileDesc = _fileno(pf); |
| 610 | + union { intptr_t osfh; HANDLE fh; } fid = { |
| 611 | + (fileDesc>=0)? _get_osfhandle(fileDesc) : (intptr_t)INVALID_HANDLE_VALUE |
| 612 | + }; |
| 613 | + return fid.fh; |
| 614 | +} |
| 615 | +#endif |
| 616 | + |
| 617 | +#ifndef SQLITE_CIO_NO_TRANSLATE |
| 618 | +typedef struct PerStreamTags { |
| 619 | +# if CIO_WIN_WC_XLATE |
| 620 | + HANDLE hx; |
| 621 | + DWORD consMode; |
| 622 | + char acIncomplete[4]; |
| 623 | +# else |
| 624 | + short reachesConsole; |
| 625 | +# endif |
| 626 | + FILE *pf; |
| 627 | +} PerStreamTags; |
| 628 | + |
| 629 | +/* Define NULL-like value for things which can validly be 0. */ |
| 630 | +# define SHELL_INVALID_FILE_PTR ((FILE *)~0) |
| 631 | +# if CIO_WIN_WC_XLATE |
| 632 | +# define SHELL_INVALID_CONS_MODE 0xFFFF0000 |
| 633 | +# endif |
| 634 | + |
| 635 | +# if CIO_WIN_WC_XLATE |
| 636 | +# define PST_INITIALIZER { INVALID_HANDLE_VALUE, SHELL_INVALID_CONS_MODE, \ |
| 637 | + {0,0,0,0}, SHELL_INVALID_FILE_PTR } |
| 638 | +# else |
| 639 | +# define PST_INITIALIZER { 0, SHELL_INVALID_FILE_PTR } |
| 640 | +# endif |
| 641 | + |
| 642 | +/* Quickly say whether a known output is going to the console. */ |
| 643 | +# if CIO_WIN_WC_XLATE |
| 644 | +static short pstReachesConsole(PerStreamTags *ppst){ |
| 645 | + return (ppst->hx != INVALID_HANDLE_VALUE); |
| 646 | +} |
| 647 | +# else |
| 648 | +# define pstReachesConsole(ppst) 0 |
| 649 | +# endif |
| 650 | + |
| 651 | +# if CIO_WIN_WC_XLATE |
| 652 | +static void restoreConsoleArb(PerStreamTags *ppst){ |
| 653 | + if( pstReachesConsole(ppst) ) SetConsoleMode(ppst->hx, ppst->consMode); |
| 654 | +} |
| 655 | +# else |
| 656 | +# define restoreConsoleArb(ppst) |
| 657 | +# endif |
| 658 | + |
| 659 | +/* Say whether FILE* appears to be a console, collect associated info. */ |
| 660 | +static short streamOfConsole(FILE *pf, /* out */ PerStreamTags *ppst){ |
| 661 | +# if CIO_WIN_WC_XLATE |
| 662 | + short rv = 0; |
| 663 | + DWORD dwCM = SHELL_INVALID_CONS_MODE; |
| 664 | + HANDLE fh = handleOfFile(pf); |
| 665 | + ppst->pf = pf; |
| 666 | + if( INVALID_HANDLE_VALUE != fh ){ |
| 667 | + rv = (GetFileType(fh) == FILE_TYPE_CHAR && GetConsoleMode(fh,&dwCM)); |
| 668 | + } |
| 669 | + ppst->hx = (rv)? fh : INVALID_HANDLE_VALUE; |
| 670 | + ppst->consMode = dwCM; |
| 671 | + return rv; |
| 672 | +# else |
| 673 | + ppst->pf = pf; |
| 674 | + ppst->reachesConsole = ( (short)isatty(fileno(pf)) ); |
| 675 | + return ppst->reachesConsole; |
| 676 | +# endif |
| 677 | +} |
| 678 | + |
| 679 | +# if CIO_WIN_WC_XLATE |
| 680 | +/* Define console modes for use with the Windows Console API. */ |
| 681 | +# define SHELL_CONI_MODE \ |
| 682 | + (ENABLE_ECHO_INPUT | ENABLE_INSERT_MODE | ENABLE_LINE_INPUT | 0x80 \ |
| 683 | + | ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS | ENABLE_PROCESSED_INPUT) |
| 684 | +# define SHELL_CONO_MODE (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT \ |
| 685 | + | ENABLE_VIRTUAL_TERMINAL_PROCESSING) |
| 686 | +# endif |
| 687 | + |
| 688 | +typedef struct ConsoleInfo { |
| 689 | + PerStreamTags pstSetup[3]; |
| 690 | + PerStreamTags pstDesignated[3]; |
| 691 | + StreamsAreConsole sacSetup; |
| 692 | +} ConsoleInfo; |
| 693 | + |
| 694 | +static short isValidStreamInfo(PerStreamTags *ppst){ |
| 695 | + return (ppst->pf != SHELL_INVALID_FILE_PTR); |
| 696 | +} |
| 697 | + |
| 698 | +static ConsoleInfo consoleInfo = { |
| 699 | + { /* pstSetup */ PST_INITIALIZER, PST_INITIALIZER, PST_INITIALIZER }, |
| 700 | + { /* pstDesignated[] */ PST_INITIALIZER, PST_INITIALIZER, PST_INITIALIZER }, |
| 701 | + SAC_NoConsole /* sacSetup */ |
| 702 | +}; |
| 703 | + |
| 704 | +SQLITE_INTERNAL_LINKAGE FILE* invalidFileStream = (FILE *)~0; |
| 705 | + |
| 706 | +# if CIO_WIN_WC_XLATE |
| 707 | +static void maybeSetupAsConsole(PerStreamTags *ppst, short odir){ |
| 708 | + if( pstReachesConsole(ppst) ){ |
| 709 | + DWORD cm = odir? SHELL_CONO_MODE : SHELL_CONI_MODE; |
| 710 | + SetConsoleMode(ppst->hx, cm); |
| 711 | + } |
| 712 | +} |
| 713 | +# else |
| 714 | +# define maybeSetupAsConsole(ppst,odir) |
| 715 | +# endif |
| 716 | + |
| 717 | +SQLITE_INTERNAL_LINKAGE void consoleRenewSetup(void){ |
| 718 | +# if CIO_WIN_WC_XLATE |
| 719 | + int ix = 0; |
| 720 | + while( ix < 6 ){ |
| 721 | + PerStreamTags *ppst = (ix<3)? |
| 722 | + &consoleInfo.pstSetup[ix] : &consoleInfo.pstDesignated[ix-3]; |
| 723 | + maybeSetupAsConsole(ppst, (ix % 3)>0); |
| 724 | + ++ix; |
| 725 | + } |
| 726 | +# endif |
| 727 | +} |
| 728 | + |
| 729 | +SQLITE_INTERNAL_LINKAGE StreamsAreConsole |
| 730 | +consoleClassifySetup( FILE *pfIn, FILE *pfOut, FILE *pfErr ){ |
| 731 | + StreamsAreConsole rv = SAC_NoConsole; |
| 732 | + FILE* apf[3] = { pfIn, pfOut, pfErr }; |
| 733 | + int ix; |
| 734 | + for( ix = 2; ix >= 0; --ix ){ |
| 735 | + PerStreamTags *ppst = &consoleInfo.pstSetup[ix]; |
| 736 | + if( streamOfConsole(apf[ix], ppst) ){ |
| 737 | + rv |= (SAC_InConsole<<ix); |
| 738 | + } |
| 739 | + consoleInfo.pstDesignated[ix] = *ppst; |
| 740 | + if( ix > 0 ) fflush(apf[ix]); |
| 741 | + } |
| 742 | + consoleInfo.sacSetup = rv; |
| 743 | + consoleRenewSetup(); |
| 744 | + return rv; |
| 745 | +} |
| 746 | + |
| 747 | +SQLITE_INTERNAL_LINKAGE void SQLITE_CDECL consoleRestore( void ){ |
| 748 | +# if CIO_WIN_WC_XLATE |
| 749 | + static ConsoleInfo *pci = &consoleInfo; |
| 750 | + if( pci->sacSetup ){ |
| 751 | + int ix; |
| 752 | + for( ix=0; ix<3; ++ix ){ |
| 753 | + if( pci->sacSetup & (SAC_InConsole<<ix) ){ |
| 754 | + PerStreamTags *ppst = &pci->pstSetup[ix]; |
| 755 | + SetConsoleMode(ppst->hx, ppst->consMode); |
| 756 | + } |
| 757 | + } |
| 758 | + } |
| 759 | +# endif |
| 760 | +} |
| 761 | +#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */ |
| 762 | + |
| 763 | +#ifdef SQLITE_CIO_INPUT_REDIR |
| 764 | +/* Say whether given FILE* is among those known, via either |
| 765 | +** consoleClassifySetup() or set{Output,Error}Stream, as |
| 766 | +** readable, and return an associated PerStreamTags pointer |
| 767 | +** if so. Otherwise, return 0. |
| 768 | +*/ |
| 769 | +static PerStreamTags * isKnownReadable(FILE *pf){ |
| 770 | + static PerStreamTags *apst[] = { |
| 771 | + &consoleInfo.pstDesignated[0], &consoleInfo.pstSetup[0], 0 |
| 772 | + }; |
| 773 | + int ix = 0; |
| 774 | + do { |
| 775 | + if( apst[ix]->pf == pf ) break; |
| 776 | + } while( apst[++ix] != 0 ); |
| 777 | + return apst[ix]; |
| 778 | +} |
| 779 | +#endif |
| 780 | + |
| 781 | +#ifndef SQLITE_CIO_NO_TRANSLATE |
| 782 | +/* Say whether given FILE* is among those known, via either |
| 783 | +** consoleClassifySetup() or set{Output,Error}Stream, as |
| 784 | +** writable, and return an associated PerStreamTags pointer |
| 785 | +** if so. Otherwise, return 0. |
| 786 | +*/ |
| 787 | +static PerStreamTags * isKnownWritable(FILE *pf){ |
| 788 | + static PerStreamTags *apst[] = { |
| 789 | + &consoleInfo.pstDesignated[1], &consoleInfo.pstDesignated[2], |
| 790 | + &consoleInfo.pstSetup[1], &consoleInfo.pstSetup[2], 0 |
| 791 | + }; |
| 792 | + int ix = 0; |
| 793 | + do { |
| 794 | + if( apst[ix]->pf == pf ) break; |
| 795 | + } while( apst[++ix] != 0 ); |
| 796 | + return apst[ix]; |
| 797 | +} |
| 798 | + |
| 799 | +static FILE *designateEmitStream(FILE *pf, unsigned chix){ |
| 800 | + FILE *rv = consoleInfo.pstDesignated[chix].pf; |
| 801 | + if( pf == invalidFileStream ) return rv; |
| 802 | + else{ |
| 803 | + /* Setting a possibly new output stream. */ |
| 804 | + PerStreamTags *ppst = isKnownWritable(pf); |
| 805 | + if( ppst != 0 ){ |
| 806 | + PerStreamTags pst = *ppst; |
| 807 | + consoleInfo.pstDesignated[chix] = pst; |
| 808 | + }else streamOfConsole(pf, &consoleInfo.pstDesignated[chix]); |
| 809 | + } |
| 810 | + return rv; |
| 811 | +} |
| 812 | + |
| 813 | +SQLITE_INTERNAL_LINKAGE FILE *setOutputStream(FILE *pf){ |
| 814 | + return designateEmitStream(pf, 1); |
| 815 | +} |
| 816 | +# ifdef CONSIO_SET_ERROR_STREAM |
| 817 | +SQLITE_INTERNAL_LINKAGE FILE *setErrorStream(FILE *pf){ |
| 818 | + return designateEmitStream(pf, 2); |
| 819 | +} |
| 820 | +# endif |
| 821 | +#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */ |
| 822 | + |
| 823 | +#ifndef SQLITE_CIO_NO_SETMODE |
| 824 | +# if CIO_WIN_WC_XLATE |
| 825 | +static void setModeFlushQ(FILE *pf, short bFlush, int mode){ |
| 826 | + if( bFlush ) fflush(pf); |
| 827 | + _setmode(_fileno(pf), mode); |
| 828 | +} |
| 829 | +# else |
| 830 | +# define setModeFlushQ(f, b, m) if(b) fflush(f) |
| 831 | +# endif |
| 832 | + |
| 833 | +SQLITE_INTERNAL_LINKAGE void setBinaryMode(FILE *pf, short bFlush){ |
| 834 | + setModeFlushQ(pf, bFlush, _O_BINARY); |
| 835 | +} |
| 836 | +SQLITE_INTERNAL_LINKAGE void setTextMode(FILE *pf, short bFlush){ |
| 837 | + setModeFlushQ(pf, bFlush, _O_TEXT); |
| 838 | +} |
| 839 | +# undef setModeFlushQ |
| 840 | + |
| 841 | +#else /* defined(SQLITE_CIO_NO_SETMODE) */ |
| 842 | +# define setBinaryMode(f, bFlush) do{ if((bFlush)) fflush(f); }while(0) |
| 843 | +# define setTextMode(f, bFlush) do{ if((bFlush)) fflush(f); }while(0) |
| 844 | +#endif /* defined(SQLITE_CIO_NO_SETMODE) */ |
| 845 | + |
| 846 | +#ifndef SQLITE_CIO_NO_TRANSLATE |
| 847 | +# if CIO_WIN_WC_XLATE |
| 848 | +/* Write buffer cBuf as output to stream known to reach console, |
| 849 | +** limited to ncTake char's. Return ncTake on success, else 0. */ |
| 850 | +static int conZstrEmit(PerStreamTags *ppst, const char *z, int ncTake){ |
| 851 | + int rv = 0; |
| 852 | + if( z!=NULL ){ |
| 853 | + int nwc = MultiByteToWideChar(CP_UTF8,0, z,ncTake, 0,0); |
| 854 | + if( nwc > 0 ){ |
| 855 | + WCHAR *zw = sqlite3_malloc64(nwc*sizeof(WCHAR)); |
| 856 | + if( zw!=NULL ){ |
| 857 | + nwc = MultiByteToWideChar(CP_UTF8,0, z,ncTake, zw,nwc); |
| 858 | + if( nwc > 0 ){ |
| 859 | + /* Translation from UTF-8 to UTF-16, then WCHARs out. */ |
| 860 | + if( WriteConsoleW(ppst->hx, zw,nwc, 0, NULL) ){ |
| 861 | + rv = ncTake; |
| 862 | + } |
| 863 | + } |
| 864 | + sqlite3_free(zw); |
| 865 | + } |
| 866 | + } |
| 867 | + } |
| 868 | + return rv; |
| 869 | +} |
| 870 | + |
| 871 | +/* For {f,o,e}PrintfUtf8() when stream is known to reach console. */ |
| 872 | +static int conioVmPrintf(PerStreamTags *ppst, const char *zFormat, va_list ap){ |
| 873 | + char *z = sqlite3_vmprintf(zFormat, ap); |
| 874 | + if( z ){ |
| 875 | + int rv = conZstrEmit(ppst, z, (int)strlen(z)); |
| 876 | + sqlite3_free(z); |
| 877 | + return rv; |
| 878 | + }else return 0; |
| 879 | +} |
| 880 | +# endif /* CIO_WIN_WC_XLATE */ |
| 881 | + |
| 882 | +# ifdef CONSIO_GET_EMIT_STREAM |
| 883 | +static PerStreamTags * getDesignatedEmitStream(FILE *pf, unsigned chix, |
| 884 | + PerStreamTags *ppst){ |
| 885 | + PerStreamTags *rv = isKnownWritable(pf); |
| 886 | + short isValid = (rv!=0)? isValidStreamInfo(rv) : 0; |
| 887 | + if( rv != 0 && isValid ) return rv; |
| 888 | + streamOfConsole(pf, ppst); |
| 889 | + return ppst; |
| 890 | +} |
| 891 | +# endif |
| 892 | + |
| 893 | +/* Get stream info, either for designated output or error stream when |
| 894 | +** chix equals 1 or 2, or for an arbitrary stream when chix == 0. |
| 895 | +** In either case, ppst references a caller-owned PerStreamTags |
| 896 | +** struct which may be filled in if none of the known writable |
| 897 | +** streams is being held by consoleInfo. The ppf parameter is an |
| 898 | +** output when chix!=0 and an input when chix==0. |
| 899 | + */ |
| 900 | +static PerStreamTags * |
| 901 | +getEmitStreamInfo(unsigned chix, PerStreamTags *ppst, |
| 902 | + /* in/out */ FILE **ppf){ |
| 903 | + PerStreamTags *ppstTry; |
| 904 | + FILE *pfEmit; |
| 905 | + if( chix > 0 ){ |
| 906 | + ppstTry = &consoleInfo.pstDesignated[chix]; |
| 907 | + if( !isValidStreamInfo(ppstTry) ){ |
| 908 | + ppstTry = &consoleInfo.pstSetup[chix]; |
| 909 | + pfEmit = ppst->pf; |
| 910 | + }else pfEmit = ppstTry->pf; |
| 911 | + if( !isValidStreamInfo(ppst) ){ |
| 912 | + pfEmit = (chix > 1)? stderr : stdout; |
| 913 | + ppstTry = ppst; |
| 914 | + streamOfConsole(pfEmit, ppstTry); |
| 915 | + } |
| 916 | + *ppf = pfEmit; |
| 917 | + }else{ |
| 918 | + ppstTry = isKnownWritable(*ppf); |
| 919 | + if( ppstTry != 0 ) return ppstTry; |
| 920 | + streamOfConsole(*ppf, ppst); |
| 921 | + return ppst; |
| 922 | + } |
| 923 | + return ppstTry; |
| 924 | +} |
| 925 | + |
| 926 | +SQLITE_INTERNAL_LINKAGE int oPrintfUtf8(const char *zFormat, ...){ |
| 927 | + va_list ap; |
| 928 | + int rv; |
| 929 | + FILE *pfOut; |
| 930 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 931 | +# if CIO_WIN_WC_XLATE |
| 932 | + PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut); |
| 933 | +# else |
| 934 | + getEmitStreamInfo(1, &pst, &pfOut); |
| 935 | +# endif |
| 936 | + assert(zFormat!=0); |
| 937 | + va_start(ap, zFormat); |
| 938 | +# if CIO_WIN_WC_XLATE |
| 939 | + if( pstReachesConsole(ppst) ){ |
| 940 | + rv = conioVmPrintf(ppst, zFormat, ap); |
| 941 | + }else{ |
| 942 | +# endif |
| 943 | + rv = vfprintf(pfOut, zFormat, ap); |
| 944 | +# if CIO_WIN_WC_XLATE |
| 945 | + } |
| 946 | +# endif |
| 947 | + va_end(ap); |
| 948 | + return rv; |
| 949 | +} |
| 950 | + |
| 951 | +SQLITE_INTERNAL_LINKAGE int ePrintfUtf8(const char *zFormat, ...){ |
| 952 | + va_list ap; |
| 953 | + int rv; |
| 954 | + FILE *pfErr; |
| 955 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 956 | +# if CIO_WIN_WC_XLATE |
| 957 | + PerStreamTags *ppst = getEmitStreamInfo(2, &pst, &pfErr); |
| 958 | +# else |
| 959 | + getEmitStreamInfo(2, &pst, &pfErr); |
| 960 | +# endif |
| 961 | + assert(zFormat!=0); |
| 962 | + va_start(ap, zFormat); |
| 963 | +# if CIO_WIN_WC_XLATE |
| 964 | + if( pstReachesConsole(ppst) ){ |
| 965 | + rv = conioVmPrintf(ppst, zFormat, ap); |
| 966 | + }else{ |
| 967 | +# endif |
| 968 | + rv = vfprintf(pfErr, zFormat, ap); |
| 969 | +# if CIO_WIN_WC_XLATE |
| 970 | + } |
| 971 | +# endif |
| 972 | + va_end(ap); |
| 973 | + return rv; |
| 974 | +} |
| 975 | + |
| 976 | +SQLITE_INTERNAL_LINKAGE int fPrintfUtf8(FILE *pfO, const char *zFormat, ...){ |
| 977 | + va_list ap; |
| 978 | + int rv; |
| 979 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 980 | +# if CIO_WIN_WC_XLATE |
| 981 | + PerStreamTags *ppst = getEmitStreamInfo(0, &pst, &pfO); |
| 982 | +# else |
| 983 | + getEmitStreamInfo(0, &pst, &pfO); |
| 984 | +# endif |
| 985 | + assert(zFormat!=0); |
| 986 | + va_start(ap, zFormat); |
| 987 | +# if CIO_WIN_WC_XLATE |
| 988 | + if( pstReachesConsole(ppst) ){ |
| 989 | + maybeSetupAsConsole(ppst, 1); |
| 990 | + rv = conioVmPrintf(ppst, zFormat, ap); |
| 991 | + if( 0 == isKnownWritable(ppst->pf) ) restoreConsoleArb(ppst); |
| 992 | + }else{ |
| 993 | +# endif |
| 994 | + rv = vfprintf(pfO, zFormat, ap); |
| 995 | +# if CIO_WIN_WC_XLATE |
| 996 | + } |
| 997 | +# endif |
| 998 | + va_end(ap); |
| 999 | + return rv; |
| 1000 | +} |
| 1001 | + |
| 1002 | +SQLITE_INTERNAL_LINKAGE int fPutsUtf8(const char *z, FILE *pfO){ |
| 1003 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 1004 | +# if CIO_WIN_WC_XLATE |
| 1005 | + PerStreamTags *ppst = getEmitStreamInfo(0, &pst, &pfO); |
| 1006 | +# else |
| 1007 | + getEmitStreamInfo(0, &pst, &pfO); |
| 1008 | +# endif |
| 1009 | + assert(z!=0); |
| 1010 | +# if CIO_WIN_WC_XLATE |
| 1011 | + if( pstReachesConsole(ppst) ){ |
| 1012 | + int rv; |
| 1013 | + maybeSetupAsConsole(ppst, 1); |
| 1014 | + rv = conZstrEmit(ppst, z, (int)strlen(z)); |
| 1015 | + if( 0 == isKnownWritable(ppst->pf) ) restoreConsoleArb(ppst); |
| 1016 | + return rv; |
| 1017 | + }else { |
| 1018 | +# endif |
| 1019 | + return (fputs(z, pfO)<0)? 0 : (int)strlen(z); |
| 1020 | +# if CIO_WIN_WC_XLATE |
| 1021 | + } |
| 1022 | +# endif |
| 1023 | +} |
| 1024 | + |
| 1025 | +SQLITE_INTERNAL_LINKAGE int ePutsUtf8(const char *z){ |
| 1026 | + FILE *pfErr; |
| 1027 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 1028 | +# if CIO_WIN_WC_XLATE |
| 1029 | + PerStreamTags *ppst = getEmitStreamInfo(2, &pst, &pfErr); |
| 1030 | +# else |
| 1031 | + getEmitStreamInfo(2, &pst, &pfErr); |
| 1032 | +# endif |
| 1033 | + assert(z!=0); |
| 1034 | +# if CIO_WIN_WC_XLATE |
| 1035 | + if( pstReachesConsole(ppst) ) return conZstrEmit(ppst, z, (int)strlen(z)); |
| 1036 | + else { |
| 1037 | +# endif |
| 1038 | + return (fputs(z, pfErr)<0)? 0 : (int)strlen(z); |
| 1039 | +# if CIO_WIN_WC_XLATE |
| 1040 | + } |
| 1041 | +# endif |
| 1042 | +} |
| 1043 | + |
| 1044 | +SQLITE_INTERNAL_LINKAGE int oPutsUtf8(const char *z){ |
| 1045 | + FILE *pfOut; |
| 1046 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 1047 | +# if CIO_WIN_WC_XLATE |
| 1048 | + PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut); |
| 1049 | +# else |
| 1050 | + getEmitStreamInfo(1, &pst, &pfOut); |
| 1051 | +# endif |
| 1052 | + assert(z!=0); |
| 1053 | +# if CIO_WIN_WC_XLATE |
| 1054 | + if( pstReachesConsole(ppst) ) return conZstrEmit(ppst, z, (int)strlen(z)); |
| 1055 | + else { |
| 1056 | +# endif |
| 1057 | + return (fputs(z, pfOut)<0)? 0 : (int)strlen(z); |
| 1058 | +# if CIO_WIN_WC_XLATE |
| 1059 | + } |
| 1060 | +# endif |
| 1061 | +} |
| 1062 | + |
| 1063 | +#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */ |
| 1064 | + |
| 1065 | +#if !(defined(SQLITE_CIO_NO_UTF8SCAN) && defined(SQLITE_CIO_NO_TRANSLATE)) |
| 1066 | +/* Skip over as much z[] input char sequence as is valid UTF-8, |
| 1067 | +** limited per nAccept char's or whole characters and containing |
| 1068 | +** no char cn such that ((1<<cn) & ccm)!=0. On return, the |
| 1069 | +** sequence z:return (inclusive:exclusive) is validated UTF-8. |
| 1070 | +** Limit: nAccept>=0 => char count, nAccept<0 => character |
| 1071 | + */ |
| 1072 | +SQLITE_INTERNAL_LINKAGE const char* |
| 1073 | +zSkipValidUtf8(const char *z, int nAccept, long ccm){ |
| 1074 | + int ng = (nAccept<0)? -nAccept : 0; |
| 1075 | + const char *pcLimit = (nAccept>=0)? z+nAccept : 0; |
| 1076 | + assert(z!=0); |
| 1077 | + while( (pcLimit)? (z<pcLimit) : (ng-- != 0) ){ |
| 1078 | + char c = *z; |
| 1079 | + if( (c & 0x80) == 0 ){ |
| 1080 | + if( ccm != 0L && c < 0x20 && ((1L<<c) & ccm) != 0 ) return z; |
| 1081 | + ++z; /* ASCII */ |
| 1082 | + }else if( (c & 0xC0) != 0xC0 ) return z; /* not a lead byte */ |
| 1083 | + else{ |
| 1084 | + const char *zt = z+1; /* Got lead byte, look at trail bytes.*/ |
| 1085 | + do{ |
| 1086 | + if( pcLimit && zt >= pcLimit ) return z; |
| 1087 | + else{ |
| 1088 | + char ct = *zt++; |
| 1089 | + if( ct==0 || (zt-z)>4 || (ct & 0xC0)!=0x80 ){ |
| 1090 | + /* Trailing bytes are too few, too many, or invalid. */ |
| 1091 | + return z; |
| 1092 | + } |
| 1093 | + } |
| 1094 | + } while( ((c <<= 1) & 0x40) == 0x40 ); /* Eat lead byte's count. */ |
| 1095 | + z = zt; |
| 1096 | + } |
| 1097 | + } |
| 1098 | + return z; |
| 1099 | +} |
| 1100 | +#endif /*!(defined(SQLITE_CIO_NO_UTF8SCAN)&&defined(SQLITE_CIO_NO_TRANSLATE))*/ |
| 1101 | + |
| 1102 | +#ifndef SQLITE_CIO_NO_TRANSLATE |
| 1103 | + |
| 1104 | +#ifdef CONSIO_SPUTB |
| 1105 | +SQLITE_INTERNAL_LINKAGE int |
| 1106 | +fPutbUtf8(FILE *pfO, const char *cBuf, int nAccept){ |
| 1107 | + assert(pfO!=0); |
| 1108 | +# if CIO_WIN_WC_XLATE |
| 1109 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 1110 | + PerStreamTags *ppst = getEmitStreamInfo(0, &pst, &pfO); |
| 1111 | + if( pstReachesConsole(ppst) ){ |
| 1112 | + int rv; |
| 1113 | + maybeSetupAsConsole(ppst, 1); |
| 1114 | + rv = conZstrEmit(ppst, cBuf, nAccept); |
| 1115 | + if( 0 == isKnownWritable(ppst->pf) ) restoreConsoleArb(ppst); |
| 1116 | + return rv; |
| 1117 | + }else { |
| 1118 | +# endif |
| 1119 | + return (int)fwrite(cBuf, 1, nAccept, pfO); |
| 1120 | +# if CIO_WIN_WC_XLATE |
| 1121 | + } |
| 1122 | +# endif |
| 1123 | +} |
| 1124 | +#endif /* defined(CONSIO_SPUTB) */ |
| 1125 | + |
| 1126 | +SQLITE_INTERNAL_LINKAGE int |
| 1127 | +oPutbUtf8(const char *cBuf, int nAccept){ |
| 1128 | + FILE *pfOut; |
| 1129 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 1130 | +# if CIO_WIN_WC_XLATE |
| 1131 | + PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut); |
| 1132 | +# else |
| 1133 | + getEmitStreamInfo(1, &pst, &pfOut); |
| 1134 | +# endif |
| 1135 | +# if CIO_WIN_WC_XLATE |
| 1136 | + if( pstReachesConsole(ppst) ){ |
| 1137 | + return conZstrEmit(ppst, cBuf, nAccept); |
| 1138 | + }else { |
| 1139 | +# endif |
| 1140 | + return (int)fwrite(cBuf, 1, nAccept, pfOut); |
| 1141 | +# if CIO_WIN_WC_XLATE |
| 1142 | + } |
| 1143 | +# endif |
| 1144 | +} |
| 1145 | + |
| 1146 | +# ifdef CONSIO_EPUTB |
| 1147 | +SQLITE_INTERNAL_LINKAGE int |
| 1148 | +ePutbUtf8(const char *cBuf, int nAccept){ |
| 1149 | + FILE *pfErr; |
| 1150 | + PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */ |
| 1151 | + PerStreamTags *ppst = getEmitStreamInfo(2, &pst, &pfErr); |
| 1152 | +# if CIO_WIN_WC_XLATE |
| 1153 | + if( pstReachesConsole(ppst) ){ |
| 1154 | + return conZstrEmit(ppst, cBuf, nAccept); |
| 1155 | + }else { |
| 1156 | +# endif |
| 1157 | + return (int)fwrite(cBuf, 1, nAccept, pfErr); |
| 1158 | +# if CIO_WIN_WC_XLATE |
| 1159 | + } |
| 1160 | +# endif |
| 1161 | +} |
| 1162 | +# endif /* defined(CONSIO_EPUTB) */ |
| 1163 | + |
| 1164 | +SQLITE_INTERNAL_LINKAGE char* fGetsUtf8(char *cBuf, int ncMax, FILE *pfIn){ |
| 1165 | + if( pfIn==0 ) pfIn = stdin; |
| 1166 | +# if CIO_WIN_WC_XLATE |
| 1167 | + if( pfIn == consoleInfo.pstSetup[0].pf |
| 1168 | + && (consoleInfo.sacSetup & SAC_InConsole)!=0 ){ |
| 1169 | +# if CIO_WIN_WC_XLATE==1 |
| 1170 | +# define SHELL_GULP 150 /* Count of WCHARS to be gulped at a time */ |
| 1171 | + WCHAR wcBuf[SHELL_GULP+1]; |
| 1172 | + int lend = 0, noc = 0; |
| 1173 | + if( ncMax > 0 ) cBuf[0] = 0; |
| 1174 | + while( noc < ncMax-8-1 && !lend ){ |
| 1175 | + /* There is room for at least 2 more characters and a 0-terminator. */ |
| 1176 | + int na = (ncMax > SHELL_GULP*4+1 + noc)? SHELL_GULP : (ncMax-1 - noc)/4; |
| 1177 | +# undef SHELL_GULP |
| 1178 | + DWORD nbr = 0; |
| 1179 | + BOOL bRC = ReadConsoleW(consoleInfo.pstSetup[0].hx, wcBuf, na, &nbr, 0); |
| 1180 | + if( bRC && nbr>0 && (wcBuf[nbr-1]&0xF800)==0xD800 ){ |
| 1181 | + /* Last WHAR read is first of a UTF-16 surrogate pair. Grab its mate. */ |
| 1182 | + DWORD nbrx; |
| 1183 | + bRC &= ReadConsoleW(consoleInfo.pstSetup[0].hx, wcBuf+nbr, 1, &nbrx, 0); |
| 1184 | + if( bRC ) nbr += nbrx; |
| 1185 | + } |
| 1186 | + if( !bRC || (noc==0 && nbr==0) ) return 0; |
| 1187 | + if( nbr > 0 ){ |
| 1188 | + int nmb = WideCharToMultiByte(CP_UTF8, 0, wcBuf,nbr,0,0,0,0); |
| 1189 | + if( nmb != 0 && noc+nmb <= ncMax ){ |
| 1190 | + int iseg = noc; |
| 1191 | + nmb = WideCharToMultiByte(CP_UTF8, 0, wcBuf,nbr,cBuf+noc,nmb,0,0); |
| 1192 | + noc += nmb; |
| 1193 | + /* Fixup line-ends as coded by Windows for CR (or "Enter".) |
| 1194 | + ** This is done without regard for any setMode{Text,Binary}() |
| 1195 | + ** call that might have been done on the interactive input. |
| 1196 | + */ |
| 1197 | + if( noc > 0 ){ |
| 1198 | + if( cBuf[noc-1]=='\n' ){ |
| 1199 | + lend = 1; |
| 1200 | + if( noc > 1 && cBuf[noc-2]=='\r' ) cBuf[--noc-1] = '\n'; |
| 1201 | + } |
| 1202 | + } |
| 1203 | + /* Check for ^Z (anywhere in line) too, to act as EOF. */ |
| 1204 | + while( iseg < noc ){ |
| 1205 | + if( cBuf[iseg]=='\x1a' ){ |
| 1206 | + noc = iseg; /* Chop ^Z and anything following. */ |
| 1207 | + lend = 1; /* Counts as end of line too. */ |
| 1208 | + break; |
| 1209 | + } |
| 1210 | + ++iseg; |
| 1211 | + } |
| 1212 | + }else break; /* Drop apparent garbage in. (Could assert.) */ |
| 1213 | + }else break; |
| 1214 | + } |
| 1215 | + /* If got nothing, (after ^Z chop), must be at end-of-file. */ |
| 1216 | + if( noc > 0 ){ |
| 1217 | + cBuf[noc] = 0; |
| 1218 | + return cBuf; |
| 1219 | + }else return 0; |
| 1220 | +# endif |
| 1221 | + }else{ |
| 1222 | +# endif |
| 1223 | + return fgets(cBuf, ncMax, pfIn); |
| 1224 | +# if CIO_WIN_WC_XLATE |
| 1225 | + } |
| 1226 | +# endif |
| 1227 | +} |
| 1228 | +#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */ |
| 1229 | + |
| 1230 | +#undef SHELL_INVALID_FILE_PTR |
| 1231 | + |
| 1232 | +/************************* End ../ext/consio/console_io.c ********************/ |
| 1233 | + |
| 1234 | +#ifndef SQLITE_SHELL_FIDDLE |
| 1235 | +/* From here onward, fgets() is redirected to the console_io library. */ |
| 1236 | +# define fgets(b,n,f) fGetsUtf8(b,n,f) |
| 1237 | +/* |
| 1238 | + * Define macros for emitting output text in various ways: |
| 1239 | + * sputz(s, z) => emit 0-terminated string z to given stream s |
| 1240 | + * sputf(s, f, ...) => emit varargs per format f to given stream s |
| 1241 | + * oputz(z) => emit 0-terminated string z to default stream |
| 1242 | + * oputf(f, ...) => emit varargs per format f to default stream |
| 1243 | + * eputz(z) => emit 0-terminated string z to error stream |
| 1244 | + * eputf(f, ...) => emit varargs per format f to error stream |
| 1245 | + * oputb(b, n) => emit char buffer b[0..n-1] to default stream |
| 1246 | + * |
| 1247 | + * Note that the default stream is whatever has been last set via: |
| 1248 | + * setOutputStream(FILE *pf) |
| 1249 | + * This is normally the stream that CLI normal output goes to. |
| 1250 | + * For the stand-alone CLI, it is stdout with no .output redirect. |
| 1251 | + */ |
| 1252 | +# define sputz(s,z) fPutsUtf8(z,s) |
| 1253 | +# define sputf fPrintfUtf8 |
| 1254 | +# define oputz(z) oPutsUtf8(z) |
| 1255 | +# define oputf oPrintfUtf8 |
| 1256 | +# define eputz(z) ePutsUtf8(z) |
| 1257 | +# define eputf ePrintfUtf8 |
| 1258 | +# define oputb(buf,na) oPutbUtf8(buf,na) |
| 275 | 1259 | #else |
| 276 | | -# define setBinaryMode(X,Y) |
| 277 | | -# define setTextMode(X,Y) |
| 1260 | +/* For Fiddle, all console handling and emit redirection is omitted. */ |
| 1261 | +# define sputz(fp,z) fputs(z,fp) |
| 1262 | +# define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__) |
| 1263 | +# define oputz(z) fputs(z,stdout) |
| 1264 | +# define oputf(fmt, ...) printf(fmt,__VA_ARGS__) |
| 1265 | +# define eputz(z) fputs(z,stderr) |
| 1266 | +# define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__) |
| 1267 | +# define oputb(buf,na) fwrite(buf,1,na,stdout) |
| 278 | 1268 | #endif |
| 279 | 1269 | |
| 280 | 1270 | /* True if the timer is enabled */ |
| 281 | 1271 | static int enableTimer = 0; |
| 282 | 1272 | |
| | @@ -347,14 +1337,14 @@ |
| 347 | 1337 | static void endTimer(void){ |
| 348 | 1338 | if( enableTimer ){ |
| 349 | 1339 | sqlite3_int64 iEnd = timeOfDay(); |
| 350 | 1340 | struct rusage sEnd; |
| 351 | 1341 | getrusage(RUSAGE_SELF, &sEnd); |
| 352 | | - printf("Run Time: real %.3f user %f sys %f\n", |
| 353 | | - (iEnd - iBegin)*0.001, |
| 354 | | - timeDiff(&sBegin.ru_utime, &sEnd.ru_utime), |
| 355 | | - timeDiff(&sBegin.ru_stime, &sEnd.ru_stime)); |
| 1342 | + oputf("Run Time: real %.3f user %f sys %f\n", |
| 1343 | + (iEnd - iBegin)*0.001, |
| 1344 | + timeDiff(&sBegin.ru_utime, &sEnd.ru_utime), |
| 1345 | + timeDiff(&sBegin.ru_stime, &sEnd.ru_stime)); |
| 356 | 1346 | } |
| 357 | 1347 | } |
| 358 | 1348 | |
| 359 | 1349 | #define BEGIN_TIMER beginTimer() |
| 360 | 1350 | #define END_TIMER endTimer() |
| | @@ -426,14 +1416,14 @@ |
| 426 | 1416 | static void endTimer(void){ |
| 427 | 1417 | if( enableTimer && getProcessTimesAddr){ |
| 428 | 1418 | FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd; |
| 429 | 1419 | sqlite3_int64 ftWallEnd = timeOfDay(); |
| 430 | 1420 | getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd); |
| 431 | | - printf("Run Time: real %.3f user %f sys %f\n", |
| 432 | | - (ftWallEnd - ftWallBegin)*0.001, |
| 433 | | - timeDiff(&ftUserBegin, &ftUserEnd), |
| 434 | | - timeDiff(&ftKernelBegin, &ftKernelEnd)); |
| 1421 | + oputf("Run Time: real %.3f user %f sys %f\n", |
| 1422 | + (ftWallEnd - ftWallBegin)*0.001, |
| 1423 | + timeDiff(&ftUserBegin, &ftUserEnd), |
| 1424 | + timeDiff(&ftKernelBegin, &ftKernelEnd)); |
| 435 | 1425 | } |
| 436 | 1426 | } |
| 437 | 1427 | |
| 438 | 1428 | #define BEGIN_TIMER beginTimer() |
| 439 | 1429 | #define END_TIMER endTimer() |
| | @@ -466,32 +1456,13 @@ |
| 466 | 1456 | ** is true. Otherwise, assume stdin is connected to a file or pipe. |
| 467 | 1457 | */ |
| 468 | 1458 | static int stdin_is_interactive = 1; |
| 469 | 1459 | |
| 470 | 1460 | /* |
| 471 | | -** If build is for non-RT Windows, without 3rd-party line editing, |
| 472 | | -** console input and output may be done in a UTF-8 compatible way, |
| 473 | | -** if the OS is capable of it and the --no-utf8 option is not seen. |
| 474 | | -*/ |
| 475 | | -#if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE \ |
| 476 | | - && !defined(SHELL_OMIT_WIN_UTF8) && !SQLITE_OS_WINRT |
| 477 | | -# define SHELL_WIN_UTF8_OPT 1 |
| 478 | | -/* Record whether to do UTF-8 console I/O translation per stream. */ |
| 479 | | - static int console_utf8_in = 0; |
| 480 | | - static int console_utf8_out = 0; |
| 481 | | -/* Record whether can do UTF-8 or --no-utf8 seen in invocation. */ |
| 482 | | - static int mbcs_opted = 1; /* Assume cannot do until shown otherwise. */ |
| 483 | | -#else |
| 484 | | -# define console_utf8_in 0 |
| 485 | | -# define console_utf8_out 0 |
| 486 | | -# define SHELL_WIN_UTF8_OPT 0 |
| 487 | | -#endif |
| 488 | | - |
| 489 | | -/* |
| 490 | | -** On Windows systems we have to know if standard output is a console |
| 491 | | -** in order to translate UTF-8 into MBCS. The following variable is |
| 492 | | -** true if translation is required. |
| 1461 | +** On Windows systems we need to know if standard output is a console |
| 1462 | +** in order to show that UTF-16 translation is done in the sign-on |
| 1463 | +** banner. The following variable is true if it is the console. |
| 493 | 1464 | */ |
| 494 | 1465 | static int stdout_is_console = 1; |
| 495 | 1466 | |
| 496 | 1467 | /* |
| 497 | 1468 | ** The following is the open SQLite database. We make a pointer |
| | @@ -609,255 +1580,21 @@ |
| 609 | 1580 | shell_strncpy(dynPrompt.dynamicPrompt, ")x!", 4); |
| 610 | 1581 | }else{ |
| 611 | 1582 | shell_strncpy(dynPrompt.dynamicPrompt, "(x.", 4); |
| 612 | 1583 | dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel); |
| 613 | 1584 | } |
| 614 | | - shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4); |
| 1585 | + shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, |
| 1586 | + PROMPT_LEN_MAX-4); |
| 615 | 1587 | } |
| 616 | 1588 | } |
| 617 | 1589 | return dynPrompt.dynamicPrompt; |
| 618 | 1590 | } |
| 619 | 1591 | #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */ |
| 620 | 1592 | |
| 621 | | -#if SHELL_WIN_UTF8_OPT |
| 622 | | -/* Following struct is used for UTF-8 console I/O. */ |
| 623 | | -static struct ConsoleState { |
| 624 | | - int stdinEof; /* EOF has been seen on console input */ |
| 625 | | - int infsMode; /* Input file stream mode upon shell start */ |
| 626 | | - UINT inCodePage; /* Input code page upon shell start */ |
| 627 | | - UINT outCodePage; /* Output code page upon shell start */ |
| 628 | | - HANDLE hConsole; /* Console input or output handle */ |
| 629 | | - DWORD consoleMode; /* Console mode upon shell start */ |
| 630 | | -} conState = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 }; |
| 631 | | - |
| 632 | | -#ifndef _O_U16TEXT /* For build environments lacking this constant: */ |
| 633 | | -# define _O_U16TEXT 0x20000 |
| 634 | | -#endif |
| 635 | | - |
| 636 | | -/* |
| 637 | | -** If given stream number is a console, return 1 and get some attributes, |
| 638 | | -** else return 0 and set the output attributes to invalid values. |
| 639 | | -*/ |
| 640 | | -static short console_attrs(unsigned stnum, HANDLE *pH, DWORD *pConsMode){ |
| 641 | | - static int stid[3] = { STD_INPUT_HANDLE,STD_OUTPUT_HANDLE,STD_ERROR_HANDLE }; |
| 642 | | - HANDLE h; |
| 643 | | - *pH = INVALID_HANDLE_VALUE; |
| 644 | | - *pConsMode = 0; |
| 645 | | - if( stnum > 2 ) return 0; |
| 646 | | - h = GetStdHandle(stid[stnum]); |
| 647 | | - if( h!=*pH && GetFileType(h)==FILE_TYPE_CHAR && GetConsoleMode(h,pConsMode) ){ |
| 648 | | - *pH = h; |
| 649 | | - return 1; |
| 650 | | - } |
| 651 | | - return 0; |
| 652 | | -} |
| 653 | | - |
| 654 | | -/* |
| 655 | | -** Perform a runtime test of Windows console to determine if it can |
| 656 | | -** do char-stream I/O correctly when the code page is set to CP_UTF8. |
| 657 | | -** Returns are: 1 => yes it can, 0 => no it cannot |
| 658 | | -** |
| 659 | | -** The console's output code page is momentarily set, then restored. |
| 660 | | -** So this should only be run when the process is given use of the |
| 661 | | -** console for either input or output. |
| 662 | | -*/ |
| 663 | | -static short ConsoleDoesUTF8(void){ |
| 664 | | - UINT ocp = GetConsoleOutputCP(); |
| 665 | | - const char TrialUtf8[] = { '\xC8', '\xAB' }; /* "ȫ" or 2 MBCS characters */ |
| 666 | | - WCHAR aReadBack[1] = { 0 }; /* Read back as 0x022B when decoded as UTF-8. */ |
| 667 | | - CONSOLE_SCREEN_BUFFER_INFO csbInfo = {0}; |
| 668 | | - /* Create an inactive screen buffer with which to do the experiment. */ |
| 669 | | - HANDLE hCSB = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE, 0, 0, |
| 670 | | - CONSOLE_TEXTMODE_BUFFER, NULL); |
| 671 | | - if( hCSB!=INVALID_HANDLE_VALUE ){ |
| 672 | | - COORD cpos = {0,0}; |
| 673 | | - DWORD rbc; |
| 674 | | - SetConsoleCursorPosition(hCSB, cpos); |
| 675 | | - SetConsoleOutputCP(CP_UTF8); |
| 676 | | - /* Write 2 chars which are a single character in UTF-8 but more in MBCS. */ |
| 677 | | - WriteConsoleA(hCSB, TrialUtf8, sizeof(TrialUtf8), NULL, NULL); |
| 678 | | - ReadConsoleOutputCharacterW(hCSB, &aReadBack[0], 1, cpos, &rbc); |
| 679 | | - GetConsoleScreenBufferInfo(hCSB, &csbInfo); |
| 680 | | - SetConsoleOutputCP(ocp); |
| 681 | | - CloseHandle(hCSB); |
| 682 | | - } |
| 683 | | - /* Return 1 if cursor advanced by 1 position, else 0. */ |
| 684 | | - return (short)(csbInfo.dwCursorPosition.X == 1 && aReadBack[0] == 0x022B); |
| 685 | | -} |
| 686 | | - |
| 687 | | -static short in_console = 0; |
| 688 | | -static short out_console = 0; |
| 689 | | - |
| 690 | | -/* |
| 691 | | -** Determine whether either normal I/O stream is the console, |
| 692 | | -** and whether it can do UTF-8 translation, setting globals |
| 693 | | -** in_console, out_console and mbcs_opted accordingly. |
| 694 | | -*/ |
| 695 | | -static void probe_console(void){ |
| 696 | | - HANDLE h; |
| 697 | | - DWORD cMode; |
| 698 | | - in_console = console_attrs(0, &h, &cMode); |
| 699 | | - out_console = console_attrs(1, &h, &cMode); |
| 700 | | - if( in_console || out_console ) mbcs_opted = !ConsoleDoesUTF8(); |
| 701 | | -} |
| 702 | | - |
| 703 | | -/* |
| 704 | | -** If console is used for normal I/O, absent a --no-utf8 option, |
| 705 | | -** prepare console for UTF-8 input (from either typing or suitable |
| 706 | | -** paste operations) and/or for UTF-8 output rendering. |
| 707 | | -** |
| 708 | | -** The console state upon entry is preserved, in conState, so that |
| 709 | | -** console_restore() can later restore the same console state. |
| 710 | | -** |
| 711 | | -** The globals console_utf8_in and console_utf8_out are set, for |
| 712 | | -** later use in selecting UTF-8 or MBCS console I/O translations. |
| 713 | | -** This routine depends upon globals set by probe_console(). |
| 714 | | -*/ |
| 715 | | -static void console_prepare_utf8(void){ |
| 716 | | - struct ConsoleState csWork = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 }; |
| 717 | | - |
| 718 | | - console_utf8_in = console_utf8_out = 0; |
| 719 | | - if( (!in_console && !out_console) || mbcs_opted ) return; |
| 720 | | - console_attrs((in_console)? 0 : 1, &conState.hConsole, &conState.consoleMode); |
| 721 | | - conState.inCodePage = GetConsoleCP(); |
| 722 | | - conState.outCodePage = GetConsoleOutputCP(); |
| 723 | | - if( in_console ){ |
| 724 | | - SetConsoleCP(CP_UTF8); |
| 725 | | - DWORD newConsoleMode = conState.consoleMode |
| 726 | | - | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT; |
| 727 | | - SetConsoleMode(conState.hConsole, newConsoleMode); |
| 728 | | - conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT); |
| 729 | | - console_utf8_in = 1; |
| 730 | | - } |
| 731 | | - if( out_console ){ |
| 732 | | - SetConsoleOutputCP(CP_UTF8); |
| 733 | | - console_utf8_out = 1; |
| 734 | | - } |
| 735 | | -} |
| 736 | | - |
| 737 | | -/* |
| 738 | | -** Undo the effects of console_prepare_utf8(), if any. |
| 739 | | -*/ |
| 740 | | -static void SQLITE_CDECL console_restore(void){ |
| 741 | | - if( (console_utf8_in||console_utf8_out) |
| 742 | | - && conState.hConsole!=INVALID_HANDLE_VALUE ){ |
| 743 | | - if( console_utf8_in ){ |
| 744 | | - SetConsoleCP(conState.inCodePage); |
| 745 | | - _setmode(_fileno(stdin), conState.infsMode); |
| 746 | | - } |
| 747 | | - if( console_utf8_out ) SetConsoleOutputCP(conState.outCodePage); |
| 748 | | - SetConsoleMode(conState.hConsole, conState.consoleMode); |
| 749 | | - /* Avoid multiple calls. */ |
| 750 | | - conState.hConsole = INVALID_HANDLE_VALUE; |
| 751 | | - conState.consoleMode = 0; |
| 752 | | - console_utf8_in = 0; |
| 753 | | - console_utf8_out = 0; |
| 754 | | - } |
| 755 | | -} |
| 756 | | - |
| 757 | | -/* |
| 758 | | -** Collect input like fgets(...) with special provisions for input |
| 759 | | -** from the Windows console to get around its strange coding issues. |
| 760 | | -** Defers to plain fgets() when input is not interactive or when the |
| 761 | | -** UTF-8 input is unavailable or opted out. |
| 762 | | -*/ |
| 763 | | -static char* utf8_fgets(char *buf, int ncmax, FILE *fin){ |
| 764 | | - if( fin==0 ) fin = stdin; |
| 765 | | - if( fin==stdin && stdin_is_interactive && console_utf8_in ){ |
| 766 | | -# define SQLITE_IALIM 150 |
| 767 | | - wchar_t wbuf[SQLITE_IALIM]; |
| 768 | | - int lend = 0; |
| 769 | | - int noc = 0; |
| 770 | | - if( ncmax==0 || conState.stdinEof ) return 0; |
| 771 | | - buf[0] = 0; |
| 772 | | - while( noc<ncmax-7-1 && !lend ){ |
| 773 | | - /* There is room for at least 2 more characters and a 0-terminator. */ |
| 774 | | - int na = (ncmax > SQLITE_IALIM*4+1 + noc) |
| 775 | | - ? SQLITE_IALIM : (ncmax-1 - noc)/4; |
| 776 | | -# undef SQLITE_IALIM |
| 777 | | - DWORD nbr = 0; |
| 778 | | - BOOL bRC = ReadConsoleW(conState.hConsole, wbuf, na, &nbr, 0); |
| 779 | | - if( !bRC || (noc==0 && nbr==0) ) return 0; |
| 780 | | - if( nbr > 0 ){ |
| 781 | | - int nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR, |
| 782 | | - wbuf,nbr,0,0,0,0); |
| 783 | | - if( nmb !=0 && noc+nmb <= ncmax ){ |
| 784 | | - int iseg = noc; |
| 785 | | - nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR, |
| 786 | | - wbuf,nbr,buf+noc,nmb,0,0); |
| 787 | | - noc += nmb; |
| 788 | | - /* Fixup line-ends as coded by Windows for CR (or "Enter".)*/ |
| 789 | | - if( noc > 0 ){ |
| 790 | | - if( buf[noc-1]=='\n' ){ |
| 791 | | - lend = 1; |
| 792 | | - if( noc > 1 && buf[noc-2]=='\r' ){ |
| 793 | | - buf[noc-2] = '\n'; |
| 794 | | - --noc; |
| 795 | | - } |
| 796 | | - } |
| 797 | | - } |
| 798 | | - /* Check for ^Z (anywhere in line) too. */ |
| 799 | | - while( iseg < noc ){ |
| 800 | | - if( buf[iseg]==0x1a ){ |
| 801 | | - conState.stdinEof = 1; |
| 802 | | - noc = iseg; /* Chop ^Z and anything following. */ |
| 803 | | - break; |
| 804 | | - } |
| 805 | | - ++iseg; |
| 806 | | - } |
| 807 | | - }else break; /* Drop apparent garbage in. (Could assert.) */ |
| 808 | | - }else break; |
| 809 | | - } |
| 810 | | - /* If got nothing, (after ^Z chop), must be at end-of-file. */ |
| 811 | | - if( noc == 0 ) return 0; |
| 812 | | - buf[noc] = 0; |
| 813 | | - return buf; |
| 814 | | - }else{ |
| 815 | | - return fgets(buf, ncmax, fin); |
| 816 | | - } |
| 817 | | -} |
| 818 | | - |
| 819 | | -# define fgets(b,n,f) utf8_fgets(b,n,f) |
| 820 | | -#endif /* SHELL_WIN_UTF8_OPT */ |
| 821 | | - |
| 822 | | -/* |
| 823 | | -** Render output like fprintf(). Except, if the output is going to the |
| 824 | | -** console and if this is running on a Windows machine, and if UTF-8 |
| 825 | | -** output unavailable (or available but opted out), translate the |
| 826 | | -** output from UTF-8 into MBCS for output through 8-bit stdout stream. |
| 827 | | -** (Without -no-utf8, no translation is needed and must not be done.) |
| 828 | | -*/ |
| 829 | | -#if defined(_WIN32) || defined(WIN32) |
| 830 | | -void utf8_printf(FILE *out, const char *zFormat, ...){ |
| 831 | | - va_list ap; |
| 832 | | - va_start(ap, zFormat); |
| 833 | | - if( stdout_is_console && (out==stdout || out==stderr) && !console_utf8_out ){ |
| 834 | | - char *z1 = sqlite3_vmprintf(zFormat, ap); |
| 835 | | - char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0); |
| 836 | | - sqlite3_free(z1); |
| 837 | | - fputs(z2, out); |
| 838 | | - sqlite3_free(z2); |
| 839 | | - }else{ |
| 840 | | - vfprintf(out, zFormat, ap); |
| 841 | | - } |
| 842 | | - va_end(ap); |
| 843 | | -} |
| 844 | | -#elif !defined(utf8_printf) |
| 845 | | -# define utf8_printf fprintf |
| 846 | | -#endif |
| 847 | | - |
| 848 | | -/* |
| 849 | | -** Render output like fprintf(). This should not be used on anything that |
| 850 | | -** includes string formatting (e.g. "%s"). |
| 851 | | -*/ |
| 852 | | -#if !defined(raw_printf) |
| 853 | | -# define raw_printf fprintf |
| 854 | | -#endif |
| 855 | | - |
| 856 | 1593 | /* Indicate out-of-memory and exit. */ |
| 857 | 1594 | static void shell_out_of_memory(void){ |
| 858 | | - raw_printf(stderr,"Error: out of memory\n"); |
| 1595 | + eputz("Error: out of memory\n"); |
| 859 | 1596 | exit(1); |
| 860 | 1597 | } |
| 861 | 1598 | |
| 862 | 1599 | /* Check a pointer to see if it is NULL. If it is NULL, exit with an |
| 863 | 1600 | ** out-of-memory error. |
| | @@ -885,22 +1622,22 @@ |
| 885 | 1622 | char *z; |
| 886 | 1623 | if( iotrace==0 ) return; |
| 887 | 1624 | va_start(ap, zFormat); |
| 888 | 1625 | z = sqlite3_vmprintf(zFormat, ap); |
| 889 | 1626 | va_end(ap); |
| 890 | | - utf8_printf(iotrace, "%s", z); |
| 1627 | + sputf(iotrace, "%s", z); |
| 891 | 1628 | sqlite3_free(z); |
| 892 | 1629 | } |
| 893 | 1630 | #endif |
| 894 | 1631 | |
| 895 | 1632 | /* |
| 896 | | -** Output string zUtf to stream pOut as w characters. If w is negative, |
| 1633 | +** Output string zUtf to Out stream as w characters. If w is negative, |
| 897 | 1634 | ** then right-justify the text. W is the width in UTF-8 characters, not |
| 898 | 1635 | ** in bytes. This is different from the %*.*s specification in printf |
| 899 | 1636 | ** since with %*.*s the width is measured in bytes, not characters. |
| 900 | 1637 | */ |
| 901 | | -static void utf8_width_print(FILE *pOut, int w, const char *zUtf){ |
| 1638 | +static void utf8_width_print(int w, const char *zUtf){ |
| 902 | 1639 | int i; |
| 903 | 1640 | int n; |
| 904 | 1641 | int aw = w<0 ? -w : w; |
| 905 | 1642 | if( zUtf==0 ) zUtf = ""; |
| 906 | 1643 | for(i=n=0; zUtf[i]; i++){ |
| | @@ -911,15 +1648,15 @@ |
| 911 | 1648 | break; |
| 912 | 1649 | } |
| 913 | 1650 | } |
| 914 | 1651 | } |
| 915 | 1652 | if( n>=aw ){ |
| 916 | | - utf8_printf(pOut, "%.*s", i, zUtf); |
| 1653 | + oputf("%.*s", i, zUtf); |
| 917 | 1654 | }else if( w<0 ){ |
| 918 | | - utf8_printf(pOut, "%*s%s", aw-n, "", zUtf); |
| 1655 | + oputf("%*s%s", aw-n, "", zUtf); |
| 919 | 1656 | }else{ |
| 920 | | - utf8_printf(pOut, "%s%*s", zUtf, aw-n, ""); |
| 1657 | + oputf("%s%*s", zUtf, aw-n, ""); |
| 921 | 1658 | } |
| 922 | 1659 | } |
| 923 | 1660 | |
| 924 | 1661 | |
| 925 | 1662 | /* |
| | @@ -975,11 +1712,11 @@ |
| 975 | 1712 | ** Return open FILE * if zFile exists, can be opened for read |
| 976 | 1713 | ** and is an ordinary file or a character stream source. |
| 977 | 1714 | ** Otherwise return 0. |
| 978 | 1715 | */ |
| 979 | 1716 | static FILE * openChrSource(const char *zFile){ |
| 980 | | -#ifdef _WIN32 |
| 1717 | +#if defined(_WIN32) || defined(WIN32) |
| 981 | 1718 | struct _stat x = {0}; |
| 982 | 1719 | # define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0) |
| 983 | 1720 | /* On Windows, open first, then check the stream nature. This order |
| 984 | 1721 | ** is necessary because _stat() and sibs, when checking a named pipe, |
| 985 | 1722 | ** effectively break the pipe as its supplier sees it. */ |
| | @@ -1038,27 +1775,10 @@ |
| 1038 | 1775 | if( n>0 && zLine[n-1]=='\r' ) n--; |
| 1039 | 1776 | zLine[n] = 0; |
| 1040 | 1777 | break; |
| 1041 | 1778 | } |
| 1042 | 1779 | } |
| 1043 | | -#if defined(_WIN32) || defined(WIN32) |
| 1044 | | - /* For interactive input on Windows systems, with -no-utf8, |
| 1045 | | - ** translate the multi-byte characterset characters into UTF-8. |
| 1046 | | - ** This is the translation that predates console UTF-8 input. */ |
| 1047 | | - if( stdin_is_interactive && in==stdin && !console_utf8_in ){ |
| 1048 | | - char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0); |
| 1049 | | - if( zTrans ){ |
| 1050 | | - i64 nTrans = strlen(zTrans)+1; |
| 1051 | | - if( nTrans>nLine ){ |
| 1052 | | - zLine = realloc(zLine, nTrans); |
| 1053 | | - shell_check_oom(zLine); |
| 1054 | | - } |
| 1055 | | - memcpy(zLine, zTrans, nTrans); |
| 1056 | | - sqlite3_free(zTrans); |
| 1057 | | - } |
| 1058 | | - } |
| 1059 | | -#endif /* defined(_WIN32) || defined(WIN32) */ |
| 1060 | 1780 | return zLine; |
| 1061 | 1781 | } |
| 1062 | 1782 | |
| 1063 | 1783 | /* |
| 1064 | 1784 | ** Retrieve a single line of input text. |
| | @@ -1081,11 +1801,11 @@ |
| 1081 | 1801 | if( in!=0 ){ |
| 1082 | 1802 | zResult = local_getline(zPrior, in); |
| 1083 | 1803 | }else{ |
| 1084 | 1804 | zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt; |
| 1085 | 1805 | #if SHELL_USE_LOCAL_GETLINE |
| 1086 | | - printf("%s", zPrompt); |
| 1806 | + sputz(stdout, zPrompt); |
| 1087 | 1807 | fflush(stdout); |
| 1088 | 1808 | do{ |
| 1089 | 1809 | zResult = local_getline(zPrior, stdin); |
| 1090 | 1810 | zPrior = 0; |
| 1091 | 1811 | /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */ |
| | @@ -1328,11 +2048,11 @@ |
| 1328 | 2048 | double r = sqlite3_value_double(apVal[0]); |
| 1329 | 2049 | int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26; |
| 1330 | 2050 | char z[400]; |
| 1331 | 2051 | if( n<1 ) n = 1; |
| 1332 | 2052 | if( n>350 ) n = 350; |
| 1333 | | - snprintf(z, sizeof(z)-1, "%#+.*e", n, r); |
| 2053 | + sqlite3_snprintf(sizeof(z), z, "%#+.*e", n, r); |
| 1334 | 2054 | sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT); |
| 1335 | 2055 | } |
| 1336 | 2056 | |
| 1337 | 2057 | |
| 1338 | 2058 | /* |
| | @@ -17614,11 +18334,11 @@ |
| 17614 | 18334 | ** A callback for the sqlite3_log() interface. |
| 17615 | 18335 | */ |
| 17616 | 18336 | static void shellLog(void *pArg, int iErrCode, const char *zMsg){ |
| 17617 | 18337 | ShellState *p = (ShellState*)pArg; |
| 17618 | 18338 | if( p->pLog==0 ) return; |
| 17619 | | - utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg); |
| 18339 | + sputf(p->pLog, "(%d) %s\n", iErrCode, zMsg); |
| 17620 | 18340 | fflush(p->pLog); |
| 17621 | 18341 | } |
| 17622 | 18342 | |
| 17623 | 18343 | /* |
| 17624 | 18344 | ** SQL function: shell_putsnl(X) |
| | @@ -17629,13 +18349,13 @@ |
| 17629 | 18349 | static void shellPutsFunc( |
| 17630 | 18350 | sqlite3_context *pCtx, |
| 17631 | 18351 | int nVal, |
| 17632 | 18352 | sqlite3_value **apVal |
| 17633 | 18353 | ){ |
| 17634 | | - ShellState *p = (ShellState*)sqlite3_user_data(pCtx); |
| 18354 | + /* Unused: (ShellState*)sqlite3_user_data(pCtx); */ |
| 17635 | 18355 | (void)nVal; |
| 17636 | | - utf8_printf(p->out, "%s\n", sqlite3_value_text(apVal[0])); |
| 18356 | + oputf("%s\n", sqlite3_value_text(apVal[0])); |
| 17637 | 18357 | sqlite3_result_value(pCtx, apVal[0]); |
| 17638 | 18358 | } |
| 17639 | 18359 | |
| 17640 | 18360 | /* |
| 17641 | 18361 | ** If in safe mode, print an error message described by the arguments |
| | @@ -17650,12 +18370,11 @@ |
| 17650 | 18370 | va_list ap; |
| 17651 | 18371 | char *zMsg; |
| 17652 | 18372 | va_start(ap, zErrMsg); |
| 17653 | 18373 | zMsg = sqlite3_vmprintf(zErrMsg, ap); |
| 17654 | 18374 | va_end(ap); |
| 17655 | | - raw_printf(stderr, "line %d: ", p->lineno); |
| 17656 | | - utf8_printf(stderr, "%s\n", zMsg); |
| 18375 | + eputf("line %d: %s\n", p->lineno, zMsg); |
| 17657 | 18376 | exit(1); |
| 17658 | 18377 | } |
| 17659 | 18378 | } |
| 17660 | 18379 | |
| 17661 | 18380 | /* |
| | @@ -17819,11 +18538,11 @@ |
| 17819 | 18538 | } |
| 17820 | 18539 | |
| 17821 | 18540 | /* |
| 17822 | 18541 | ** Output the given string as a hex-encoded blob (eg. X'1234' ) |
| 17823 | 18542 | */ |
| 17824 | | -static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){ |
| 18543 | +static void output_hex_blob(const void *pBlob, int nBlob){ |
| 17825 | 18544 | int i; |
| 17826 | 18545 | unsigned char *aBlob = (unsigned char*)pBlob; |
| 17827 | 18546 | |
| 17828 | 18547 | char *zStr = sqlite3_malloc(nBlob*2 + 1); |
| 17829 | 18548 | shell_check_oom(zStr); |
| | @@ -17836,11 +18555,11 @@ |
| 17836 | 18555 | zStr[i*2] = aHex[ (aBlob[i] >> 4) ]; |
| 17837 | 18556 | zStr[i*2+1] = aHex[ (aBlob[i] & 0x0F) ]; |
| 17838 | 18557 | } |
| 17839 | 18558 | zStr[i*2] = '\0'; |
| 17840 | 18559 | |
| 17841 | | - raw_printf(out,"X'%s'", zStr); |
| 18560 | + oputf("X'%s'", zStr); |
| 17842 | 18561 | sqlite3_free(zStr); |
| 17843 | 18562 | } |
| 17844 | 18563 | |
| 17845 | 18564 | /* |
| 17846 | 18565 | ** Find a string that is not found anywhere in z[]. Return a pointer |
| | @@ -17866,39 +18585,46 @@ |
| 17866 | 18585 | /* |
| 17867 | 18586 | ** Output the given string as a quoted string using SQL quoting conventions. |
| 17868 | 18587 | ** |
| 17869 | 18588 | ** See also: output_quoted_escaped_string() |
| 17870 | 18589 | */ |
| 17871 | | -static void output_quoted_string(FILE *out, const char *z){ |
| 18590 | +static void output_quoted_string(const char *z){ |
| 17872 | 18591 | int i; |
| 17873 | 18592 | char c; |
| 17874 | | - setBinaryMode(out, 1); |
| 18593 | +#ifndef SQLITE_SHELL_FIDDLE |
| 18594 | + FILE *pfO = setOutputStream(invalidFileStream); |
| 18595 | + setBinaryMode(pfO, 1); |
| 18596 | +#endif |
| 17875 | 18597 | if( z==0 ) return; |
| 17876 | 18598 | for(i=0; (c = z[i])!=0 && c!='\''; i++){} |
| 17877 | 18599 | if( c==0 ){ |
| 17878 | | - utf8_printf(out,"'%s'",z); |
| 18600 | + oputf("'%s'",z); |
| 17879 | 18601 | }else{ |
| 17880 | | - raw_printf(out, "'"); |
| 18602 | + oputz("'"); |
| 17881 | 18603 | while( *z ){ |
| 17882 | 18604 | for(i=0; (c = z[i])!=0 && c!='\''; i++){} |
| 17883 | 18605 | if( c=='\'' ) i++; |
| 17884 | 18606 | if( i ){ |
| 17885 | | - utf8_printf(out, "%.*s", i, z); |
| 18607 | + oputf("%.*s", i, z); |
| 17886 | 18608 | z += i; |
| 17887 | 18609 | } |
| 17888 | 18610 | if( c=='\'' ){ |
| 17889 | | - raw_printf(out, "'"); |
| 18611 | + oputz("'"); |
| 17890 | 18612 | continue; |
| 17891 | 18613 | } |
| 17892 | 18614 | if( c==0 ){ |
| 17893 | 18615 | break; |
| 17894 | 18616 | } |
| 17895 | 18617 | z++; |
| 17896 | 18618 | } |
| 17897 | | - raw_printf(out, "'"); |
| 18619 | + oputz("'"); |
| 17898 | 18620 | } |
| 17899 | | - setTextMode(out, 1); |
| 18621 | +#ifndef SQLITE_SHELL_FIDDLE |
| 18622 | + setTextMode(pfO, 1); |
| 18623 | +#else |
| 18624 | + setTextMode(stdout, 1); |
| 18625 | +#endif |
| 17900 | 18626 | } |
| 17901 | 18627 | |
| 17902 | 18628 | /* |
| 17903 | 18629 | ** Output the given string as a quoted string using SQL quoting conventions. |
| 17904 | 18630 | ** Additionallly , escape the "\n" and "\r" characters so that they do not |
| | @@ -17906,17 +18632,20 @@ |
| 17906 | 18632 | ** systems. |
| 17907 | 18633 | ** |
| 17908 | 18634 | ** This is like output_quoted_string() but with the addition of the \r\n |
| 17909 | 18635 | ** escape mechanism. |
| 17910 | 18636 | */ |
| 17911 | | -static void output_quoted_escaped_string(FILE *out, const char *z){ |
| 18637 | +static void output_quoted_escaped_string(const char *z){ |
| 17912 | 18638 | int i; |
| 17913 | 18639 | char c; |
| 17914 | | - setBinaryMode(out, 1); |
| 18640 | +#ifndef SQLITE_SHELL_FIDDLE |
| 18641 | + FILE *pfO = setOutputStream(invalidFileStream); |
| 18642 | + setBinaryMode(pfO, 1); |
| 18643 | +#endif |
| 17915 | 18644 | for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){} |
| 17916 | 18645 | if( c==0 ){ |
| 17917 | | - utf8_printf(out,"'%s'",z); |
| 18646 | + oputf("'%s'",z); |
| 17918 | 18647 | }else{ |
| 17919 | 18648 | const char *zNL = 0; |
| 17920 | 18649 | const char *zCR = 0; |
| 17921 | 18650 | int nNL = 0; |
| 17922 | 18651 | int nCR = 0; |
| | @@ -17924,121 +18653,167 @@ |
| 17924 | 18653 | for(i=0; z[i]; i++){ |
| 17925 | 18654 | if( z[i]=='\n' ) nNL++; |
| 17926 | 18655 | if( z[i]=='\r' ) nCR++; |
| 17927 | 18656 | } |
| 17928 | 18657 | if( nNL ){ |
| 17929 | | - raw_printf(out, "replace("); |
| 18658 | + oputz("replace("); |
| 17930 | 18659 | zNL = unused_string(z, "\\n", "\\012", zBuf1); |
| 17931 | 18660 | } |
| 17932 | 18661 | if( nCR ){ |
| 17933 | | - raw_printf(out, "replace("); |
| 18662 | + oputz("replace("); |
| 17934 | 18663 | zCR = unused_string(z, "\\r", "\\015", zBuf2); |
| 17935 | 18664 | } |
| 17936 | | - raw_printf(out, "'"); |
| 18665 | + oputz("'"); |
| 17937 | 18666 | while( *z ){ |
| 17938 | 18667 | for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){} |
| 17939 | 18668 | if( c=='\'' ) i++; |
| 17940 | 18669 | if( i ){ |
| 17941 | | - utf8_printf(out, "%.*s", i, z); |
| 18670 | + oputf("%.*s", i, z); |
| 17942 | 18671 | z += i; |
| 17943 | 18672 | } |
| 17944 | 18673 | if( c=='\'' ){ |
| 17945 | | - raw_printf(out, "'"); |
| 18674 | + oputz("'"); |
| 17946 | 18675 | continue; |
| 17947 | 18676 | } |
| 17948 | 18677 | if( c==0 ){ |
| 17949 | 18678 | break; |
| 17950 | 18679 | } |
| 17951 | 18680 | z++; |
| 17952 | 18681 | if( c=='\n' ){ |
| 17953 | | - raw_printf(out, "%s", zNL); |
| 18682 | + oputz(zNL); |
| 17954 | 18683 | continue; |
| 17955 | 18684 | } |
| 17956 | | - raw_printf(out, "%s", zCR); |
| 18685 | + oputz(zCR); |
| 17957 | 18686 | } |
| 17958 | | - raw_printf(out, "'"); |
| 18687 | + oputz("'"); |
| 17959 | 18688 | if( nCR ){ |
| 17960 | | - raw_printf(out, ",'%s',char(13))", zCR); |
| 18689 | + oputf(",'%s',char(13))", zCR); |
| 17961 | 18690 | } |
| 17962 | 18691 | if( nNL ){ |
| 17963 | | - raw_printf(out, ",'%s',char(10))", zNL); |
| 18692 | + oputf(",'%s',char(10))", zNL); |
| 17964 | 18693 | } |
| 17965 | 18694 | } |
| 17966 | | - setTextMode(out, 1); |
| 18695 | +#ifndef SQLITE_SHELL_FIDDLE |
| 18696 | + setTextMode(pfO, 1); |
| 18697 | +#else |
| 18698 | + setTextMode(stdout, 1); |
| 18699 | +#endif |
| 17967 | 18700 | } |
| 17968 | 18701 | |
| 18702 | +/* |
| 18703 | +** Find earliest of chars within s specified in zAny. |
| 18704 | +** With ns == ~0, is like strpbrk(s,zAny) and s must be 0-terminated. |
| 18705 | +*/ |
| 18706 | +static const char *anyOfInStr(const char *s, const char *zAny, size_t ns){ |
| 18707 | + const char *pcFirst = 0; |
| 18708 | + if( ns == ~(size_t)0 ) ns = strlen(s); |
| 18709 | + while(*zAny){ |
| 18710 | + const char *pc = (const char*)memchr(s, *zAny&0xff, ns); |
| 18711 | + if( pc ){ |
| 18712 | + pcFirst = pc; |
| 18713 | + ns = pcFirst - s; |
| 18714 | + } |
| 18715 | + ++zAny; |
| 18716 | + } |
| 18717 | + return pcFirst; |
| 18718 | +} |
| 17969 | 18719 | /* |
| 17970 | 18720 | ** Output the given string as a quoted according to C or TCL quoting rules. |
| 17971 | 18721 | */ |
| 17972 | | -static void output_c_string(FILE *out, const char *z){ |
| 17973 | | - unsigned int c; |
| 17974 | | - fputc('"', out); |
| 17975 | | - while( (c = *(z++))!=0 ){ |
| 17976 | | - if( c=='\\' ){ |
| 17977 | | - fputc(c, out); |
| 17978 | | - fputc(c, out); |
| 17979 | | - }else if( c=='"' ){ |
| 17980 | | - fputc('\\', out); |
| 17981 | | - fputc('"', out); |
| 17982 | | - }else if( c=='\t' ){ |
| 17983 | | - fputc('\\', out); |
| 17984 | | - fputc('t', out); |
| 17985 | | - }else if( c=='\n' ){ |
| 17986 | | - fputc('\\', out); |
| 17987 | | - fputc('n', out); |
| 17988 | | - }else if( c=='\r' ){ |
| 17989 | | - fputc('\\', out); |
| 17990 | | - fputc('r', out); |
| 18722 | +static void output_c_string(const char *z){ |
| 18723 | + char c; |
| 18724 | + static const char *zq = "\""; |
| 18725 | + static long ctrlMask = ~0L; |
| 18726 | + static const char *zDQBSRO = "\"\\\x7f"; /* double-quote, backslash, rubout */ |
| 18727 | + char ace[3] = "\\?"; |
| 18728 | + char cbsSay; |
| 18729 | + oputz(zq); |
| 18730 | + while( *z!=0 ){ |
| 18731 | + const char *pcDQBSRO = anyOfInStr(z, zDQBSRO, ~(size_t)0); |
| 18732 | + const char *pcPast = zSkipValidUtf8(z, INT_MAX, ctrlMask); |
| 18733 | + const char *pcEnd = (pcDQBSRO && pcDQBSRO < pcPast)? pcDQBSRO : pcPast; |
| 18734 | + if( pcEnd > z ) oputb(z, (int)(pcEnd-z)); |
| 18735 | + if( (c = *pcEnd)==0 ) break; |
| 18736 | + ++pcEnd; |
| 18737 | + switch( c ){ |
| 18738 | + case '\\': case '"': |
| 18739 | + cbsSay = (char)c; |
| 18740 | + break; |
| 18741 | + case '\t': cbsSay = 't'; break; |
| 18742 | + case '\n': cbsSay = 'n'; break; |
| 18743 | + case '\r': cbsSay = 'r'; break; |
| 18744 | + case '\f': cbsSay = 'f'; break; |
| 18745 | + default: cbsSay = 0; break; |
| 18746 | + } |
| 18747 | + if( cbsSay ){ |
| 18748 | + ace[1] = cbsSay; |
| 18749 | + oputz(ace); |
| 17991 | 18750 | }else if( !isprint(c&0xff) ){ |
| 17992 | | - raw_printf(out, "\\%03o", c&0xff); |
| 18751 | + oputf("\\%03o", c&0xff); |
| 17993 | 18752 | }else{ |
| 17994 | | - fputc(c, out); |
| 18753 | + ace[1] = (char)c; |
| 18754 | + oputz(ace+1); |
| 17995 | 18755 | } |
| 18756 | + z = pcEnd; |
| 17996 | 18757 | } |
| 17997 | | - fputc('"', out); |
| 18758 | + oputz(zq); |
| 17998 | 18759 | } |
| 17999 | 18760 | |
| 18000 | 18761 | /* |
| 18001 | 18762 | ** Output the given string as a quoted according to JSON quoting rules. |
| 18002 | 18763 | */ |
| 18003 | | -static void output_json_string(FILE *out, const char *z, i64 n){ |
| 18004 | | - unsigned int c; |
| 18764 | +static void output_json_string(const char *z, i64 n){ |
| 18765 | + char c; |
| 18766 | + static const char *zq = "\""; |
| 18767 | + static long ctrlMask = ~0L; |
| 18768 | + static const char *zDQBS = "\"\\"; |
| 18769 | + const char *pcLimit; |
| 18770 | + char ace[3] = "\\?"; |
| 18771 | + char cbsSay; |
| 18772 | + |
| 18005 | 18773 | if( z==0 ) z = ""; |
| 18006 | | - if( n<0 ) n = strlen(z); |
| 18007 | | - fputc('"', out); |
| 18008 | | - while( n-- ){ |
| 18774 | + pcLimit = z + ((n<0)? strlen(z) : (size_t)n); |
| 18775 | + oputz(zq); |
| 18776 | + while( z < pcLimit ){ |
| 18777 | + const char *pcDQBS = anyOfInStr(z, zDQBS, pcLimit-z); |
| 18778 | + const char *pcPast = zSkipValidUtf8(z, (int)(pcLimit-z), ctrlMask); |
| 18779 | + const char *pcEnd = (pcDQBS && pcDQBS < pcPast)? pcDQBS : pcPast; |
| 18780 | + if( pcEnd > z ){ |
| 18781 | + oputb(z, (int)(pcEnd-z)); |
| 18782 | + z = pcEnd; |
| 18783 | + } |
| 18784 | + if( z >= pcLimit ) break; |
| 18009 | 18785 | c = *(z++); |
| 18010 | | - if( c=='\\' || c=='"' ){ |
| 18011 | | - fputc('\\', out); |
| 18012 | | - fputc(c, out); |
| 18786 | + switch( c ){ |
| 18787 | + case '"': case '\\': |
| 18788 | + cbsSay = (char)c; |
| 18789 | + break; |
| 18790 | + case '\b': cbsSay = 'b'; break; |
| 18791 | + case '\f': cbsSay = 'f'; break; |
| 18792 | + case '\n': cbsSay = 'n'; break; |
| 18793 | + case '\r': cbsSay = 'r'; break; |
| 18794 | + case '\t': cbsSay = 't'; break; |
| 18795 | + default: cbsSay = 0; break; |
| 18796 | + } |
| 18797 | + if( cbsSay ){ |
| 18798 | + ace[1] = cbsSay; |
| 18799 | + oputz(ace); |
| 18013 | 18800 | }else if( c<=0x1f ){ |
| 18014 | | - fputc('\\', out); |
| 18015 | | - if( c=='\b' ){ |
| 18016 | | - fputc('b', out); |
| 18017 | | - }else if( c=='\f' ){ |
| 18018 | | - fputc('f', out); |
| 18019 | | - }else if( c=='\n' ){ |
| 18020 | | - fputc('n', out); |
| 18021 | | - }else if( c=='\r' ){ |
| 18022 | | - fputc('r', out); |
| 18023 | | - }else if( c=='\t' ){ |
| 18024 | | - fputc('t', out); |
| 18025 | | - }else{ |
| 18026 | | - raw_printf(out, "u%04x",c); |
| 18027 | | - } |
| 18028 | | - }else{ |
| 18029 | | - fputc(c, out); |
| 18030 | | - } |
| 18031 | | - } |
| 18032 | | - fputc('"', out); |
| 18801 | + oputf("u%04x", c); |
| 18802 | + }else{ |
| 18803 | + ace[1] = (char)c; |
| 18804 | + oputz(ace+1); |
| 18805 | + } |
| 18806 | + } |
| 18807 | + oputz(zq); |
| 18033 | 18808 | } |
| 18034 | 18809 | |
| 18035 | 18810 | /* |
| 18036 | 18811 | ** Output the given string with characters that are special to |
| 18037 | 18812 | ** HTML escaped. |
| 18038 | 18813 | */ |
| 18039 | | -static void output_html_string(FILE *out, const char *z){ |
| 18814 | +static void output_html_string(const char *z){ |
| 18040 | 18815 | int i; |
| 18041 | 18816 | if( z==0 ) z = ""; |
| 18042 | 18817 | while( *z ){ |
| 18043 | 18818 | for(i=0; z[i] |
| 18044 | 18819 | && z[i]!='<' |
| | @@ -18046,22 +18821,22 @@ |
| 18046 | 18821 | && z[i]!='>' |
| 18047 | 18822 | && z[i]!='\"' |
| 18048 | 18823 | && z[i]!='\''; |
| 18049 | 18824 | i++){} |
| 18050 | 18825 | if( i>0 ){ |
| 18051 | | - utf8_printf(out,"%.*s",i,z); |
| 18826 | + oputf("%.*s",i,z); |
| 18052 | 18827 | } |
| 18053 | 18828 | if( z[i]=='<' ){ |
| 18054 | | - raw_printf(out,"<"); |
| 18829 | + oputz("<"); |
| 18055 | 18830 | }else if( z[i]=='&' ){ |
| 18056 | | - raw_printf(out,"&"); |
| 18831 | + oputz("&"); |
| 18057 | 18832 | }else if( z[i]=='>' ){ |
| 18058 | | - raw_printf(out,">"); |
| 18833 | + oputz(">"); |
| 18059 | 18834 | }else if( z[i]=='\"' ){ |
| 18060 | | - raw_printf(out,"""); |
| 18835 | + oputz("""); |
| 18061 | 18836 | }else if( z[i]=='\'' ){ |
| 18062 | | - raw_printf(out,"'"); |
| 18837 | + oputz("'"); |
| 18063 | 18838 | }else{ |
| 18064 | 18839 | break; |
| 18065 | 18840 | } |
| 18066 | 18841 | z += i + 1; |
| 18067 | 18842 | } |
| | @@ -18095,13 +18870,12 @@ |
| 18095 | 18870 | ** the separator, which may or may not be a comma. p->nullValue is |
| 18096 | 18871 | ** the null value. Strings are quoted if necessary. The separator |
| 18097 | 18872 | ** is only issued if bSep is true. |
| 18098 | 18873 | */ |
| 18099 | 18874 | static void output_csv(ShellState *p, const char *z, int bSep){ |
| 18100 | | - FILE *out = p->out; |
| 18101 | 18875 | if( z==0 ){ |
| 18102 | | - utf8_printf(out,"%s",p->nullValue); |
| 18876 | + oputf("%s",p->nullValue); |
| 18103 | 18877 | }else{ |
| 18104 | 18878 | unsigned i; |
| 18105 | 18879 | for(i=0; z[i]; i++){ |
| 18106 | 18880 | if( needCsvQuote[((unsigned char*)z)[i]] ){ |
| 18107 | 18881 | i = 0; |
| | @@ -18109,18 +18883,18 @@ |
| 18109 | 18883 | } |
| 18110 | 18884 | } |
| 18111 | 18885 | if( i==0 || strstr(z, p->colSeparator)!=0 ){ |
| 18112 | 18886 | char *zQuoted = sqlite3_mprintf("\"%w\"", z); |
| 18113 | 18887 | shell_check_oom(zQuoted); |
| 18114 | | - utf8_printf(out, "%s", zQuoted); |
| 18888 | + oputz(zQuoted); |
| 18115 | 18889 | sqlite3_free(zQuoted); |
| 18116 | 18890 | }else{ |
| 18117 | | - utf8_printf(out, "%s", z); |
| 18891 | + oputz(z); |
| 18118 | 18892 | } |
| 18119 | 18893 | } |
| 18120 | 18894 | if( bSep ){ |
| 18121 | | - utf8_printf(p->out, "%s", p->colSeparator); |
| 18895 | + oputz(p->colSeparator); |
| 18122 | 18896 | } |
| 18123 | 18897 | } |
| 18124 | 18898 | |
| 18125 | 18899 | /* |
| 18126 | 18900 | ** This routine runs when the user presses Ctrl-C |
| | @@ -18224,20 +18998,20 @@ |
| 18224 | 18998 | const char *az[4]; |
| 18225 | 18999 | az[0] = zA1; |
| 18226 | 19000 | az[1] = zA2; |
| 18227 | 19001 | az[2] = zA3; |
| 18228 | 19002 | az[3] = zA4; |
| 18229 | | - utf8_printf(p->out, "authorizer: %s", azAction[op]); |
| 19003 | + oputf("authorizer: %s", azAction[op]); |
| 18230 | 19004 | for(i=0; i<4; i++){ |
| 18231 | | - raw_printf(p->out, " "); |
| 19005 | + oputz(" "); |
| 18232 | 19006 | if( az[i] ){ |
| 18233 | | - output_c_string(p->out, az[i]); |
| 19007 | + output_c_string(az[i]); |
| 18234 | 19008 | }else{ |
| 18235 | | - raw_printf(p->out, "NULL"); |
| 19009 | + oputz("NULL"); |
| 18236 | 19010 | } |
| 18237 | 19011 | } |
| 18238 | | - raw_printf(p->out, "\n"); |
| 19012 | + oputz("\n"); |
| 18239 | 19013 | if( p->bSafeMode ) (void)safeModeAuth(pClientData, op, zA1, zA2, zA3, zA4); |
| 18240 | 19014 | return SQLITE_OK; |
| 18241 | 19015 | } |
| 18242 | 19016 | #endif |
| 18243 | 19017 | |
| | @@ -18249,11 +19023,11 @@ |
| 18249 | 19023 | ** |
| 18250 | 19024 | ** If the schema statement in z[] contains a start-of-comment and if |
| 18251 | 19025 | ** sqlite3_complete() returns false, try to terminate the comment before |
| 18252 | 19026 | ** printing the result. https://sqlite.org/forum/forumpost/d7be961c5c |
| 18253 | 19027 | */ |
| 18254 | | -static void printSchemaLine(FILE *out, const char *z, const char *zTail){ |
| 19028 | +static void printSchemaLine(const char *z, const char *zTail){ |
| 18255 | 19029 | char *zToFree = 0; |
| 18256 | 19030 | if( z==0 ) return; |
| 18257 | 19031 | if( zTail==0 ) return; |
| 18258 | 19032 | if( zTail[0]==';' && (strstr(z, "/*")!=0 || strstr(z,"--")!=0) ){ |
| 18259 | 19033 | const char *zOrig = z; |
| | @@ -18271,20 +19045,20 @@ |
| 18271 | 19045 | } |
| 18272 | 19046 | sqlite3_free(zNew); |
| 18273 | 19047 | } |
| 18274 | 19048 | } |
| 18275 | 19049 | if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){ |
| 18276 | | - utf8_printf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail); |
| 19050 | + oputf("CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail); |
| 18277 | 19051 | }else{ |
| 18278 | | - utf8_printf(out, "%s%s", z, zTail); |
| 19052 | + oputf("%s%s", z, zTail); |
| 18279 | 19053 | } |
| 18280 | 19054 | sqlite3_free(zToFree); |
| 18281 | 19055 | } |
| 18282 | | -static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){ |
| 19056 | +static void printSchemaLineN(char *z, int n, const char *zTail){ |
| 18283 | 19057 | char c = z[n]; |
| 18284 | 19058 | z[n] = 0; |
| 18285 | | - printSchemaLine(out, z, zTail); |
| 19059 | + printSchemaLine(z, zTail); |
| 18286 | 19060 | z[n] = c; |
| 18287 | 19061 | } |
| 18288 | 19062 | |
| 18289 | 19063 | /* |
| 18290 | 19064 | ** Return true if string z[] has nothing but whitespace and comments to the |
| | @@ -18308,11 +19082,11 @@ |
| 18308 | 19082 | EQPGraphRow *pNew; |
| 18309 | 19083 | i64 nText; |
| 18310 | 19084 | if( zText==0 ) return; |
| 18311 | 19085 | nText = strlen(zText); |
| 18312 | 19086 | if( p->autoEQPtest ){ |
| 18313 | | - utf8_printf(p->out, "%d,%d,%s\n", iEqpId, p2, zText); |
| 19087 | + oputf("%d,%d,%s\n", iEqpId, p2, zText); |
| 18314 | 19088 | } |
| 18315 | 19089 | pNew = sqlite3_malloc64( sizeof(*pNew) + nText ); |
| 18316 | 19090 | shell_check_oom(pNew); |
| 18317 | 19091 | pNew->iEqpId = iEqpId; |
| 18318 | 19092 | pNew->iParentId = p2; |
| | @@ -18356,12 +19130,11 @@ |
| 18356 | 19130 | i64 n = strlen(p->sGraph.zPrefix); |
| 18357 | 19131 | char *z; |
| 18358 | 19132 | for(pRow = eqp_next_row(p, iEqpId, 0); pRow; pRow = pNext){ |
| 18359 | 19133 | pNext = eqp_next_row(p, iEqpId, pRow); |
| 18360 | 19134 | z = pRow->zText; |
| 18361 | | - utf8_printf(p->out, "%s%s%s\n", p->sGraph.zPrefix, |
| 18362 | | - pNext ? "|--" : "`--", z); |
| 19135 | + oputf("%s%s%s\n", p->sGraph.zPrefix, pNext ? "|--" : "`--", z); |
| 18363 | 19136 | if( n<(i64)sizeof(p->sGraph.zPrefix)-7 ){ |
| 18364 | 19137 | memcpy(&p->sGraph.zPrefix[n], pNext ? "| " : " ", 4); |
| 18365 | 19138 | eqp_render_level(p, pRow->iEqpId); |
| 18366 | 19139 | p->sGraph.zPrefix[n] = 0; |
| 18367 | 19140 | } |
| | @@ -18377,17 +19150,17 @@ |
| 18377 | 19150 | if( pRow->zText[0]=='-' ){ |
| 18378 | 19151 | if( pRow->pNext==0 ){ |
| 18379 | 19152 | eqp_reset(p); |
| 18380 | 19153 | return; |
| 18381 | 19154 | } |
| 18382 | | - utf8_printf(p->out, "%s\n", pRow->zText+3); |
| 19155 | + oputf("%s\n", pRow->zText+3); |
| 18383 | 19156 | p->sGraph.pRow = pRow->pNext; |
| 18384 | 19157 | sqlite3_free(pRow); |
| 18385 | 19158 | }else if( nCycle>0 ){ |
| 18386 | | - utf8_printf(p->out, "QUERY PLAN (cycles=%lld [100%%])\n", nCycle); |
| 19159 | + oputf("QUERY PLAN (cycles=%lld [100%%])\n", nCycle); |
| 18387 | 19160 | }else{ |
| 18388 | | - utf8_printf(p->out, "QUERY PLAN\n"); |
| 19161 | + oputz("QUERY PLAN\n"); |
| 18389 | 19162 | } |
| 18390 | 19163 | p->sGraph.zPrefix[0] = 0; |
| 18391 | 19164 | eqp_render_level(p, 0); |
| 18392 | 19165 | eqp_reset(p); |
| 18393 | 19166 | } |
| | @@ -18399,33 +19172,33 @@ |
| 18399 | 19172 | */ |
| 18400 | 19173 | static int progress_handler(void *pClientData) { |
| 18401 | 19174 | ShellState *p = (ShellState*)pClientData; |
| 18402 | 19175 | p->nProgress++; |
| 18403 | 19176 | if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){ |
| 18404 | | - raw_printf(p->out, "Progress limit reached (%u)\n", p->nProgress); |
| 19177 | + oputf("Progress limit reached (%u)\n", p->nProgress); |
| 18405 | 19178 | if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0; |
| 18406 | 19179 | if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0; |
| 18407 | 19180 | return 1; |
| 18408 | 19181 | } |
| 18409 | 19182 | if( (p->flgProgress & SHELL_PROGRESS_QUIET)==0 ){ |
| 18410 | | - raw_printf(p->out, "Progress %u\n", p->nProgress); |
| 19183 | + oputf("Progress %u\n", p->nProgress); |
| 18411 | 19184 | } |
| 18412 | 19185 | return 0; |
| 18413 | 19186 | } |
| 18414 | 19187 | #endif /* SQLITE_OMIT_PROGRESS_CALLBACK */ |
| 18415 | 19188 | |
| 18416 | 19189 | /* |
| 18417 | 19190 | ** Print N dashes |
| 18418 | 19191 | */ |
| 18419 | | -static void print_dashes(FILE *out, int N){ |
| 19192 | +static void print_dashes(int N){ |
| 18420 | 19193 | const char zDash[] = "--------------------------------------------------"; |
| 18421 | 19194 | const int nDash = sizeof(zDash) - 1; |
| 18422 | 19195 | while( N>nDash ){ |
| 18423 | | - fputs(zDash, out); |
| 19196 | + oputz(zDash); |
| 18424 | 19197 | N -= nDash; |
| 18425 | 19198 | } |
| 18426 | | - raw_printf(out, "%.*s", N, zDash); |
| 19199 | + oputf("%.*s", N, zDash); |
| 18427 | 19200 | } |
| 18428 | 19201 | |
| 18429 | 19202 | /* |
| 18430 | 19203 | ** Print a markdown or table-style row separator using ascii-art |
| 18431 | 19204 | */ |
| | @@ -18434,19 +19207,19 @@ |
| 18434 | 19207 | int nArg, |
| 18435 | 19208 | const char *zSep |
| 18436 | 19209 | ){ |
| 18437 | 19210 | int i; |
| 18438 | 19211 | if( nArg>0 ){ |
| 18439 | | - fputs(zSep, p->out); |
| 18440 | | - print_dashes(p->out, p->actualWidth[0]+2); |
| 19212 | + oputz(zSep); |
| 19213 | + print_dashes(p->actualWidth[0]+2); |
| 18441 | 19214 | for(i=1; i<nArg; i++){ |
| 18442 | | - fputs(zSep, p->out); |
| 18443 | | - print_dashes(p->out, p->actualWidth[i]+2); |
| 19215 | + oputz(zSep); |
| 19216 | + print_dashes(p->actualWidth[i]+2); |
| 18444 | 19217 | } |
| 18445 | | - fputs(zSep, p->out); |
| 19218 | + oputz(zSep); |
| 18446 | 19219 | } |
| 18447 | | - fputs("\n", p->out); |
| 19220 | + oputz("\n"); |
| 18448 | 19221 | } |
| 18449 | 19222 | |
| 18450 | 19223 | /* |
| 18451 | 19224 | ** This is the callback routine that the shell |
| 18452 | 19225 | ** invokes for each row of a query result. |
| | @@ -18472,14 +19245,14 @@ |
| 18472 | 19245 | if( azArg==0 ) break; |
| 18473 | 19246 | for(i=0; i<nArg; i++){ |
| 18474 | 19247 | int len = strlen30(azCol[i] ? azCol[i] : ""); |
| 18475 | 19248 | if( len>w ) w = len; |
| 18476 | 19249 | } |
| 18477 | | - if( p->cnt++>0 ) utf8_printf(p->out, "%s", p->rowSeparator); |
| 19250 | + if( p->cnt++>0 ) oputz(p->rowSeparator); |
| 18478 | 19251 | for(i=0; i<nArg; i++){ |
| 18479 | | - utf8_printf(p->out,"%*s = %s%s", w, azCol[i], |
| 18480 | | - azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator); |
| 19252 | + oputf("%*s = %s%s", w, azCol[i], |
| 19253 | + azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator); |
| 18481 | 19254 | } |
| 18482 | 19255 | break; |
| 18483 | 19256 | } |
| 18484 | 19257 | case MODE_ScanExp: |
| 18485 | 19258 | case MODE_Explain: { |
| | @@ -18502,16 +19275,16 @@ |
| 18502 | 19275 | if( nArg>nWidth ) nArg = nWidth; |
| 18503 | 19276 | |
| 18504 | 19277 | /* If this is the first row seen, print out the headers */ |
| 18505 | 19278 | if( p->cnt++==0 ){ |
| 18506 | 19279 | for(i=0; i<nArg; i++){ |
| 18507 | | - utf8_width_print(p->out, aWidth[i], azCol[ aMap[i] ]); |
| 18508 | | - fputs(i==nArg-1 ? "\n" : " ", p->out); |
| 19280 | + utf8_width_print(aWidth[i], azCol[ aMap[i] ]); |
| 19281 | + oputz(i==nArg-1 ? "\n" : " "); |
| 18509 | 19282 | } |
| 18510 | 19283 | for(i=0; i<nArg; i++){ |
| 18511 | | - print_dashes(p->out, aWidth[i]); |
| 18512 | | - fputs(i==nArg-1 ? "\n" : " ", p->out); |
| 19284 | + print_dashes(aWidth[i]); |
| 19285 | + oputz(i==nArg-1 ? "\n" : " "); |
| 18513 | 19286 | } |
| 18514 | 19287 | } |
| 18515 | 19288 | |
| 18516 | 19289 | /* If there is no data, exit early. */ |
| 18517 | 19290 | if( azArg==0 ) break; |
| | @@ -18525,21 +19298,21 @@ |
| 18525 | 19298 | w = strlenChar(zVal); |
| 18526 | 19299 | zSep = " "; |
| 18527 | 19300 | } |
| 18528 | 19301 | if( i==iIndent && p->aiIndent && p->pStmt ){ |
| 18529 | 19302 | if( p->iIndent<p->nIndent ){ |
| 18530 | | - utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], ""); |
| 19303 | + oputf("%*.s", p->aiIndent[p->iIndent], ""); |
| 18531 | 19304 | } |
| 18532 | 19305 | p->iIndent++; |
| 18533 | 19306 | } |
| 18534 | | - utf8_width_print(p->out, w, zVal ? zVal : p->nullValue); |
| 18535 | | - fputs(i==nArg-1 ? "\n" : zSep, p->out); |
| 19307 | + utf8_width_print(w, zVal ? zVal : p->nullValue); |
| 19308 | + oputz(i==nArg-1 ? "\n" : zSep); |
| 18536 | 19309 | } |
| 18537 | 19310 | break; |
| 18538 | 19311 | } |
| 18539 | 19312 | case MODE_Semi: { /* .schema and .fullschema output */ |
| 18540 | | - printSchemaLine(p->out, azArg[0], ";\n"); |
| 19313 | + printSchemaLine(azArg[0], ";\n"); |
| 18541 | 19314 | break; |
| 18542 | 19315 | } |
| 18543 | 19316 | case MODE_Pretty: { /* .schema and .fullschema with --indent */ |
| 18544 | 19317 | char *z; |
| 18545 | 19318 | int j; |
| | @@ -18550,11 +19323,11 @@ |
| 18550 | 19323 | assert( nArg==1 ); |
| 18551 | 19324 | if( azArg[0]==0 ) break; |
| 18552 | 19325 | if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0 |
| 18553 | 19326 | || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0 |
| 18554 | 19327 | ){ |
| 18555 | | - utf8_printf(p->out, "%s;\n", azArg[0]); |
| 19328 | + oputf("%s;\n", azArg[0]); |
| 18556 | 19329 | break; |
| 18557 | 19330 | } |
| 18558 | 19331 | z = sqlite3_mprintf("%s", azArg[0]); |
| 18559 | 19332 | shell_check_oom(z); |
| 18560 | 19333 | j = 0; |
| | @@ -18583,166 +19356,161 @@ |
| 18583 | 19356 | }else if( c=='(' ){ |
| 18584 | 19357 | nParen++; |
| 18585 | 19358 | }else if( c==')' ){ |
| 18586 | 19359 | nParen--; |
| 18587 | 19360 | if( nLine>0 && nParen==0 && j>0 ){ |
| 18588 | | - printSchemaLineN(p->out, z, j, "\n"); |
| 19361 | + printSchemaLineN(z, j, "\n"); |
| 18589 | 19362 | j = 0; |
| 18590 | 19363 | } |
| 18591 | 19364 | } |
| 18592 | 19365 | z[j++] = c; |
| 18593 | 19366 | if( nParen==1 && cEnd==0 |
| 18594 | 19367 | && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1))) |
| 18595 | 19368 | ){ |
| 18596 | 19369 | if( c=='\n' ) j--; |
| 18597 | | - printSchemaLineN(p->out, z, j, "\n "); |
| 19370 | + printSchemaLineN(z, j, "\n "); |
| 18598 | 19371 | j = 0; |
| 18599 | 19372 | nLine++; |
| 18600 | 19373 | while( IsSpace(z[i+1]) ){ i++; } |
| 18601 | 19374 | } |
| 18602 | 19375 | } |
| 18603 | 19376 | z[j] = 0; |
| 18604 | 19377 | } |
| 18605 | | - printSchemaLine(p->out, z, ";\n"); |
| 19378 | + printSchemaLine(z, ";\n"); |
| 18606 | 19379 | sqlite3_free(z); |
| 18607 | 19380 | break; |
| 18608 | 19381 | } |
| 18609 | 19382 | case MODE_List: { |
| 18610 | 19383 | if( p->cnt++==0 && p->showHeader ){ |
| 18611 | 19384 | for(i=0; i<nArg; i++){ |
| 18612 | | - utf8_printf(p->out,"%s%s",azCol[i], |
| 18613 | | - i==nArg-1 ? p->rowSeparator : p->colSeparator); |
| 19385 | + oputf("%s%s",azCol[i], i==nArg-1 ? p->rowSeparator : p->colSeparator); |
| 18614 | 19386 | } |
| 18615 | 19387 | } |
| 18616 | 19388 | if( azArg==0 ) break; |
| 18617 | 19389 | for(i=0; i<nArg; i++){ |
| 18618 | 19390 | char *z = azArg[i]; |
| 18619 | 19391 | if( z==0 ) z = p->nullValue; |
| 18620 | | - utf8_printf(p->out, "%s", z); |
| 18621 | | - if( i<nArg-1 ){ |
| 18622 | | - utf8_printf(p->out, "%s", p->colSeparator); |
| 18623 | | - }else{ |
| 18624 | | - utf8_printf(p->out, "%s", p->rowSeparator); |
| 18625 | | - } |
| 19392 | + oputz(z); |
| 19393 | + oputz((i<nArg-1)? p->colSeparator : p->rowSeparator); |
| 18626 | 19394 | } |
| 18627 | 19395 | break; |
| 18628 | 19396 | } |
| 18629 | 19397 | case MODE_Html: { |
| 18630 | 19398 | if( p->cnt++==0 && p->showHeader ){ |
| 18631 | | - raw_printf(p->out,"<TR>"); |
| 19399 | + oputz("<TR>"); |
| 18632 | 19400 | for(i=0; i<nArg; i++){ |
| 18633 | | - raw_printf(p->out,"<TH>"); |
| 18634 | | - output_html_string(p->out, azCol[i]); |
| 18635 | | - raw_printf(p->out,"</TH>\n"); |
| 19401 | + oputz("<TH>"); |
| 19402 | + output_html_string(azCol[i]); |
| 19403 | + oputz("</TH>\n"); |
| 18636 | 19404 | } |
| 18637 | | - raw_printf(p->out,"</TR>\n"); |
| 19405 | + oputz("</TR>\n"); |
| 18638 | 19406 | } |
| 18639 | 19407 | if( azArg==0 ) break; |
| 18640 | | - raw_printf(p->out,"<TR>"); |
| 19408 | + oputz("<TR>"); |
| 18641 | 19409 | for(i=0; i<nArg; i++){ |
| 18642 | | - raw_printf(p->out,"<TD>"); |
| 18643 | | - output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue); |
| 18644 | | - raw_printf(p->out,"</TD>\n"); |
| 19410 | + oputz("<TD>"); |
| 19411 | + output_html_string(azArg[i] ? azArg[i] : p->nullValue); |
| 19412 | + oputz("</TD>\n"); |
| 18645 | 19413 | } |
| 18646 | | - raw_printf(p->out,"</TR>\n"); |
| 19414 | + oputz("</TR>\n"); |
| 18647 | 19415 | break; |
| 18648 | 19416 | } |
| 18649 | 19417 | case MODE_Tcl: { |
| 18650 | 19418 | if( p->cnt++==0 && p->showHeader ){ |
| 18651 | 19419 | for(i=0; i<nArg; i++){ |
| 18652 | | - output_c_string(p->out,azCol[i] ? azCol[i] : ""); |
| 18653 | | - if(i<nArg-1) utf8_printf(p->out, "%s", p->colSeparator); |
| 19420 | + output_c_string(azCol[i] ? azCol[i] : ""); |
| 19421 | + if(i<nArg-1) oputz(p->colSeparator); |
| 18654 | 19422 | } |
| 18655 | | - utf8_printf(p->out, "%s", p->rowSeparator); |
| 19423 | + oputz(p->rowSeparator); |
| 18656 | 19424 | } |
| 18657 | 19425 | if( azArg==0 ) break; |
| 18658 | 19426 | for(i=0; i<nArg; i++){ |
| 18659 | | - output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue); |
| 18660 | | - if(i<nArg-1) utf8_printf(p->out, "%s", p->colSeparator); |
| 19427 | + output_c_string(azArg[i] ? azArg[i] : p->nullValue); |
| 19428 | + if(i<nArg-1) oputz(p->colSeparator); |
| 18661 | 19429 | } |
| 18662 | | - utf8_printf(p->out, "%s", p->rowSeparator); |
| 19430 | + oputz(p->rowSeparator); |
| 18663 | 19431 | break; |
| 18664 | 19432 | } |
| 18665 | 19433 | case MODE_Csv: { |
| 18666 | 19434 | setBinaryMode(p->out, 1); |
| 18667 | 19435 | if( p->cnt++==0 && p->showHeader ){ |
| 18668 | 19436 | for(i=0; i<nArg; i++){ |
| 18669 | 19437 | output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1); |
| 18670 | 19438 | } |
| 18671 | | - utf8_printf(p->out, "%s", p->rowSeparator); |
| 19439 | + oputz(p->rowSeparator); |
| 18672 | 19440 | } |
| 18673 | 19441 | if( nArg>0 ){ |
| 18674 | 19442 | for(i=0; i<nArg; i++){ |
| 18675 | 19443 | output_csv(p, azArg[i], i<nArg-1); |
| 18676 | 19444 | } |
| 18677 | | - utf8_printf(p->out, "%s", p->rowSeparator); |
| 19445 | + oputz(p->rowSeparator); |
| 18678 | 19446 | } |
| 18679 | 19447 | setTextMode(p->out, 1); |
| 18680 | 19448 | break; |
| 18681 | 19449 | } |
| 18682 | 19450 | case MODE_Insert: { |
| 18683 | 19451 | if( azArg==0 ) break; |
| 18684 | | - utf8_printf(p->out,"INSERT INTO %s",p->zDestTable); |
| 19452 | + oputf("INSERT INTO %s",p->zDestTable); |
| 18685 | 19453 | if( p->showHeader ){ |
| 18686 | | - raw_printf(p->out,"("); |
| 19454 | + oputz("("); |
| 18687 | 19455 | for(i=0; i<nArg; i++){ |
| 18688 | | - if( i>0 ) raw_printf(p->out, ","); |
| 19456 | + if( i>0 ) oputz(","); |
| 18689 | 19457 | if( quoteChar(azCol[i]) ){ |
| 18690 | 19458 | char *z = sqlite3_mprintf("\"%w\"", azCol[i]); |
| 18691 | 19459 | shell_check_oom(z); |
| 18692 | | - utf8_printf(p->out, "%s", z); |
| 19460 | + oputz(z); |
| 18693 | 19461 | sqlite3_free(z); |
| 18694 | 19462 | }else{ |
| 18695 | | - raw_printf(p->out, "%s", azCol[i]); |
| 19463 | + oputf("%s", azCol[i]); |
| 18696 | 19464 | } |
| 18697 | 19465 | } |
| 18698 | | - raw_printf(p->out,")"); |
| 19466 | + oputz(")"); |
| 18699 | 19467 | } |
| 18700 | 19468 | p->cnt++; |
| 18701 | 19469 | for(i=0; i<nArg; i++){ |
| 18702 | | - raw_printf(p->out, i>0 ? "," : " VALUES("); |
| 19470 | + oputz(i>0 ? "," : " VALUES("); |
| 18703 | 19471 | if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ |
| 18704 | | - utf8_printf(p->out,"NULL"); |
| 19472 | + oputz("NULL"); |
| 18705 | 19473 | }else if( aiType && aiType[i]==SQLITE_TEXT ){ |
| 18706 | 19474 | if( ShellHasFlag(p, SHFLG_Newlines) ){ |
| 18707 | | - output_quoted_string(p->out, azArg[i]); |
| 19475 | + output_quoted_string(azArg[i]); |
| 18708 | 19476 | }else{ |
| 18709 | | - output_quoted_escaped_string(p->out, azArg[i]); |
| 19477 | + output_quoted_escaped_string(azArg[i]); |
| 18710 | 19478 | } |
| 18711 | 19479 | }else if( aiType && aiType[i]==SQLITE_INTEGER ){ |
| 18712 | | - utf8_printf(p->out,"%s", azArg[i]); |
| 19480 | + oputz(azArg[i]); |
| 18713 | 19481 | }else if( aiType && aiType[i]==SQLITE_FLOAT ){ |
| 18714 | 19482 | char z[50]; |
| 18715 | 19483 | double r = sqlite3_column_double(p->pStmt, i); |
| 18716 | 19484 | sqlite3_uint64 ur; |
| 18717 | 19485 | memcpy(&ur,&r,sizeof(r)); |
| 18718 | 19486 | if( ur==0x7ff0000000000000LL ){ |
| 18719 | | - raw_printf(p->out, "9.0e+999"); |
| 19487 | + oputz("9.0e+999"); |
| 18720 | 19488 | }else if( ur==0xfff0000000000000LL ){ |
| 18721 | | - raw_printf(p->out, "-9.0e+999"); |
| 19489 | + oputz("-9.0e+999"); |
| 18722 | 19490 | }else{ |
| 18723 | 19491 | sqlite3_int64 ir = (sqlite3_int64)r; |
| 18724 | 19492 | if( r==(double)ir ){ |
| 18725 | 19493 | sqlite3_snprintf(50,z,"%lld.0", ir); |
| 18726 | 19494 | }else{ |
| 18727 | 19495 | sqlite3_snprintf(50,z,"%!.20g", r); |
| 18728 | 19496 | } |
| 18729 | | - raw_printf(p->out, "%s", z); |
| 19497 | + oputz(z); |
| 18730 | 19498 | } |
| 18731 | 19499 | }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ |
| 18732 | 19500 | const void *pBlob = sqlite3_column_blob(p->pStmt, i); |
| 18733 | 19501 | int nBlob = sqlite3_column_bytes(p->pStmt, i); |
| 18734 | | - output_hex_blob(p->out, pBlob, nBlob); |
| 19502 | + output_hex_blob(pBlob, nBlob); |
| 18735 | 19503 | }else if( isNumber(azArg[i], 0) ){ |
| 18736 | | - utf8_printf(p->out,"%s", azArg[i]); |
| 19504 | + oputz(azArg[i]); |
| 18737 | 19505 | }else if( ShellHasFlag(p, SHFLG_Newlines) ){ |
| 18738 | | - output_quoted_string(p->out, azArg[i]); |
| 19506 | + output_quoted_string(azArg[i]); |
| 18739 | 19507 | }else{ |
| 18740 | | - output_quoted_escaped_string(p->out, azArg[i]); |
| 19508 | + output_quoted_escaped_string(azArg[i]); |
| 18741 | 19509 | } |
| 18742 | 19510 | } |
| 18743 | | - raw_printf(p->out,");\n"); |
| 19511 | + oputz(");\n"); |
| 18744 | 19512 | break; |
| 18745 | 19513 | } |
| 18746 | 19514 | case MODE_Json: { |
| 18747 | 19515 | if( azArg==0 ) break; |
| 18748 | 19516 | if( p->cnt==0 ){ |
| | @@ -18750,93 +19518,93 @@ |
| 18750 | 19518 | }else{ |
| 18751 | 19519 | fputs(",\n{", p->out); |
| 18752 | 19520 | } |
| 18753 | 19521 | p->cnt++; |
| 18754 | 19522 | for(i=0; i<nArg; i++){ |
| 18755 | | - output_json_string(p->out, azCol[i], -1); |
| 18756 | | - putc(':', p->out); |
| 19523 | + output_json_string(azCol[i], -1); |
| 19524 | + oputz(":"); |
| 18757 | 19525 | if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ |
| 18758 | | - fputs("null",p->out); |
| 19526 | + oputz("null"); |
| 18759 | 19527 | }else if( aiType && aiType[i]==SQLITE_FLOAT ){ |
| 18760 | 19528 | char z[50]; |
| 18761 | 19529 | double r = sqlite3_column_double(p->pStmt, i); |
| 18762 | 19530 | sqlite3_uint64 ur; |
| 18763 | 19531 | memcpy(&ur,&r,sizeof(r)); |
| 18764 | 19532 | if( ur==0x7ff0000000000000LL ){ |
| 18765 | | - raw_printf(p->out, "9.0e+999"); |
| 19533 | + oputz("9.0e+999"); |
| 18766 | 19534 | }else if( ur==0xfff0000000000000LL ){ |
| 18767 | | - raw_printf(p->out, "-9.0e+999"); |
| 19535 | + oputz("-9.0e+999"); |
| 18768 | 19536 | }else{ |
| 18769 | 19537 | sqlite3_snprintf(50,z,"%!.20g", r); |
| 18770 | | - raw_printf(p->out, "%s", z); |
| 19538 | + oputz(z); |
| 18771 | 19539 | } |
| 18772 | 19540 | }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ |
| 18773 | 19541 | const void *pBlob = sqlite3_column_blob(p->pStmt, i); |
| 18774 | 19542 | int nBlob = sqlite3_column_bytes(p->pStmt, i); |
| 18775 | | - output_json_string(p->out, pBlob, nBlob); |
| 19543 | + output_json_string(pBlob, nBlob); |
| 18776 | 19544 | }else if( aiType && aiType[i]==SQLITE_TEXT ){ |
| 18777 | | - output_json_string(p->out, azArg[i], -1); |
| 19545 | + output_json_string(azArg[i], -1); |
| 18778 | 19546 | }else{ |
| 18779 | | - utf8_printf(p->out,"%s", azArg[i]); |
| 19547 | + oputz(azArg[i]); |
| 18780 | 19548 | } |
| 18781 | 19549 | if( i<nArg-1 ){ |
| 18782 | | - putc(',', p->out); |
| 19550 | + oputz(","); |
| 18783 | 19551 | } |
| 18784 | 19552 | } |
| 18785 | | - putc('}', p->out); |
| 19553 | + oputz("}"); |
| 18786 | 19554 | break; |
| 18787 | 19555 | } |
| 18788 | 19556 | case MODE_Quote: { |
| 18789 | 19557 | if( azArg==0 ) break; |
| 18790 | 19558 | if( p->cnt==0 && p->showHeader ){ |
| 18791 | 19559 | for(i=0; i<nArg; i++){ |
| 18792 | 19560 | if( i>0 ) fputs(p->colSeparator, p->out); |
| 18793 | | - output_quoted_string(p->out, azCol[i]); |
| 19561 | + output_quoted_string(azCol[i]); |
| 18794 | 19562 | } |
| 18795 | 19563 | fputs(p->rowSeparator, p->out); |
| 18796 | 19564 | } |
| 18797 | 19565 | p->cnt++; |
| 18798 | 19566 | for(i=0; i<nArg; i++){ |
| 18799 | 19567 | if( i>0 ) fputs(p->colSeparator, p->out); |
| 18800 | 19568 | if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ |
| 18801 | | - utf8_printf(p->out,"NULL"); |
| 19569 | + oputz("NULL"); |
| 18802 | 19570 | }else if( aiType && aiType[i]==SQLITE_TEXT ){ |
| 18803 | | - output_quoted_string(p->out, azArg[i]); |
| 19571 | + output_quoted_string(azArg[i]); |
| 18804 | 19572 | }else if( aiType && aiType[i]==SQLITE_INTEGER ){ |
| 18805 | | - utf8_printf(p->out,"%s", azArg[i]); |
| 19573 | + oputz(azArg[i]); |
| 18806 | 19574 | }else if( aiType && aiType[i]==SQLITE_FLOAT ){ |
| 18807 | 19575 | char z[50]; |
| 18808 | 19576 | double r = sqlite3_column_double(p->pStmt, i); |
| 18809 | 19577 | sqlite3_snprintf(50,z,"%!.20g", r); |
| 18810 | | - raw_printf(p->out, "%s", z); |
| 19578 | + oputz(z); |
| 18811 | 19579 | }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ |
| 18812 | 19580 | const void *pBlob = sqlite3_column_blob(p->pStmt, i); |
| 18813 | 19581 | int nBlob = sqlite3_column_bytes(p->pStmt, i); |
| 18814 | | - output_hex_blob(p->out, pBlob, nBlob); |
| 19582 | + output_hex_blob(pBlob, nBlob); |
| 18815 | 19583 | }else if( isNumber(azArg[i], 0) ){ |
| 18816 | | - utf8_printf(p->out,"%s", azArg[i]); |
| 19584 | + oputz(azArg[i]); |
| 18817 | 19585 | }else{ |
| 18818 | | - output_quoted_string(p->out, azArg[i]); |
| 19586 | + output_quoted_string(azArg[i]); |
| 18819 | 19587 | } |
| 18820 | 19588 | } |
| 18821 | 19589 | fputs(p->rowSeparator, p->out); |
| 18822 | 19590 | break; |
| 18823 | 19591 | } |
| 18824 | 19592 | case MODE_Ascii: { |
| 18825 | 19593 | if( p->cnt++==0 && p->showHeader ){ |
| 18826 | 19594 | for(i=0; i<nArg; i++){ |
| 18827 | | - if( i>0 ) utf8_printf(p->out, "%s", p->colSeparator); |
| 18828 | | - utf8_printf(p->out,"%s",azCol[i] ? azCol[i] : ""); |
| 19595 | + if( i>0 ) oputz(p->colSeparator); |
| 19596 | + oputz(azCol[i] ? azCol[i] : ""); |
| 18829 | 19597 | } |
| 18830 | | - utf8_printf(p->out, "%s", p->rowSeparator); |
| 19598 | + oputz(p->rowSeparator); |
| 18831 | 19599 | } |
| 18832 | 19600 | if( azArg==0 ) break; |
| 18833 | 19601 | for(i=0; i<nArg; i++){ |
| 18834 | | - if( i>0 ) utf8_printf(p->out, "%s", p->colSeparator); |
| 18835 | | - utf8_printf(p->out,"%s",azArg[i] ? azArg[i] : p->nullValue); |
| 19602 | + if( i>0 ) oputz(p->colSeparator); |
| 19603 | + oputz(azArg[i] ? azArg[i] : p->nullValue); |
| 18836 | 19604 | } |
| 18837 | | - utf8_printf(p->out, "%s", p->rowSeparator); |
| 19605 | + oputz(p->rowSeparator); |
| 18838 | 19606 | break; |
| 18839 | 19607 | } |
| 18840 | 19608 | case MODE_EQP: { |
| 18841 | 19609 | eqp_append(p, atoi(azArg[0]), atoi(azArg[1]), azArg[3]); |
| 18842 | 19610 | break; |
| | @@ -18911,11 +19679,11 @@ |
| 18911 | 19679 | "INSERT INTO selftest(tno,op,cmd,ans)" |
| 18912 | 19680 | " SELECT rowid*10,op,cmd,ans FROM [_shell$self];\n" |
| 18913 | 19681 | "DROP TABLE [_shell$self];" |
| 18914 | 19682 | ,0,0,&zErrMsg); |
| 18915 | 19683 | if( zErrMsg ){ |
| 18916 | | - utf8_printf(stderr, "SELFTEST initialization failure: %s\n", zErrMsg); |
| 19684 | + eputf("SELFTEST initialization failure: %s\n", zErrMsg); |
| 18917 | 19685 | sqlite3_free(zErrMsg); |
| 18918 | 19686 | } |
| 18919 | 19687 | sqlite3_exec(p->db, "RELEASE selftest_init",0,0,0); |
| 18920 | 19688 | } |
| 18921 | 19689 | |
| | @@ -19014,37 +19782,36 @@ |
| 19014 | 19782 | int i; |
| 19015 | 19783 | const char *z; |
| 19016 | 19784 | rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0); |
| 19017 | 19785 | if( rc!=SQLITE_OK || !pSelect ){ |
| 19018 | 19786 | char *zContext = shell_error_context(zSelect, p->db); |
| 19019 | | - utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n%s", rc, |
| 19020 | | - sqlite3_errmsg(p->db), zContext); |
| 19787 | + oputf("/**** ERROR: (%d) %s *****/\n%s", |
| 19788 | + rc, sqlite3_errmsg(p->db), zContext); |
| 19021 | 19789 | sqlite3_free(zContext); |
| 19022 | 19790 | if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; |
| 19023 | 19791 | return rc; |
| 19024 | 19792 | } |
| 19025 | 19793 | rc = sqlite3_step(pSelect); |
| 19026 | 19794 | nResult = sqlite3_column_count(pSelect); |
| 19027 | 19795 | while( rc==SQLITE_ROW ){ |
| 19028 | 19796 | z = (const char*)sqlite3_column_text(pSelect, 0); |
| 19029 | | - utf8_printf(p->out, "%s", z); |
| 19797 | + oputf("%s", z); |
| 19030 | 19798 | for(i=1; i<nResult; i++){ |
| 19031 | | - utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i)); |
| 19799 | + oputf(",%s", sqlite3_column_text(pSelect, i)); |
| 19032 | 19800 | } |
| 19033 | 19801 | if( z==0 ) z = ""; |
| 19034 | 19802 | while( z[0] && (z[0]!='-' || z[1]!='-') ) z++; |
| 19035 | 19803 | if( z[0] ){ |
| 19036 | | - raw_printf(p->out, "\n;\n"); |
| 19804 | + oputz("\n;\n"); |
| 19037 | 19805 | }else{ |
| 19038 | | - raw_printf(p->out, ";\n"); |
| 19806 | + oputz(";\n"); |
| 19039 | 19807 | } |
| 19040 | 19808 | rc = sqlite3_step(pSelect); |
| 19041 | 19809 | } |
| 19042 | 19810 | rc = sqlite3_finalize(pSelect); |
| 19043 | 19811 | if( rc!=SQLITE_OK ){ |
| 19044 | | - utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, |
| 19045 | | - sqlite3_errmsg(p->db)); |
| 19812 | + oputf("/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db)); |
| 19046 | 19813 | if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; |
| 19047 | 19814 | } |
| 19048 | 19815 | return rc; |
| 19049 | 19816 | } |
| 19050 | 19817 | |
| | @@ -19076,11 +19843,11 @@ |
| 19076 | 19843 | |
| 19077 | 19844 | #ifdef __linux__ |
| 19078 | 19845 | /* |
| 19079 | 19846 | ** Attempt to display I/O stats on Linux using /proc/PID/io |
| 19080 | 19847 | */ |
| 19081 | | -static void displayLinuxIoStats(FILE *out){ |
| 19848 | +static void displayLinuxIoStats(void){ |
| 19082 | 19849 | FILE *in; |
| 19083 | 19850 | char z[200]; |
| 19084 | 19851 | sqlite3_snprintf(sizeof(z), z, "/proc/%d/io", getpid()); |
| 19085 | 19852 | in = fopen(z, "rb"); |
| 19086 | 19853 | if( in==0 ) return; |
| | @@ -19099,11 +19866,11 @@ |
| 19099 | 19866 | }; |
| 19100 | 19867 | int i; |
| 19101 | 19868 | for(i=0; i<ArraySize(aTrans); i++){ |
| 19102 | 19869 | int n = strlen30(aTrans[i].zPattern); |
| 19103 | 19870 | if( cli_strncmp(aTrans[i].zPattern, z, n)==0 ){ |
| 19104 | | - utf8_printf(out, "%-36s %s", aTrans[i].zDesc, &z[n]); |
| 19871 | + oputf("%-36s %s", aTrans[i].zDesc, &z[n]); |
| 19105 | 19872 | break; |
| 19106 | 19873 | } |
| 19107 | 19874 | } |
| 19108 | 19875 | } |
| 19109 | 19876 | fclose(in); |
| | @@ -19112,11 +19879,10 @@ |
| 19112 | 19879 | |
| 19113 | 19880 | /* |
| 19114 | 19881 | ** Display a single line of status using 64-bit values. |
| 19115 | 19882 | */ |
| 19116 | 19883 | static void displayStatLine( |
| 19117 | | - ShellState *p, /* The shell context */ |
| 19118 | 19884 | char *zLabel, /* Label for this one line */ |
| 19119 | 19885 | char *zFormat, /* Format for the result */ |
| 19120 | 19886 | int iStatusCtrl, /* Which status to display */ |
| 19121 | 19887 | int bReset /* True to reset the stats */ |
| 19122 | 19888 | ){ |
| | @@ -19131,11 +19897,11 @@ |
| 19131 | 19897 | if( nPercent>1 ){ |
| 19132 | 19898 | sqlite3_snprintf(sizeof(zLine), zLine, zFormat, iCur, iHiwtr); |
| 19133 | 19899 | }else{ |
| 19134 | 19900 | sqlite3_snprintf(sizeof(zLine), zLine, zFormat, iHiwtr); |
| 19135 | 19901 | } |
| 19136 | | - raw_printf(p->out, "%-36s %s\n", zLabel, zLine); |
| 19902 | + oputf("%-36s %s\n", zLabel, zLine); |
| 19137 | 19903 | } |
| 19138 | 19904 | |
| 19139 | 19905 | /* |
| 19140 | 19906 | ** Display memory stats. |
| 19141 | 19907 | */ |
| | @@ -19144,141 +19910,130 @@ |
| 19144 | 19910 | ShellState *pArg, /* Pointer to ShellState */ |
| 19145 | 19911 | int bReset /* True to reset the stats */ |
| 19146 | 19912 | ){ |
| 19147 | 19913 | int iCur; |
| 19148 | 19914 | int iHiwtr; |
| 19149 | | - FILE *out; |
| 19150 | 19915 | if( pArg==0 || pArg->out==0 ) return 0; |
| 19151 | | - out = pArg->out; |
| 19152 | 19916 | |
| 19153 | 19917 | if( pArg->pStmt && pArg->statsOn==2 ){ |
| 19154 | 19918 | int nCol, i, x; |
| 19155 | 19919 | sqlite3_stmt *pStmt = pArg->pStmt; |
| 19156 | 19920 | char z[100]; |
| 19157 | 19921 | nCol = sqlite3_column_count(pStmt); |
| 19158 | | - raw_printf(out, "%-36s %d\n", "Number of output columns:", nCol); |
| 19922 | + oputf("%-36s %d\n", "Number of output columns:", nCol); |
| 19159 | 19923 | for(i=0; i<nCol; i++){ |
| 19160 | 19924 | sqlite3_snprintf(sizeof(z),z,"Column %d %nname:", i, &x); |
| 19161 | | - utf8_printf(out, "%-36s %s\n", z, sqlite3_column_name(pStmt,i)); |
| 19925 | + oputf("%-36s %s\n", z, sqlite3_column_name(pStmt,i)); |
| 19162 | 19926 | #ifndef SQLITE_OMIT_DECLTYPE |
| 19163 | 19927 | sqlite3_snprintf(30, z+x, "declared type:"); |
| 19164 | | - utf8_printf(out, "%-36s %s\n", z, sqlite3_column_decltype(pStmt, i)); |
| 19928 | + oputf("%-36s %s\n", z, sqlite3_column_decltype(pStmt, i)); |
| 19165 | 19929 | #endif |
| 19166 | 19930 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 19167 | 19931 | sqlite3_snprintf(30, z+x, "database name:"); |
| 19168 | | - utf8_printf(out, "%-36s %s\n", z, sqlite3_column_database_name(pStmt,i)); |
| 19932 | + oputf("%-36s %s\n", z, sqlite3_column_database_name(pStmt,i)); |
| 19169 | 19933 | sqlite3_snprintf(30, z+x, "table name:"); |
| 19170 | | - utf8_printf(out, "%-36s %s\n", z, sqlite3_column_table_name(pStmt,i)); |
| 19934 | + oputf("%-36s %s\n", z, sqlite3_column_table_name(pStmt,i)); |
| 19171 | 19935 | sqlite3_snprintf(30, z+x, "origin name:"); |
| 19172 | | - utf8_printf(out, "%-36s %s\n", z, sqlite3_column_origin_name(pStmt,i)); |
| 19936 | + oputf("%-36s %s\n", z, sqlite3_column_origin_name(pStmt,i)); |
| 19173 | 19937 | #endif |
| 19174 | 19938 | } |
| 19175 | 19939 | } |
| 19176 | 19940 | |
| 19177 | 19941 | if( pArg->statsOn==3 ){ |
| 19178 | 19942 | if( pArg->pStmt ){ |
| 19179 | 19943 | iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP,bReset); |
| 19180 | | - raw_printf(pArg->out, "VM-steps: %d\n", iCur); |
| 19944 | + oputf("VM-steps: %d\n", iCur); |
| 19181 | 19945 | } |
| 19182 | 19946 | return 0; |
| 19183 | 19947 | } |
| 19184 | 19948 | |
| 19185 | | - displayStatLine(pArg, "Memory Used:", |
| 19949 | + displayStatLine("Memory Used:", |
| 19186 | 19950 | "%lld (max %lld) bytes", SQLITE_STATUS_MEMORY_USED, bReset); |
| 19187 | | - displayStatLine(pArg, "Number of Outstanding Allocations:", |
| 19951 | + displayStatLine("Number of Outstanding Allocations:", |
| 19188 | 19952 | "%lld (max %lld)", SQLITE_STATUS_MALLOC_COUNT, bReset); |
| 19189 | 19953 | if( pArg->shellFlgs & SHFLG_Pagecache ){ |
| 19190 | | - displayStatLine(pArg, "Number of Pcache Pages Used:", |
| 19954 | + displayStatLine("Number of Pcache Pages Used:", |
| 19191 | 19955 | "%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset); |
| 19192 | 19956 | } |
| 19193 | | - displayStatLine(pArg, "Number of Pcache Overflow Bytes:", |
| 19957 | + displayStatLine("Number of Pcache Overflow Bytes:", |
| 19194 | 19958 | "%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset); |
| 19195 | | - displayStatLine(pArg, "Largest Allocation:", |
| 19959 | + displayStatLine("Largest Allocation:", |
| 19196 | 19960 | "%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset); |
| 19197 | | - displayStatLine(pArg, "Largest Pcache Allocation:", |
| 19961 | + displayStatLine("Largest Pcache Allocation:", |
| 19198 | 19962 | "%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset); |
| 19199 | 19963 | #ifdef YYTRACKMAXSTACKDEPTH |
| 19200 | | - displayStatLine(pArg, "Deepest Parser Stack:", |
| 19964 | + displayStatLine("Deepest Parser Stack:", |
| 19201 | 19965 | "%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset); |
| 19202 | 19966 | #endif |
| 19203 | 19967 | |
| 19204 | 19968 | if( db ){ |
| 19205 | 19969 | if( pArg->shellFlgs & SHFLG_Lookaside ){ |
| 19206 | 19970 | iHiwtr = iCur = -1; |
| 19207 | 19971 | sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, |
| 19208 | 19972 | &iCur, &iHiwtr, bReset); |
| 19209 | | - raw_printf(pArg->out, |
| 19210 | | - "Lookaside Slots Used: %d (max %d)\n", |
| 19211 | | - iCur, iHiwtr); |
| 19973 | + oputf("Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr); |
| 19212 | 19974 | sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, |
| 19213 | 19975 | &iCur, &iHiwtr, bReset); |
| 19214 | | - raw_printf(pArg->out, "Successful lookaside attempts: %d\n", |
| 19215 | | - iHiwtr); |
| 19976 | + oputf("Successful lookaside attempts: %d\n", iHiwtr); |
| 19216 | 19977 | sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, |
| 19217 | 19978 | &iCur, &iHiwtr, bReset); |
| 19218 | | - raw_printf(pArg->out, "Lookaside failures due to size: %d\n", |
| 19219 | | - iHiwtr); |
| 19979 | + oputf("Lookaside failures due to size: %d\n", iHiwtr); |
| 19220 | 19980 | sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, |
| 19221 | 19981 | &iCur, &iHiwtr, bReset); |
| 19222 | | - raw_printf(pArg->out, "Lookaside failures due to OOM: %d\n", |
| 19223 | | - iHiwtr); |
| 19982 | + oputf("Lookaside failures due to OOM: %d\n", iHiwtr); |
| 19224 | 19983 | } |
| 19225 | 19984 | iHiwtr = iCur = -1; |
| 19226 | 19985 | sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset); |
| 19227 | | - raw_printf(pArg->out, "Pager Heap Usage: %d bytes\n", |
| 19228 | | - iCur); |
| 19986 | + oputf("Pager Heap Usage: %d bytes\n", iCur); |
| 19229 | 19987 | iHiwtr = iCur = -1; |
| 19230 | 19988 | sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1); |
| 19231 | | - raw_printf(pArg->out, "Page cache hits: %d\n", iCur); |
| 19989 | + oputf("Page cache hits: %d\n", iCur); |
| 19232 | 19990 | iHiwtr = iCur = -1; |
| 19233 | 19991 | sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1); |
| 19234 | | - raw_printf(pArg->out, "Page cache misses: %d\n", iCur); |
| 19992 | + oputf("Page cache misses: %d\n", iCur); |
| 19235 | 19993 | iHiwtr = iCur = -1; |
| 19236 | 19994 | sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1); |
| 19237 | | - raw_printf(pArg->out, "Page cache writes: %d\n", iCur); |
| 19995 | + oputf("Page cache writes: %d\n", iCur); |
| 19238 | 19996 | iHiwtr = iCur = -1; |
| 19239 | 19997 | sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_SPILL, &iCur, &iHiwtr, 1); |
| 19240 | | - raw_printf(pArg->out, "Page cache spills: %d\n", iCur); |
| 19998 | + oputf("Page cache spills: %d\n", iCur); |
| 19241 | 19999 | iHiwtr = iCur = -1; |
| 19242 | 20000 | sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset); |
| 19243 | | - raw_printf(pArg->out, "Schema Heap Usage: %d bytes\n", |
| 19244 | | - iCur); |
| 20001 | + oputf("Schema Heap Usage: %d bytes\n", iCur); |
| 19245 | 20002 | iHiwtr = iCur = -1; |
| 19246 | 20003 | sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset); |
| 19247 | | - raw_printf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", |
| 19248 | | - iCur); |
| 20004 | + oputf("Statement Heap/Lookaside Usage: %d bytes\n", iCur); |
| 19249 | 20005 | } |
| 19250 | 20006 | |
| 19251 | 20007 | if( pArg->pStmt ){ |
| 19252 | 20008 | int iHit, iMiss; |
| 19253 | 20009 | iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, |
| 19254 | 20010 | bReset); |
| 19255 | | - raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur); |
| 20011 | + oputf("Fullscan Steps: %d\n", iCur); |
| 19256 | 20012 | iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset); |
| 19257 | | - raw_printf(pArg->out, "Sort Operations: %d\n", iCur); |
| 20013 | + oputf("Sort Operations: %d\n", iCur); |
| 19258 | 20014 | iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset); |
| 19259 | | - raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur); |
| 20015 | + oputf("Autoindex Inserts: %d\n", iCur); |
| 19260 | 20016 | iHit = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_HIT, |
| 19261 | 20017 | bReset); |
| 19262 | 20018 | iMiss = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_MISS, |
| 19263 | 20019 | bReset); |
| 19264 | 20020 | if( iHit || iMiss ){ |
| 19265 | | - raw_printf(pArg->out, "Bloom filter bypass taken: %d/%d\n", |
| 19266 | | - iHit, iHit+iMiss); |
| 20021 | + oputf("Bloom filter bypass taken: %d/%d\n", iHit, iHit+iMiss); |
| 19267 | 20022 | } |
| 19268 | 20023 | iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset); |
| 19269 | | - raw_printf(pArg->out, "Virtual Machine Steps: %d\n", iCur); |
| 20024 | + oputf("Virtual Machine Steps: %d\n", iCur); |
| 19270 | 20025 | iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_REPREPARE,bReset); |
| 19271 | | - raw_printf(pArg->out, "Reprepare operations: %d\n", iCur); |
| 20026 | + oputf("Reprepare operations: %d\n", iCur); |
| 19272 | 20027 | iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_RUN, bReset); |
| 19273 | | - raw_printf(pArg->out, "Number of times run: %d\n", iCur); |
| 20028 | + oputf("Number of times run: %d\n", iCur); |
| 19274 | 20029 | iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_MEMUSED, bReset); |
| 19275 | | - raw_printf(pArg->out, "Memory used by prepared stmt: %d\n", iCur); |
| 20030 | + oputf("Memory used by prepared stmt: %d\n", iCur); |
| 19276 | 20031 | } |
| 19277 | 20032 | |
| 19278 | 20033 | #ifdef __linux__ |
| 19279 | | - displayLinuxIoStats(pArg->out); |
| 20034 | + displayLinuxIoStats(); |
| 19280 | 20035 | #endif |
| 19281 | 20036 | |
| 19282 | 20037 | /* Do not remove this machine readable comment: extra-stats-output-here */ |
| 19283 | 20038 | |
| 19284 | 20039 | return 0; |
| | @@ -19509,11 +20264,11 @@ |
| 19509 | 20264 | #ifndef SQLITE_ENABLE_STMT_SCANSTATUS |
| 19510 | 20265 | UNUSED_PARAMETER(db); |
| 19511 | 20266 | UNUSED_PARAMETER(pArg); |
| 19512 | 20267 | #else |
| 19513 | 20268 | if( pArg->scanstatsOn==3 ){ |
| 19514 | | - const char *zSql = |
| 20269 | + const char *zSql = |
| 19515 | 20270 | " SELECT addr, opcode, p1, p2, p3, p4, p5, comment, nexec," |
| 19516 | 20271 | " round(ncycle*100.0 / (sum(ncycle) OVER ()), 2)||'%' AS cycles" |
| 19517 | 20272 | " FROM bytecode(?)"; |
| 19518 | 20273 | |
| 19519 | 20274 | int rc = SQLITE_OK; |
| | @@ -19655,21 +20410,21 @@ |
| 19655 | 20410 | #define BOX_1234 "\342\224\274" /* U+253c -|- */ |
| 19656 | 20411 | |
| 19657 | 20412 | /* Draw horizontal line N characters long using unicode box |
| 19658 | 20413 | ** characters |
| 19659 | 20414 | */ |
| 19660 | | -static void print_box_line(FILE *out, int N){ |
| 20415 | +static void print_box_line(int N){ |
| 19661 | 20416 | const char zDash[] = |
| 19662 | 20417 | BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 |
| 19663 | 20418 | BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24; |
| 19664 | 20419 | const int nDash = sizeof(zDash) - 1; |
| 19665 | 20420 | N *= 3; |
| 19666 | 20421 | while( N>nDash ){ |
| 19667 | | - utf8_printf(out, zDash); |
| 20422 | + oputz(zDash); |
| 19668 | 20423 | N -= nDash; |
| 19669 | 20424 | } |
| 19670 | | - utf8_printf(out, "%.*s", N, zDash); |
| 20425 | + oputf("%.*s", N, zDash); |
| 19671 | 20426 | } |
| 19672 | 20427 | |
| 19673 | 20428 | /* |
| 19674 | 20429 | ** Draw a horizontal separator for a MODE_Box table. |
| 19675 | 20430 | */ |
| | @@ -19680,19 +20435,19 @@ |
| 19680 | 20435 | const char *zSep2, |
| 19681 | 20436 | const char *zSep3 |
| 19682 | 20437 | ){ |
| 19683 | 20438 | int i; |
| 19684 | 20439 | if( nArg>0 ){ |
| 19685 | | - utf8_printf(p->out, "%s", zSep1); |
| 19686 | | - print_box_line(p->out, p->actualWidth[0]+2); |
| 20440 | + oputz(zSep1); |
| 20441 | + print_box_line(p->actualWidth[0]+2); |
| 19687 | 20442 | for(i=1; i<nArg; i++){ |
| 19688 | | - utf8_printf(p->out, "%s", zSep2); |
| 19689 | | - print_box_line(p->out, p->actualWidth[i]+2); |
| 20443 | + oputz(zSep2); |
| 20444 | + print_box_line(p->actualWidth[i]+2); |
| 19690 | 20445 | } |
| 19691 | | - utf8_printf(p->out, "%s", zSep3); |
| 20446 | + oputz(zSep3); |
| 19692 | 20447 | } |
| 19693 | | - fputs("\n", p->out); |
| 20448 | + oputz("\n"); |
| 19694 | 20449 | } |
| 19695 | 20450 | |
| 19696 | 20451 | /* |
| 19697 | 20452 | ** z[] is a line of text that is to be displayed the .mode box or table or |
| 19698 | 20453 | ** similar tabular formats. z[] might contain control characters such |
| | @@ -19951,15 +20706,15 @@ |
| 19951 | 20706 | rowSep = "\n"; |
| 19952 | 20707 | if( p->showHeader ){ |
| 19953 | 20708 | for(i=0; i<nColumn; i++){ |
| 19954 | 20709 | w = p->actualWidth[i]; |
| 19955 | 20710 | if( p->colWidth[i]<0 ) w = -w; |
| 19956 | | - utf8_width_print(p->out, w, azData[i]); |
| 20711 | + utf8_width_print(w, azData[i]); |
| 19957 | 20712 | fputs(i==nColumn-1?"\n":" ", p->out); |
| 19958 | 20713 | } |
| 19959 | 20714 | for(i=0; i<nColumn; i++){ |
| 19960 | | - print_dashes(p->out, p->actualWidth[i]); |
| 20715 | + print_dashes(p->actualWidth[i]); |
| 19961 | 20716 | fputs(i==nColumn-1?"\n":" ", p->out); |
| 19962 | 20717 | } |
| 19963 | 20718 | } |
| 19964 | 20719 | break; |
| 19965 | 20720 | } |
| | @@ -19969,12 +20724,12 @@ |
| 19969 | 20724 | print_row_separator(p, nColumn, "+"); |
| 19970 | 20725 | fputs("| ", p->out); |
| 19971 | 20726 | for(i=0; i<nColumn; i++){ |
| 19972 | 20727 | w = p->actualWidth[i]; |
| 19973 | 20728 | n = strlenChar(azData[i]); |
| 19974 | | - utf8_printf(p->out, "%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, ""); |
| 19975 | | - fputs(i==nColumn-1?" |\n":" | ", p->out); |
| 20729 | + oputf("%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, ""); |
| 20730 | + oputz(i==nColumn-1?" |\n":" | "); |
| 19976 | 20731 | } |
| 19977 | 20732 | print_row_separator(p, nColumn, "+"); |
| 19978 | 20733 | break; |
| 19979 | 20734 | } |
| 19980 | 20735 | case MODE_Markdown: { |
| | @@ -19982,66 +20737,66 @@ |
| 19982 | 20737 | rowSep = " |\n"; |
| 19983 | 20738 | fputs("| ", p->out); |
| 19984 | 20739 | for(i=0; i<nColumn; i++){ |
| 19985 | 20740 | w = p->actualWidth[i]; |
| 19986 | 20741 | n = strlenChar(azData[i]); |
| 19987 | | - utf8_printf(p->out, "%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, ""); |
| 19988 | | - fputs(i==nColumn-1?" |\n":" | ", p->out); |
| 20742 | + oputf("%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, ""); |
| 20743 | + oputz(i==nColumn-1?" |\n":" | "); |
| 19989 | 20744 | } |
| 19990 | 20745 | print_row_separator(p, nColumn, "|"); |
| 19991 | 20746 | break; |
| 19992 | 20747 | } |
| 19993 | 20748 | case MODE_Box: { |
| 19994 | 20749 | colSep = " " BOX_13 " "; |
| 19995 | 20750 | rowSep = " " BOX_13 "\n"; |
| 19996 | 20751 | print_box_row_separator(p, nColumn, BOX_23, BOX_234, BOX_34); |
| 19997 | | - utf8_printf(p->out, BOX_13 " "); |
| 20752 | + oputz(BOX_13 " "); |
| 19998 | 20753 | for(i=0; i<nColumn; i++){ |
| 19999 | 20754 | w = p->actualWidth[i]; |
| 20000 | 20755 | n = strlenChar(azData[i]); |
| 20001 | | - utf8_printf(p->out, "%*s%s%*s%s", |
| 20002 | | - (w-n)/2, "", azData[i], (w-n+1)/2, "", |
| 20003 | | - i==nColumn-1?" "BOX_13"\n":" "BOX_13" "); |
| 20756 | + oputf("%*s%s%*s%s", |
| 20757 | + (w-n)/2, "", azData[i], (w-n+1)/2, "", |
| 20758 | + i==nColumn-1?" "BOX_13"\n":" "BOX_13" "); |
| 20004 | 20759 | } |
| 20005 | 20760 | print_box_row_separator(p, nColumn, BOX_123, BOX_1234, BOX_134); |
| 20006 | 20761 | break; |
| 20007 | 20762 | } |
| 20008 | 20763 | } |
| 20009 | 20764 | for(i=nColumn, j=0; i<nTotal; i++, j++){ |
| 20010 | 20765 | if( j==0 && p->cMode!=MODE_Column ){ |
| 20011 | | - utf8_printf(p->out, "%s", p->cMode==MODE_Box?BOX_13" ":"| "); |
| 20766 | + oputz(p->cMode==MODE_Box?BOX_13" ":"| "); |
| 20012 | 20767 | } |
| 20013 | 20768 | z = azData[i]; |
| 20014 | 20769 | if( z==0 ) z = p->nullValue; |
| 20015 | 20770 | w = p->actualWidth[j]; |
| 20016 | 20771 | if( p->colWidth[j]<0 ) w = -w; |
| 20017 | | - utf8_width_print(p->out, w, z); |
| 20772 | + utf8_width_print(w, z); |
| 20018 | 20773 | if( j==nColumn-1 ){ |
| 20019 | | - utf8_printf(p->out, "%s", rowSep); |
| 20774 | + oputz(rowSep); |
| 20020 | 20775 | if( bMultiLineRowExists && abRowDiv[i/nColumn-1] && i+1<nTotal ){ |
| 20021 | 20776 | if( p->cMode==MODE_Table ){ |
| 20022 | 20777 | print_row_separator(p, nColumn, "+"); |
| 20023 | 20778 | }else if( p->cMode==MODE_Box ){ |
| 20024 | 20779 | print_box_row_separator(p, nColumn, BOX_123, BOX_1234, BOX_134); |
| 20025 | 20780 | }else if( p->cMode==MODE_Column ){ |
| 20026 | | - raw_printf(p->out, "\n"); |
| 20781 | + oputz("\n"); |
| 20027 | 20782 | } |
| 20028 | 20783 | } |
| 20029 | 20784 | j = -1; |
| 20030 | 20785 | if( seenInterrupt ) goto columnar_end; |
| 20031 | 20786 | }else{ |
| 20032 | | - utf8_printf(p->out, "%s", colSep); |
| 20787 | + oputz(colSep); |
| 20033 | 20788 | } |
| 20034 | 20789 | } |
| 20035 | 20790 | if( p->cMode==MODE_Table ){ |
| 20036 | 20791 | print_row_separator(p, nColumn, "+"); |
| 20037 | 20792 | }else if( p->cMode==MODE_Box ){ |
| 20038 | 20793 | print_box_row_separator(p, nColumn, BOX_12, BOX_124, BOX_14); |
| 20039 | 20794 | } |
| 20040 | 20795 | columnar_end: |
| 20041 | 20796 | if( seenInterrupt ){ |
| 20042 | | - utf8_printf(p->out, "Interrupt\n"); |
| 20797 | + oputz("Interrupt\n"); |
| 20043 | 20798 | } |
| 20044 | 20799 | nData = (nRow+1)*nColumn; |
| 20045 | 20800 | for(i=0; i<nData; i++){ |
| 20046 | 20801 | z = azData[i]; |
| 20047 | 20802 | if( z!=zEmpty && z!=zShowNull ) free(azData[i]); |
| | @@ -20176,34 +20931,33 @@ |
| 20176 | 20931 | int rc = SQLITE_OK; |
| 20177 | 20932 | sqlite3expert *p = pState->expert.pExpert; |
| 20178 | 20933 | assert( p ); |
| 20179 | 20934 | assert( bCancel || pzErr==0 || *pzErr==0 ); |
| 20180 | 20935 | if( bCancel==0 ){ |
| 20181 | | - FILE *out = pState->out; |
| 20182 | 20936 | int bVerbose = pState->expert.bVerbose; |
| 20183 | 20937 | |
| 20184 | 20938 | rc = sqlite3_expert_analyze(p, pzErr); |
| 20185 | 20939 | if( rc==SQLITE_OK ){ |
| 20186 | 20940 | int nQuery = sqlite3_expert_count(p); |
| 20187 | 20941 | int i; |
| 20188 | 20942 | |
| 20189 | 20943 | if( bVerbose ){ |
| 20190 | 20944 | const char *zCand = sqlite3_expert_report(p,0,EXPERT_REPORT_CANDIDATES); |
| 20191 | | - raw_printf(out, "-- Candidates -----------------------------\n"); |
| 20192 | | - raw_printf(out, "%s\n", zCand); |
| 20945 | + oputz("-- Candidates -----------------------------\n"); |
| 20946 | + oputf("%s\n", zCand); |
| 20193 | 20947 | } |
| 20194 | 20948 | for(i=0; i<nQuery; i++){ |
| 20195 | 20949 | const char *zSql = sqlite3_expert_report(p, i, EXPERT_REPORT_SQL); |
| 20196 | 20950 | const char *zIdx = sqlite3_expert_report(p, i, EXPERT_REPORT_INDEXES); |
| 20197 | 20951 | const char *zEQP = sqlite3_expert_report(p, i, EXPERT_REPORT_PLAN); |
| 20198 | 20952 | if( zIdx==0 ) zIdx = "(no new indexes)\n"; |
| 20199 | 20953 | if( bVerbose ){ |
| 20200 | | - raw_printf(out, "-- Query %d --------------------------------\n",i+1); |
| 20201 | | - raw_printf(out, "%s\n\n", zSql); |
| 20954 | + oputf("-- Query %d --------------------------------\n",i+1); |
| 20955 | + oputf("%s\n\n", zSql); |
| 20202 | 20956 | } |
| 20203 | | - raw_printf(out, "%s\n", zIdx); |
| 20204 | | - raw_printf(out, "%s\n", zEQP); |
| 20957 | + oputf("%s\n", zIdx); |
| 20958 | + oputf("%s\n", zEQP); |
| 20205 | 20959 | } |
| 20206 | 20960 | } |
| 20207 | 20961 | } |
| 20208 | 20962 | sqlite3_expert_destroy(p); |
| 20209 | 20963 | pState->expert.pExpert = 0; |
| | @@ -20234,31 +20988,30 @@ |
| 20234 | 20988 | if( n>=2 && 0==cli_strncmp(z, "-verbose", n) ){ |
| 20235 | 20989 | pState->expert.bVerbose = 1; |
| 20236 | 20990 | } |
| 20237 | 20991 | else if( n>=2 && 0==cli_strncmp(z, "-sample", n) ){ |
| 20238 | 20992 | if( i==(nArg-1) ){ |
| 20239 | | - raw_printf(stderr, "option requires an argument: %s\n", z); |
| 20993 | + eputf("option requires an argument: %s\n", z); |
| 20240 | 20994 | rc = SQLITE_ERROR; |
| 20241 | 20995 | }else{ |
| 20242 | 20996 | iSample = (int)integerValue(azArg[++i]); |
| 20243 | 20997 | if( iSample<0 || iSample>100 ){ |
| 20244 | | - raw_printf(stderr, "value out of range: %s\n", azArg[i]); |
| 20998 | + eputf("value out of range: %s\n", azArg[i]); |
| 20245 | 20999 | rc = SQLITE_ERROR; |
| 20246 | 21000 | } |
| 20247 | 21001 | } |
| 20248 | 21002 | } |
| 20249 | 21003 | else{ |
| 20250 | | - raw_printf(stderr, "unknown option: %s\n", z); |
| 21004 | + eputf("unknown option: %s\n", z); |
| 20251 | 21005 | rc = SQLITE_ERROR; |
| 20252 | 21006 | } |
| 20253 | 21007 | } |
| 20254 | 21008 | |
| 20255 | 21009 | if( rc==SQLITE_OK ){ |
| 20256 | 21010 | pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr); |
| 20257 | 21011 | if( pState->expert.pExpert==0 ){ |
| 20258 | | - raw_printf(stderr, "sqlite3_expert_new: %s\n", |
| 20259 | | - zErr ? zErr : "out of memory"); |
| 21012 | + eputf("sqlite3_expert_new: %s\n", zErr ? zErr : "out of memory"); |
| 20260 | 21013 | rc = SQLITE_ERROR; |
| 20261 | 21014 | }else{ |
| 20262 | 21015 | sqlite3_expert_config( |
| 20263 | 21016 | pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample |
| 20264 | 21017 | ); |
| | @@ -20581,33 +21334,33 @@ |
| 20581 | 21334 | if( zType==0 ) return 0; |
| 20582 | 21335 | dataOnly = (p->shellFlgs & SHFLG_DumpDataOnly)!=0; |
| 20583 | 21336 | noSys = (p->shellFlgs & SHFLG_DumpNoSys)!=0; |
| 20584 | 21337 | |
| 20585 | 21338 | if( cli_strcmp(zTable, "sqlite_sequence")==0 && !noSys ){ |
| 20586 | | - if( !dataOnly ) raw_printf(p->out, "DELETE FROM sqlite_sequence;\n"); |
| 21339 | + if( !dataOnly ) oputz("DELETE FROM sqlite_sequence;\n"); |
| 20587 | 21340 | }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 && !noSys ){ |
| 20588 | | - if( !dataOnly ) raw_printf(p->out, "ANALYZE sqlite_schema;\n"); |
| 21341 | + if( !dataOnly ) oputz("ANALYZE sqlite_schema;\n"); |
| 20589 | 21342 | }else if( cli_strncmp(zTable, "sqlite_", 7)==0 ){ |
| 20590 | 21343 | return 0; |
| 20591 | 21344 | }else if( dataOnly ){ |
| 20592 | 21345 | /* no-op */ |
| 20593 | 21346 | }else if( cli_strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ |
| 20594 | 21347 | char *zIns; |
| 20595 | 21348 | if( !p->writableSchema ){ |
| 20596 | | - raw_printf(p->out, "PRAGMA writable_schema=ON;\n"); |
| 21349 | + oputz("PRAGMA writable_schema=ON;\n"); |
| 20597 | 21350 | p->writableSchema = 1; |
| 20598 | 21351 | } |
| 20599 | 21352 | zIns = sqlite3_mprintf( |
| 20600 | 21353 | "INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)" |
| 20601 | 21354 | "VALUES('table','%q','%q',0,'%q');", |
| 20602 | 21355 | zTable, zTable, zSql); |
| 20603 | 21356 | shell_check_oom(zIns); |
| 20604 | | - utf8_printf(p->out, "%s\n", zIns); |
| 21357 | + oputf("%s\n", zIns); |
| 20605 | 21358 | sqlite3_free(zIns); |
| 20606 | 21359 | return 0; |
| 20607 | 21360 | }else{ |
| 20608 | | - printSchemaLine(p->out, zSql, ";\n"); |
| 21361 | + printSchemaLine(zSql, ";\n"); |
| 20609 | 21362 | } |
| 20610 | 21363 | |
| 20611 | 21364 | if( cli_strcmp(zType, "table")==0 ){ |
| 20612 | 21365 | ShellText sSelect; |
| 20613 | 21366 | ShellText sTable; |
| | @@ -20661,11 +21414,11 @@ |
| 20661 | 21414 | savedMode = p->mode; |
| 20662 | 21415 | p->zDestTable = sTable.z; |
| 20663 | 21416 | p->mode = p->cMode = MODE_Insert; |
| 20664 | 21417 | rc = shell_exec(p, sSelect.z, 0); |
| 20665 | 21418 | if( (rc&0xff)==SQLITE_CORRUPT ){ |
| 20666 | | - raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n"); |
| 21419 | + oputz("/****** CORRUPTION ERROR *******/\n"); |
| 20667 | 21420 | toggleSelectOrder(p->db); |
| 20668 | 21421 | shell_exec(p, sSelect.z, 0); |
| 20669 | 21422 | toggleSelectOrder(p->db); |
| 20670 | 21423 | } |
| 20671 | 21424 | p->zDestTable = savedDestTable; |
| | @@ -20692,22 +21445,22 @@ |
| 20692 | 21445 | char *zErr = 0; |
| 20693 | 21446 | rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr); |
| 20694 | 21447 | if( rc==SQLITE_CORRUPT ){ |
| 20695 | 21448 | char *zQ2; |
| 20696 | 21449 | int len = strlen30(zQuery); |
| 20697 | | - raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n"); |
| 21450 | + oputz("/****** CORRUPTION ERROR *******/\n"); |
| 20698 | 21451 | if( zErr ){ |
| 20699 | | - utf8_printf(p->out, "/****** %s ******/\n", zErr); |
| 21452 | + oputf("/****** %s ******/\n", zErr); |
| 20700 | 21453 | sqlite3_free(zErr); |
| 20701 | 21454 | zErr = 0; |
| 20702 | 21455 | } |
| 20703 | 21456 | zQ2 = malloc( len+100 ); |
| 20704 | 21457 | if( zQ2==0 ) return rc; |
| 20705 | 21458 | sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery); |
| 20706 | 21459 | rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr); |
| 20707 | 21460 | if( rc ){ |
| 20708 | | - utf8_printf(p->out, "/****** ERROR: %s ******/\n", zErr); |
| 21461 | + oputf("/****** ERROR: %s ******/\n", zErr); |
| 20709 | 21462 | }else{ |
| 20710 | 21463 | rc = SQLITE_CORRUPT; |
| 20711 | 21464 | } |
| 20712 | 21465 | sqlite3_free(zErr); |
| 20713 | 21466 | free(zQ2); |
| | @@ -21059,24 +21812,24 @@ |
| 21059 | 21812 | hh &= ~HH_Summary; |
| 21060 | 21813 | break; |
| 21061 | 21814 | } |
| 21062 | 21815 | if( ((hw^hh)&HH_Undoc)==0 ){ |
| 21063 | 21816 | if( (hh&HH_Summary)!=0 ){ |
| 21064 | | - utf8_printf(out, ".%s\n", azHelp[i]+1); |
| 21817 | + sputf(out, ".%s\n", azHelp[i]+1); |
| 21065 | 21818 | ++n; |
| 21066 | 21819 | }else if( (hw&HW_SummaryOnly)==0 ){ |
| 21067 | | - utf8_printf(out, "%s\n", azHelp[i]); |
| 21820 | + sputf(out, "%s\n", azHelp[i]); |
| 21068 | 21821 | } |
| 21069 | 21822 | } |
| 21070 | 21823 | } |
| 21071 | 21824 | }else{ |
| 21072 | 21825 | /* Seek documented commands for which zPattern is an exact prefix */ |
| 21073 | 21826 | zPat = sqlite3_mprintf(".%s*", zPattern); |
| 21074 | 21827 | shell_check_oom(zPat); |
| 21075 | 21828 | for(i=0; i<ArraySize(azHelp); i++){ |
| 21076 | 21829 | if( sqlite3_strglob(zPat, azHelp[i])==0 ){ |
| 21077 | | - utf8_printf(out, "%s\n", azHelp[i]); |
| 21830 | + sputf(out, "%s\n", azHelp[i]); |
| 21078 | 21831 | j = i+1; |
| 21079 | 21832 | n++; |
| 21080 | 21833 | } |
| 21081 | 21834 | } |
| 21082 | 21835 | sqlite3_free(zPat); |
| | @@ -21083,11 +21836,11 @@ |
| 21083 | 21836 | if( n ){ |
| 21084 | 21837 | if( n==1 ){ |
| 21085 | 21838 | /* when zPattern is a prefix of exactly one command, then include |
| 21086 | 21839 | ** the details of that command, which should begin at offset j */ |
| 21087 | 21840 | while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){ |
| 21088 | | - utf8_printf(out, "%s\n", azHelp[j]); |
| 21841 | + sputf(out, "%s\n", azHelp[j]); |
| 21089 | 21842 | j++; |
| 21090 | 21843 | } |
| 21091 | 21844 | } |
| 21092 | 21845 | return n; |
| 21093 | 21846 | } |
| | @@ -21100,14 +21853,14 @@ |
| 21100 | 21853 | while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i; |
| 21101 | 21854 | continue; |
| 21102 | 21855 | } |
| 21103 | 21856 | if( azHelp[i][0]=='.' ) j = i; |
| 21104 | 21857 | if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){ |
| 21105 | | - utf8_printf(out, "%s\n", azHelp[j]); |
| 21858 | + sputf(out, "%s\n", azHelp[j]); |
| 21106 | 21859 | while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){ |
| 21107 | 21860 | j++; |
| 21108 | | - utf8_printf(out, "%s\n", azHelp[j]); |
| 21861 | + sputf(out, "%s\n", azHelp[j]); |
| 21109 | 21862 | } |
| 21110 | 21863 | i = j; |
| 21111 | 21864 | n++; |
| 21112 | 21865 | } |
| 21113 | 21866 | } |
| | @@ -21141,27 +21894,27 @@ |
| 21141 | 21894 | char *pBuf; |
| 21142 | 21895 | int rc; |
| 21143 | 21896 | if( in==0 ) return 0; |
| 21144 | 21897 | rc = fseek(in, 0, SEEK_END); |
| 21145 | 21898 | if( rc!=0 ){ |
| 21146 | | - raw_printf(stderr, "Error: '%s' not seekable\n", zName); |
| 21899 | + eputf("Error: '%s' not seekable\n", zName); |
| 21147 | 21900 | fclose(in); |
| 21148 | 21901 | return 0; |
| 21149 | 21902 | } |
| 21150 | 21903 | nIn = ftell(in); |
| 21151 | 21904 | rewind(in); |
| 21152 | 21905 | pBuf = sqlite3_malloc64( nIn+1 ); |
| 21153 | 21906 | if( pBuf==0 ){ |
| 21154 | | - raw_printf(stderr, "Error: out of memory\n"); |
| 21907 | + eputz("Error: out of memory\n"); |
| 21155 | 21908 | fclose(in); |
| 21156 | 21909 | return 0; |
| 21157 | 21910 | } |
| 21158 | 21911 | nRead = fread(pBuf, nIn, 1, in); |
| 21159 | 21912 | fclose(in); |
| 21160 | 21913 | if( nRead!=1 ){ |
| 21161 | 21914 | sqlite3_free(pBuf); |
| 21162 | | - raw_printf(stderr, "Error: cannot read '%s'\n", zName); |
| 21915 | + eputf("Error: cannot read '%s'\n", zName); |
| 21163 | 21916 | return 0; |
| 21164 | 21917 | } |
| 21165 | 21918 | pBuf[nIn] = 0; |
| 21166 | 21919 | if( pnByte ) *pnByte = nIn; |
| 21167 | 21920 | return pBuf; |
| | @@ -21278,11 +22031,11 @@ |
| 21278 | 22031 | unsigned int x[16]; |
| 21279 | 22032 | char zLine[1000]; |
| 21280 | 22033 | if( zDbFilename ){ |
| 21281 | 22034 | in = fopen(zDbFilename, "r"); |
| 21282 | 22035 | if( in==0 ){ |
| 21283 | | - utf8_printf(stderr, "cannot open \"%s\" for reading\n", zDbFilename); |
| 22036 | + eputf("cannot open \"%s\" for reading\n", zDbFilename); |
| 21284 | 22037 | return 0; |
| 21285 | 22038 | } |
| 21286 | 22039 | nLine = 0; |
| 21287 | 22040 | }else{ |
| 21288 | 22041 | in = p->in; |
| | @@ -21299,11 +22052,11 @@ |
| 21299 | 22052 | n = (n+pgsz-1)&~(pgsz-1); /* Round n up to the next multiple of pgsz */ |
| 21300 | 22053 | a = sqlite3_malloc( n ? n : 1 ); |
| 21301 | 22054 | shell_check_oom(a); |
| 21302 | 22055 | memset(a, 0, n); |
| 21303 | 22056 | if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){ |
| 21304 | | - utf8_printf(stderr, "invalid pagesize\n"); |
| 22057 | + eputz("invalid pagesize\n"); |
| 21305 | 22058 | goto readHexDb_error; |
| 21306 | 22059 | } |
| 21307 | 22060 | for(nLine++; fgets(zLine, sizeof(zLine), in)!=0; nLine++){ |
| 21308 | 22061 | rc = sscanf(zLine, "| page %d offset %d", &j, &k); |
| 21309 | 22062 | if( rc==2 ){ |
| | @@ -21341,11 +22094,11 @@ |
| 21341 | 22094 | if(cli_strncmp(zLine, "| end ", 6)==0 ) break; |
| 21342 | 22095 | } |
| 21343 | 22096 | p->lineno = nLine; |
| 21344 | 22097 | } |
| 21345 | 22098 | sqlite3_free(a); |
| 21346 | | - utf8_printf(stderr,"Error on line %d of --hexdb input\n", nLine); |
| 22099 | + eputf("Error on line %d of --hexdb input\n", nLine); |
| 21347 | 22100 | return 0; |
| 21348 | 22101 | } |
| 21349 | 22102 | #endif /* SQLITE_OMIT_DESERIALIZE */ |
| 21350 | 22103 | |
| 21351 | 22104 | /* |
| | @@ -21417,26 +22170,23 @@ |
| 21417 | 22170 | break; |
| 21418 | 22171 | } |
| 21419 | 22172 | } |
| 21420 | 22173 | globalDb = p->db; |
| 21421 | 22174 | if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ |
| 21422 | | - utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n", |
| 21423 | | - zDbFilename, sqlite3_errmsg(p->db)); |
| 22175 | + eputf("Error: unable to open database \"%s\": %s\n", |
| 22176 | + zDbFilename, sqlite3_errmsg(p->db)); |
| 21424 | 22177 | if( (openFlags & OPEN_DB_KEEPALIVE)==0 ){ |
| 21425 | 22178 | exit(1); |
| 21426 | 22179 | } |
| 21427 | 22180 | sqlite3_close(p->db); |
| 21428 | 22181 | sqlite3_open(":memory:", &p->db); |
| 21429 | 22182 | if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ |
| 21430 | | - utf8_printf(stderr, |
| 21431 | | - "Also: unable to open substitute in-memory database.\n" |
| 21432 | | - ); |
| 22183 | + eputz("Also: unable to open substitute in-memory database.\n"); |
| 21433 | 22184 | exit(1); |
| 21434 | 22185 | }else{ |
| 21435 | | - utf8_printf(stderr, |
| 21436 | | - "Notice: using substitute in-memory database instead of \"%s\"\n", |
| 21437 | | - zDbFilename); |
| 22186 | + eputf("Notice: using substitute in-memory database instead of \"%s\"\n", |
| 22187 | + zDbFilename); |
| 21438 | 22188 | } |
| 21439 | 22189 | } |
| 21440 | 22190 | sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0); |
| 21441 | 22191 | |
| 21442 | 22192 | /* Reflect the use or absence of --unsafe-testing invocation. */ |
| | @@ -21539,11 +22289,11 @@ |
| 21539 | 22289 | } |
| 21540 | 22290 | rc = sqlite3_deserialize(p->db, "main", aData, nData, nData, |
| 21541 | 22291 | SQLITE_DESERIALIZE_RESIZEABLE | |
| 21542 | 22292 | SQLITE_DESERIALIZE_FREEONCLOSE); |
| 21543 | 22293 | if( rc ){ |
| 21544 | | - utf8_printf(stderr, "Error: sqlite3_deserialize() returns %d\n", rc); |
| 22294 | + eputf("Error: sqlite3_deserialize() returns %d\n", rc); |
| 21545 | 22295 | } |
| 21546 | 22296 | if( p->szMax>0 ){ |
| 21547 | 22297 | sqlite3_file_control(p->db, "main", SQLITE_FCNTL_SIZE_LIMIT, &p->szMax); |
| 21548 | 22298 | } |
| 21549 | 22299 | } |
| | @@ -21563,12 +22313,11 @@ |
| 21563 | 22313 | ** Attempt to close the database connection. Report errors. |
| 21564 | 22314 | */ |
| 21565 | 22315 | void close_db(sqlite3 *db){ |
| 21566 | 22316 | int rc = sqlite3_close(db); |
| 21567 | 22317 | if( rc ){ |
| 21568 | | - utf8_printf(stderr, "Error: sqlite3_close() returns %d: %s\n", |
| 21569 | | - rc, sqlite3_errmsg(db)); |
| 22318 | + eputf("Error: sqlite3_close() returns %d: %s\n", rc, sqlite3_errmsg(db)); |
| 21570 | 22319 | } |
| 21571 | 22320 | } |
| 21572 | 22321 | |
| 21573 | 22322 | #if HAVE_READLINE || HAVE_EDITLINE |
| 21574 | 22323 | /* |
| | @@ -21725,12 +22474,11 @@ |
| 21725 | 22474 | return 1; |
| 21726 | 22475 | } |
| 21727 | 22476 | if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){ |
| 21728 | 22477 | return 0; |
| 21729 | 22478 | } |
| 21730 | | - utf8_printf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", |
| 21731 | | - zArg); |
| 22479 | + eputf("ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", zArg); |
| 21732 | 22480 | return 0; |
| 21733 | 22481 | } |
| 21734 | 22482 | |
| 21735 | 22483 | /* |
| 21736 | 22484 | ** Set or clear a shell flag according to a boolean value. |
| | @@ -21764,11 +22512,11 @@ |
| 21764 | 22512 | }else if( cli_strcmp(zFile, "off")==0 ){ |
| 21765 | 22513 | f = 0; |
| 21766 | 22514 | }else{ |
| 21767 | 22515 | f = fopen(zFile, bTextMode ? "w" : "wb"); |
| 21768 | 22516 | if( f==0 ){ |
| 21769 | | - utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile); |
| 22517 | + eputf("Error: cannot open \"%s\"\n", zFile); |
| 21770 | 22518 | } |
| 21771 | 22519 | } |
| 21772 | 22520 | return f; |
| 21773 | 22521 | } |
| 21774 | 22522 | |
| | @@ -21786,11 +22534,11 @@ |
| 21786 | 22534 | sqlite3_stmt *pStmt; |
| 21787 | 22535 | const char *zSql; |
| 21788 | 22536 | i64 nSql; |
| 21789 | 22537 | if( p->traceOut==0 ) return 0; |
| 21790 | 22538 | if( mType==SQLITE_TRACE_CLOSE ){ |
| 21791 | | - utf8_printf(p->traceOut, "-- closing database connection\n"); |
| 22539 | + sputz(p->traceOut, "-- closing database connection\n"); |
| 21792 | 22540 | return 0; |
| 21793 | 22541 | } |
| 21794 | 22542 | if( mType!=SQLITE_TRACE_ROW && pX!=0 && ((const char*)pX)[0]=='-' ){ |
| 21795 | 22543 | zSql = (const char*)pX; |
| 21796 | 22544 | }else{ |
| | @@ -21817,16 +22565,16 @@ |
| 21817 | 22565 | if( nSql>1000000000 ) nSql = 1000000000; |
| 21818 | 22566 | while( nSql>0 && zSql[nSql-1]==';' ){ nSql--; } |
| 21819 | 22567 | switch( mType ){ |
| 21820 | 22568 | case SQLITE_TRACE_ROW: |
| 21821 | 22569 | case SQLITE_TRACE_STMT: { |
| 21822 | | - utf8_printf(p->traceOut, "%.*s;\n", (int)nSql, zSql); |
| 22570 | + sputf(p->traceOut, "%.*s;\n", (int)nSql, zSql); |
| 21823 | 22571 | break; |
| 21824 | 22572 | } |
| 21825 | 22573 | case SQLITE_TRACE_PROFILE: { |
| 21826 | 22574 | sqlite3_int64 nNanosec = pX ? *(sqlite3_int64*)pX : 0; |
| 21827 | | - utf8_printf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec); |
| 22575 | + sputf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec); |
| 21828 | 22576 | break; |
| 21829 | 22577 | } |
| 21830 | 22578 | } |
| 21831 | 22579 | return 0; |
| 21832 | 22580 | } |
| | @@ -21929,16 +22677,15 @@ |
| 21929 | 22677 | do{ p->n--; }while( p->z[p->n]!=cQuote ); |
| 21930 | 22678 | p->cTerm = c; |
| 21931 | 22679 | break; |
| 21932 | 22680 | } |
| 21933 | 22681 | if( pc==cQuote && c!='\r' ){ |
| 21934 | | - utf8_printf(stderr, "%s:%d: unescaped %c character\n", |
| 21935 | | - p->zFile, p->nLine, cQuote); |
| 22682 | + eputf("%s:%d: unescaped %c character\n", p->zFile, p->nLine, cQuote); |
| 21936 | 22683 | } |
| 21937 | 22684 | if( c==EOF ){ |
| 21938 | | - utf8_printf(stderr, "%s:%d: unterminated %c-quoted field\n", |
| 21939 | | - p->zFile, startLine, cQuote); |
| 22685 | + eputf("%s:%d: unterminated %c-quoted field\n", |
| 22686 | + p->zFile, startLine, cQuote); |
| 21940 | 22687 | p->cTerm = c; |
| 21941 | 22688 | break; |
| 21942 | 22689 | } |
| 21943 | 22690 | import_append_char(p, c); |
| 21944 | 22691 | ppc = pc; |
| | @@ -22032,13 +22779,12 @@ |
| 22032 | 22779 | |
| 22033 | 22780 | zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable); |
| 22034 | 22781 | shell_check_oom(zQuery); |
| 22035 | 22782 | rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); |
| 22036 | 22783 | if( rc ){ |
| 22037 | | - utf8_printf(stderr, "Error %d: %s on [%s]\n", |
| 22038 | | - sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), |
| 22039 | | - zQuery); |
| 22784 | + eputf("Error %d: %s on [%s]\n", |
| 22785 | + sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery); |
| 22040 | 22786 | goto end_data_xfer; |
| 22041 | 22787 | } |
| 22042 | 22788 | n = sqlite3_column_count(pQuery); |
| 22043 | 22789 | zInsert = sqlite3_malloc64(200 + nTable + n*3); |
| 22044 | 22790 | shell_check_oom(zInsert); |
| | @@ -22050,13 +22796,12 @@ |
| 22050 | 22796 | i += 2; |
| 22051 | 22797 | } |
| 22052 | 22798 | memcpy(zInsert+i, ");", 3); |
| 22053 | 22799 | rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0); |
| 22054 | 22800 | if( rc ){ |
| 22055 | | - utf8_printf(stderr, "Error %d: %s on [%s]\n", |
| 22056 | | - sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb), |
| 22057 | | - zInsert); |
| 22801 | + eputf("Error %d: %s on [%s]\n", |
| 22802 | + sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb), zInsert); |
| 22058 | 22803 | goto end_data_xfer; |
| 22059 | 22804 | } |
| 22060 | 22805 | for(k=0; k<2; k++){ |
| 22061 | 22806 | while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){ |
| 22062 | 22807 | for(i=0; i<n; i++){ |
| | @@ -22087,12 +22832,12 @@ |
| 22087 | 22832 | } |
| 22088 | 22833 | } |
| 22089 | 22834 | } /* End for */ |
| 22090 | 22835 | rc = sqlite3_step(pInsert); |
| 22091 | 22836 | if( rc!=SQLITE_OK && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){ |
| 22092 | | - utf8_printf(stderr, "Error %d: %s\n", sqlite3_extended_errcode(newDb), |
| 22093 | | - sqlite3_errmsg(newDb)); |
| 22837 | + eputf("Error %d: %s\n", |
| 22838 | + sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb)); |
| 22094 | 22839 | } |
| 22095 | 22840 | sqlite3_reset(pInsert); |
| 22096 | 22841 | cnt++; |
| 22097 | 22842 | if( (cnt%spinRate)==0 ){ |
| 22098 | 22843 | printf("%c\b", "|/-\\"[(cnt/spinRate)%4]); |
| | @@ -22105,11 +22850,11 @@ |
| 22105 | 22850 | zQuery = sqlite3_mprintf("SELECT * FROM \"%w\" ORDER BY rowid DESC;", |
| 22106 | 22851 | zTable); |
| 22107 | 22852 | shell_check_oom(zQuery); |
| 22108 | 22853 | rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); |
| 22109 | 22854 | if( rc ){ |
| 22110 | | - utf8_printf(stderr, "Warning: cannot step \"%s\" backwards", zTable); |
| 22855 | + eputf("Warning: cannot step \"%s\" backwards", zTable); |
| 22111 | 22856 | break; |
| 22112 | 22857 | } |
| 22113 | 22858 | } /* End for(k=0...) */ |
| 22114 | 22859 | |
| 22115 | 22860 | end_data_xfer: |
| | @@ -22142,62 +22887,60 @@ |
| 22142 | 22887 | zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema" |
| 22143 | 22888 | " WHERE %s ORDER BY rowid ASC", zWhere); |
| 22144 | 22889 | shell_check_oom(zQuery); |
| 22145 | 22890 | rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); |
| 22146 | 22891 | if( rc ){ |
| 22147 | | - utf8_printf(stderr, "Error: (%d) %s on [%s]\n", |
| 22148 | | - sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), |
| 22149 | | - zQuery); |
| 22892 | + eputf("Error: (%d) %s on [%s]\n", sqlite3_extended_errcode(p->db), |
| 22893 | + sqlite3_errmsg(p->db), zQuery); |
| 22150 | 22894 | goto end_schema_xfer; |
| 22151 | 22895 | } |
| 22152 | 22896 | while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){ |
| 22153 | 22897 | zName = sqlite3_column_text(pQuery, 0); |
| 22154 | 22898 | zSql = sqlite3_column_text(pQuery, 1); |
| 22155 | 22899 | if( zName==0 || zSql==0 ) continue; |
| 22156 | 22900 | if( sqlite3_stricmp((char*)zName, "sqlite_sequence")!=0 ){ |
| 22157 | | - printf("%s... ", zName); fflush(stdout); |
| 22901 | + sputf(stdout, "%s... ", zName); fflush(stdout); |
| 22158 | 22902 | sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg); |
| 22159 | 22903 | if( zErrMsg ){ |
| 22160 | | - utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql); |
| 22904 | + eputf("Error: %s\nSQL: [%s]\n", zErrMsg, zSql); |
| 22161 | 22905 | sqlite3_free(zErrMsg); |
| 22162 | 22906 | zErrMsg = 0; |
| 22163 | 22907 | } |
| 22164 | 22908 | } |
| 22165 | 22909 | if( xForEach ){ |
| 22166 | 22910 | xForEach(p, newDb, (const char*)zName); |
| 22167 | 22911 | } |
| 22168 | | - printf("done\n"); |
| 22912 | + sputz(stdout, "done\n"); |
| 22169 | 22913 | } |
| 22170 | 22914 | if( rc!=SQLITE_DONE ){ |
| 22171 | 22915 | sqlite3_finalize(pQuery); |
| 22172 | 22916 | sqlite3_free(zQuery); |
| 22173 | 22917 | zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema" |
| 22174 | 22918 | " WHERE %s ORDER BY rowid DESC", zWhere); |
| 22175 | 22919 | shell_check_oom(zQuery); |
| 22176 | 22920 | rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); |
| 22177 | 22921 | if( rc ){ |
| 22178 | | - utf8_printf(stderr, "Error: (%d) %s on [%s]\n", |
| 22179 | | - sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), |
| 22180 | | - zQuery); |
| 22922 | + eputf("Error: (%d) %s on [%s]\n", |
| 22923 | + sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery); |
| 22181 | 22924 | goto end_schema_xfer; |
| 22182 | 22925 | } |
| 22183 | 22926 | while( sqlite3_step(pQuery)==SQLITE_ROW ){ |
| 22184 | 22927 | zName = sqlite3_column_text(pQuery, 0); |
| 22185 | 22928 | zSql = sqlite3_column_text(pQuery, 1); |
| 22186 | 22929 | if( zName==0 || zSql==0 ) continue; |
| 22187 | 22930 | if( sqlite3_stricmp((char*)zName, "sqlite_sequence")==0 ) continue; |
| 22188 | | - printf("%s... ", zName); fflush(stdout); |
| 22931 | + sputf(stdout, "%s... ", zName); fflush(stdout); |
| 22189 | 22932 | sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg); |
| 22190 | 22933 | if( zErrMsg ){ |
| 22191 | | - utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql); |
| 22934 | + eputf("Error: %s\nSQL: [%s]\n", zErrMsg, zSql); |
| 22192 | 22935 | sqlite3_free(zErrMsg); |
| 22193 | 22936 | zErrMsg = 0; |
| 22194 | 22937 | } |
| 22195 | 22938 | if( xForEach ){ |
| 22196 | 22939 | xForEach(p, newDb, (const char*)zName); |
| 22197 | 22940 | } |
| 22198 | | - printf("done\n"); |
| 22941 | + sputz(stdout, "done\n"); |
| 22199 | 22942 | } |
| 22200 | 22943 | } |
| 22201 | 22944 | end_schema_xfer: |
| 22202 | 22945 | sqlite3_finalize(pQuery); |
| 22203 | 22946 | sqlite3_free(zQuery); |
| | @@ -22210,17 +22953,16 @@ |
| 22210 | 22953 | */ |
| 22211 | 22954 | static void tryToClone(ShellState *p, const char *zNewDb){ |
| 22212 | 22955 | int rc; |
| 22213 | 22956 | sqlite3 *newDb = 0; |
| 22214 | 22957 | if( access(zNewDb,0)==0 ){ |
| 22215 | | - utf8_printf(stderr, "File \"%s\" already exists.\n", zNewDb); |
| 22958 | + eputf("File \"%s\" already exists.\n", zNewDb); |
| 22216 | 22959 | return; |
| 22217 | 22960 | } |
| 22218 | 22961 | rc = sqlite3_open(zNewDb, &newDb); |
| 22219 | 22962 | if( rc ){ |
| 22220 | | - utf8_printf(stderr, "Cannot create output database: %s\n", |
| 22221 | | - sqlite3_errmsg(newDb)); |
| 22963 | + eputf("Cannot create output database: %s\n", sqlite3_errmsg(newDb)); |
| 22222 | 22964 | }else{ |
| 22223 | 22965 | sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0); |
| 22224 | 22966 | sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0); |
| 22225 | 22967 | tryToCloneSchema(p, newDb, "type='table'", tryToCloneData); |
| 22226 | 22968 | tryToCloneSchema(p, newDb, "type!='table'", 0); |
| | @@ -22227,10 +22969,22 @@ |
| 22227 | 22969 | sqlite3_exec(newDb, "COMMIT;", 0, 0, 0); |
| 22228 | 22970 | sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); |
| 22229 | 22971 | } |
| 22230 | 22972 | close_db(newDb); |
| 22231 | 22973 | } |
| 22974 | + |
| 22975 | +#ifndef SQLITE_SHELL_FIDDLE |
| 22976 | +/* |
| 22977 | +** Change the output stream (file or pipe or console) to something else. |
| 22978 | +*/ |
| 22979 | +static void output_redir(ShellState *p, FILE *pfNew){ |
| 22980 | + if( p->out != stdout ) eputz("Output already redirected.\n"); |
| 22981 | + else{ |
| 22982 | + p->out = pfNew; |
| 22983 | + setOutputStream(pfNew); |
| 22984 | + } |
| 22985 | +} |
| 22232 | 22986 | |
| 22233 | 22987 | /* |
| 22234 | 22988 | ** Change the output file back to stdout. |
| 22235 | 22989 | ** |
| 22236 | 22990 | ** If the p->doXdgOpen flag is set, that means the output was being |
| | @@ -22255,11 +23009,11 @@ |
| 22255 | 23009 | "xdg-open"; |
| 22256 | 23010 | #endif |
| 22257 | 23011 | char *zCmd; |
| 22258 | 23012 | zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile); |
| 22259 | 23013 | if( system(zCmd) ){ |
| 22260 | | - utf8_printf(stderr, "Failed: [%s]\n", zCmd); |
| 23014 | + eputf("Failed: [%s]\n", zCmd); |
| 22261 | 23015 | }else{ |
| 22262 | 23016 | /* Give the start/open/xdg-open command some time to get |
| 22263 | 23017 | ** going before we continue, and potential delete the |
| 22264 | 23018 | ** p->zTempFile data file out from under it */ |
| 22265 | 23019 | sqlite3_sleep(2000); |
| | @@ -22270,11 +23024,16 @@ |
| 22270 | 23024 | } |
| 22271 | 23025 | #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */ |
| 22272 | 23026 | } |
| 22273 | 23027 | p->outfile[0] = 0; |
| 22274 | 23028 | p->out = stdout; |
| 23029 | + setOutputStream(stdout); |
| 22275 | 23030 | } |
| 23031 | +#else |
| 23032 | +# define output_redir(SS,pfO) |
| 23033 | +# define output_reset(SS) |
| 23034 | +#endif |
| 22276 | 23035 | |
| 22277 | 23036 | /* |
| 22278 | 23037 | ** Run an SQL command and return the single integer result. |
| 22279 | 23038 | */ |
| 22280 | 23039 | static int db_int(sqlite3 *db, const char *zSql){ |
| | @@ -22341,11 +23100,11 @@ |
| 22341 | 23100 | if( p->db==0 ) return 1; |
| 22342 | 23101 | rc = sqlite3_prepare_v2(p->db, |
| 22343 | 23102 | "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1", |
| 22344 | 23103 | -1, &pStmt, 0); |
| 22345 | 23104 | if( rc ){ |
| 22346 | | - utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db)); |
| 23105 | + eputf("error: %s\n", sqlite3_errmsg(p->db)); |
| 22347 | 23106 | sqlite3_finalize(pStmt); |
| 22348 | 23107 | return 1; |
| 22349 | 23108 | } |
| 22350 | 23109 | sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC); |
| 22351 | 23110 | if( sqlite3_step(pStmt)==SQLITE_ROW |
| | @@ -22354,32 +23113,32 @@ |
| 22354 | 23113 | const u8 *pb = sqlite3_column_blob(pStmt,0); |
| 22355 | 23114 | shell_check_oom(pb); |
| 22356 | 23115 | memcpy(aHdr, pb, 100); |
| 22357 | 23116 | sqlite3_finalize(pStmt); |
| 22358 | 23117 | }else{ |
| 22359 | | - raw_printf(stderr, "unable to read database header\n"); |
| 23118 | + eputz("unable to read database header\n"); |
| 22360 | 23119 | sqlite3_finalize(pStmt); |
| 22361 | 23120 | return 1; |
| 22362 | 23121 | } |
| 22363 | 23122 | i = get2byteInt(aHdr+16); |
| 22364 | 23123 | if( i==1 ) i = 65536; |
| 22365 | | - utf8_printf(p->out, "%-20s %d\n", "database page size:", i); |
| 22366 | | - utf8_printf(p->out, "%-20s %d\n", "write format:", aHdr[18]); |
| 22367 | | - utf8_printf(p->out, "%-20s %d\n", "read format:", aHdr[19]); |
| 22368 | | - utf8_printf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]); |
| 23124 | + oputf("%-20s %d\n", "database page size:", i); |
| 23125 | + oputf("%-20s %d\n", "write format:", aHdr[18]); |
| 23126 | + oputf("%-20s %d\n", "read format:", aHdr[19]); |
| 23127 | + oputf("%-20s %d\n", "reserved bytes:", aHdr[20]); |
| 22369 | 23128 | for(i=0; i<ArraySize(aField); i++){ |
| 22370 | 23129 | int ofst = aField[i].ofst; |
| 22371 | 23130 | unsigned int val = get4byteInt(aHdr + ofst); |
| 22372 | | - utf8_printf(p->out, "%-20s %u", aField[i].zName, val); |
| 23131 | + oputf("%-20s %u", aField[i].zName, val); |
| 22373 | 23132 | switch( ofst ){ |
| 22374 | 23133 | case 56: { |
| 22375 | | - if( val==1 ) raw_printf(p->out, " (utf8)"); |
| 22376 | | - if( val==2 ) raw_printf(p->out, " (utf16le)"); |
| 22377 | | - if( val==3 ) raw_printf(p->out, " (utf16be)"); |
| 23134 | + if( val==1 ) oputz(" (utf8)"); |
| 23135 | + if( val==2 ) oputz(" (utf16le)"); |
| 23136 | + if( val==3 ) oputz(" (utf16be)"); |
| 22378 | 23137 | } |
| 22379 | 23138 | } |
| 22380 | | - raw_printf(p->out, "\n"); |
| 23139 | + oputz("\n"); |
| 22381 | 23140 | } |
| 22382 | 23141 | if( zDb==0 ){ |
| 22383 | 23142 | zSchemaTab = sqlite3_mprintf("main.sqlite_schema"); |
| 22384 | 23143 | }else if( cli_strcmp(zDb,"temp")==0 ){ |
| 22385 | 23144 | zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_schema"); |
| | @@ -22388,25 +23147,25 @@ |
| 22388 | 23147 | } |
| 22389 | 23148 | for(i=0; i<ArraySize(aQuery); i++){ |
| 22390 | 23149 | char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab); |
| 22391 | 23150 | int val = db_int(p->db, zSql); |
| 22392 | 23151 | sqlite3_free(zSql); |
| 22393 | | - utf8_printf(p->out, "%-20s %d\n", aQuery[i].zName, val); |
| 23152 | + oputf("%-20s %d\n", aQuery[i].zName, val); |
| 22394 | 23153 | } |
| 22395 | 23154 | sqlite3_free(zSchemaTab); |
| 22396 | 23155 | sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion); |
| 22397 | | - utf8_printf(p->out, "%-20s %u\n", "data version", iDataVersion); |
| 23156 | + oputf("%-20s %u\n", "data version", iDataVersion); |
| 22398 | 23157 | return 0; |
| 22399 | 23158 | } |
| 22400 | 23159 | #endif /* SQLITE_SHELL_HAVE_RECOVER */ |
| 22401 | 23160 | |
| 22402 | 23161 | /* |
| 22403 | 23162 | ** Print the current sqlite3_errmsg() value to stderr and return 1. |
| 22404 | 23163 | */ |
| 22405 | 23164 | static int shellDatabaseError(sqlite3 *db){ |
| 22406 | 23165 | const char *zErr = sqlite3_errmsg(db); |
| 22407 | | - utf8_printf(stderr, "Error: %s\n", zErr); |
| 23166 | + eputf("Error: %s\n", zErr); |
| 22408 | 23167 | return 1; |
| 22409 | 23168 | } |
| 22410 | 23169 | |
| 22411 | 23170 | /* |
| 22412 | 23171 | ** Compare the pattern in zGlob[] against the text in z[]. Return TRUE |
| | @@ -22637,11 +23396,10 @@ |
| 22637 | 23396 | ShellState *pState, /* Current shell tool state */ |
| 22638 | 23397 | char **azArg, /* Array of arguments passed to dot command */ |
| 22639 | 23398 | int nArg /* Number of entries in azArg[] */ |
| 22640 | 23399 | ){ |
| 22641 | 23400 | sqlite3 *db = pState->db; /* Database handle to query "main" db of */ |
| 22642 | | - FILE *out = pState->out; /* Stream to write non-error output to */ |
| 22643 | 23401 | int bVerbose = 0; /* If -verbose is present */ |
| 22644 | 23402 | int bGroupByParent = 0; /* If -groupbyparent is present */ |
| 22645 | 23403 | int i; /* To iterate through azArg[] */ |
| 22646 | 23404 | const char *zIndent = ""; /* How much to indent CREATE INDEX by */ |
| 22647 | 23405 | int rc; /* Return code */ |
| | @@ -22719,13 +23477,11 @@ |
| 22719 | 23477 | else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){ |
| 22720 | 23478 | bGroupByParent = 1; |
| 22721 | 23479 | zIndent = " "; |
| 22722 | 23480 | } |
| 22723 | 23481 | else{ |
| 22724 | | - raw_printf(stderr, "Usage: %s %s ?-verbose? ?-groupbyparent?\n", |
| 22725 | | - azArg[0], azArg[1] |
| 22726 | | - ); |
| 23482 | + eputf("Usage: %s %s ?-verbose? ?-groupbyparent?\n", azArg[0], azArg[1]); |
| 22727 | 23483 | return SQLITE_ERROR; |
| 22728 | 23484 | } |
| 22729 | 23485 | } |
| 22730 | 23486 | |
| 22731 | 23487 | /* Register the fkey_collate_clause() SQL function */ |
| | @@ -22765,44 +23521,44 @@ |
| 22765 | 23521 | } |
| 22766 | 23522 | rc = sqlite3_finalize(pExplain); |
| 22767 | 23523 | if( rc!=SQLITE_OK ) break; |
| 22768 | 23524 | |
| 22769 | 23525 | if( res<0 ){ |
| 22770 | | - raw_printf(stderr, "Error: internal error"); |
| 23526 | + eputz("Error: internal error"); |
| 22771 | 23527 | break; |
| 22772 | 23528 | }else{ |
| 22773 | 23529 | if( bGroupByParent |
| 22774 | 23530 | && (bVerbose || res==0) |
| 22775 | 23531 | && (zPrev==0 || sqlite3_stricmp(zParent, zPrev)) |
| 22776 | 23532 | ){ |
| 22777 | | - raw_printf(out, "-- Parent table %s\n", zParent); |
| 23533 | + oputf("-- Parent table %s\n", zParent); |
| 22778 | 23534 | sqlite3_free(zPrev); |
| 22779 | 23535 | zPrev = sqlite3_mprintf("%s", zParent); |
| 22780 | 23536 | } |
| 22781 | 23537 | |
| 22782 | 23538 | if( res==0 ){ |
| 22783 | | - raw_printf(out, "%s%s --> %s\n", zIndent, zCI, zTarget); |
| 23539 | + oputf("%s%s --> %s\n", zIndent, zCI, zTarget); |
| 22784 | 23540 | }else if( bVerbose ){ |
| 22785 | | - raw_printf(out, "%s/* no extra indexes required for %s -> %s */\n", |
| 22786 | | - zIndent, zFrom, zTarget |
| 23541 | + oputf("%s/* no extra indexes required for %s -> %s */\n", |
| 23542 | + zIndent, zFrom, zTarget |
| 22787 | 23543 | ); |
| 22788 | 23544 | } |
| 22789 | 23545 | } |
| 22790 | 23546 | } |
| 22791 | 23547 | sqlite3_free(zPrev); |
| 22792 | 23548 | |
| 22793 | 23549 | if( rc!=SQLITE_OK ){ |
| 22794 | | - raw_printf(stderr, "%s\n", sqlite3_errmsg(db)); |
| 23550 | + eputf("%s\n", sqlite3_errmsg(db)); |
| 22795 | 23551 | } |
| 22796 | 23552 | |
| 22797 | 23553 | rc2 = sqlite3_finalize(pSql); |
| 22798 | 23554 | if( rc==SQLITE_OK && rc2!=SQLITE_OK ){ |
| 22799 | 23555 | rc = rc2; |
| 22800 | | - raw_printf(stderr, "%s\n", sqlite3_errmsg(db)); |
| 23556 | + eputf("%s\n", sqlite3_errmsg(db)); |
| 22801 | 23557 | } |
| 22802 | 23558 | }else{ |
| 22803 | | - raw_printf(stderr, "%s\n", sqlite3_errmsg(db)); |
| 23559 | + eputf("%s\n", sqlite3_errmsg(db)); |
| 22804 | 23560 | } |
| 22805 | 23561 | |
| 22806 | 23562 | return rc; |
| 22807 | 23563 | } |
| 22808 | 23564 | |
| | @@ -22818,13 +23574,13 @@ |
| 22818 | 23574 | n = (nArg>=2 ? strlen30(azArg[1]) : 0); |
| 22819 | 23575 | if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage; |
| 22820 | 23576 | return lintFkeyIndexes(pState, azArg, nArg); |
| 22821 | 23577 | |
| 22822 | 23578 | usage: |
| 22823 | | - raw_printf(stderr, "Usage %s sub-command ?switches...?\n", azArg[0]); |
| 22824 | | - raw_printf(stderr, "Where sub-commands are:\n"); |
| 22825 | | - raw_printf(stderr, " fkey-indexes\n"); |
| 23579 | + eputf("Usage %s sub-command ?switches...?\n", azArg[0]); |
| 23580 | + eputz("Where sub-commands are:\n"); |
| 23581 | + eputz(" fkey-indexes\n"); |
| 22826 | 23582 | return SQLITE_ERROR; |
| 22827 | 23583 | } |
| 22828 | 23584 | |
| 22829 | 23585 | #if !defined SQLITE_OMIT_VIRTUALTABLE |
| 22830 | 23586 | static void shellPrepare( |
| | @@ -22835,13 +23591,11 @@ |
| 22835 | 23591 | ){ |
| 22836 | 23592 | *ppStmt = 0; |
| 22837 | 23593 | if( *pRc==SQLITE_OK ){ |
| 22838 | 23594 | int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0); |
| 22839 | 23595 | if( rc!=SQLITE_OK ){ |
| 22840 | | - raw_printf(stderr, "sql error: %s (%d)\n", |
| 22841 | | - sqlite3_errmsg(db), sqlite3_errcode(db) |
| 22842 | | - ); |
| 23596 | + eputf("sql error: %s (%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); |
| 22843 | 23597 | *pRc = rc; |
| 22844 | 23598 | } |
| 22845 | 23599 | } |
| 22846 | 23600 | } |
| 22847 | 23601 | |
| | @@ -22888,11 +23642,11 @@ |
| 22888 | 23642 | if( pStmt ){ |
| 22889 | 23643 | sqlite3 *db = sqlite3_db_handle(pStmt); |
| 22890 | 23644 | int rc = sqlite3_finalize(pStmt); |
| 22891 | 23645 | if( *pRc==SQLITE_OK ){ |
| 22892 | 23646 | if( rc!=SQLITE_OK ){ |
| 22893 | | - raw_printf(stderr, "SQL error: %s\n", sqlite3_errmsg(db)); |
| 23647 | + eputf("SQL error: %s\n", sqlite3_errmsg(db)); |
| 22894 | 23648 | } |
| 22895 | 23649 | *pRc = rc; |
| 22896 | 23650 | } |
| 22897 | 23651 | } |
| 22898 | 23652 | } |
| | @@ -22909,11 +23663,11 @@ |
| 22909 | 23663 | ){ |
| 22910 | 23664 | int rc = sqlite3_reset(pStmt); |
| 22911 | 23665 | if( *pRc==SQLITE_OK ){ |
| 22912 | 23666 | if( rc!=SQLITE_OK ){ |
| 22913 | 23667 | sqlite3 *db = sqlite3_db_handle(pStmt); |
| 22914 | | - raw_printf(stderr, "SQL error: %s\n", sqlite3_errmsg(db)); |
| 23668 | + eputf("SQL error: %s\n", sqlite3_errmsg(db)); |
| 22915 | 23669 | } |
| 22916 | 23670 | *pRc = rc; |
| 22917 | 23671 | } |
| 22918 | 23672 | } |
| 22919 | 23673 | #endif /* !defined SQLITE_OMIT_VIRTUALTABLE */ |
| | @@ -22959,15 +23713,15 @@ |
| 22959 | 23713 | va_list ap; |
| 22960 | 23714 | char *z; |
| 22961 | 23715 | va_start(ap, zFmt); |
| 22962 | 23716 | z = sqlite3_vmprintf(zFmt, ap); |
| 22963 | 23717 | va_end(ap); |
| 22964 | | - utf8_printf(stderr, "Error: %s\n", z); |
| 23718 | + eputf("Error: %s\n", z); |
| 22965 | 23719 | if( pAr->fromCmdLine ){ |
| 22966 | | - utf8_printf(stderr, "Use \"-A\" for more help\n"); |
| 23720 | + eputz("Use \"-A\" for more help\n"); |
| 22967 | 23721 | }else{ |
| 22968 | | - utf8_printf(stderr, "Use \".archive --help\" for more help\n"); |
| 23722 | + eputz("Use \".archive --help\" for more help\n"); |
| 22969 | 23723 | } |
| 22970 | 23724 | sqlite3_free(z); |
| 22971 | 23725 | return SQLITE_ERROR; |
| 22972 | 23726 | } |
| 22973 | 23727 | |
| | @@ -23063,11 +23817,11 @@ |
| 23063 | 23817 | }; |
| 23064 | 23818 | int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch); |
| 23065 | 23819 | struct ArSwitch *pEnd = &aSwitch[nSwitch]; |
| 23066 | 23820 | |
| 23067 | 23821 | if( nArg<=1 ){ |
| 23068 | | - utf8_printf(stderr, "Wrong number of arguments. Usage:\n"); |
| 23822 | + eputz("Wrong number of arguments. Usage:\n"); |
| 23069 | 23823 | return arUsage(stderr); |
| 23070 | 23824 | }else{ |
| 23071 | 23825 | char *z = azArg[1]; |
| 23072 | 23826 | if( z[0]!='-' ){ |
| 23073 | 23827 | /* Traditional style [tar] invocation */ |
| | @@ -23169,11 +23923,11 @@ |
| 23169 | 23923 | } |
| 23170 | 23924 | } |
| 23171 | 23925 | } |
| 23172 | 23926 | } |
| 23173 | 23927 | if( pAr->eCmd==0 ){ |
| 23174 | | - utf8_printf(stderr, "Required argument missing. Usage:\n"); |
| 23928 | + eputz("Required argument missing. Usage:\n"); |
| 23175 | 23929 | return arUsage(stderr); |
| 23176 | 23930 | } |
| 23177 | 23931 | return SQLITE_OK; |
| 23178 | 23932 | } |
| 23179 | 23933 | |
| | @@ -23212,11 +23966,11 @@ |
| 23212 | 23966 | if( SQLITE_ROW==sqlite3_step(pTest) ){ |
| 23213 | 23967 | bOk = 1; |
| 23214 | 23968 | } |
| 23215 | 23969 | shellReset(&rc, pTest); |
| 23216 | 23970 | if( rc==SQLITE_OK && bOk==0 ){ |
| 23217 | | - utf8_printf(stderr, "not found in archive: %s\n", z); |
| 23971 | + eputf("not found in archive: %s\n", z); |
| 23218 | 23972 | rc = SQLITE_ERROR; |
| 23219 | 23973 | } |
| 23220 | 23974 | } |
| 23221 | 23975 | shellFinalize(&rc, pTest); |
| 23222 | 23976 | } |
| | @@ -23279,30 +24033,26 @@ |
| 23279 | 24033 | arWhereClause(&rc, pAr, &zWhere); |
| 23280 | 24034 | |
| 23281 | 24035 | shellPreparePrintf(pAr->db, &rc, &pSql, zSql, azCols[pAr->bVerbose], |
| 23282 | 24036 | pAr->zSrcTable, zWhere); |
| 23283 | 24037 | if( pAr->bDryRun ){ |
| 23284 | | - utf8_printf(pAr->p->out, "%s\n", sqlite3_sql(pSql)); |
| 24038 | + oputf("%s\n", sqlite3_sql(pSql)); |
| 23285 | 24039 | }else{ |
| 23286 | 24040 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ |
| 23287 | 24041 | if( pAr->bVerbose ){ |
| 23288 | | - utf8_printf(pAr->p->out, "%s % 10d %s %s\n", |
| 23289 | | - sqlite3_column_text(pSql, 0), |
| 23290 | | - sqlite3_column_int(pSql, 1), |
| 23291 | | - sqlite3_column_text(pSql, 2), |
| 23292 | | - sqlite3_column_text(pSql, 3) |
| 23293 | | - ); |
| 24042 | + oputf("%s % 10d %s %s\n", |
| 24043 | + sqlite3_column_text(pSql, 0), sqlite3_column_int(pSql, 1), |
| 24044 | + sqlite3_column_text(pSql, 2),sqlite3_column_text(pSql, 3)); |
| 23294 | 24045 | }else{ |
| 23295 | | - utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0)); |
| 24046 | + oputf("%s\n", sqlite3_column_text(pSql, 0)); |
| 23296 | 24047 | } |
| 23297 | 24048 | } |
| 23298 | 24049 | } |
| 23299 | 24050 | shellFinalize(&rc, pSql); |
| 23300 | 24051 | sqlite3_free(zWhere); |
| 23301 | 24052 | return rc; |
| 23302 | 24053 | } |
| 23303 | | - |
| 23304 | 24054 | |
| 23305 | 24055 | /* |
| 23306 | 24056 | ** Implementation of .ar "Remove" command. |
| 23307 | 24057 | */ |
| 23308 | 24058 | static int arRemoveCommand(ArCommand *pAr){ |
| | @@ -23318,11 +24068,11 @@ |
| 23318 | 24068 | } |
| 23319 | 24069 | if( rc==SQLITE_OK ){ |
| 23320 | 24070 | zSql = sqlite3_mprintf("DELETE FROM %s WHERE %s;", |
| 23321 | 24071 | pAr->zSrcTable, zWhere); |
| 23322 | 24072 | if( pAr->bDryRun ){ |
| 23323 | | - utf8_printf(pAr->p->out, "%s\n", zSql); |
| 24073 | + oputf("%s\n", zSql); |
| 23324 | 24074 | }else{ |
| 23325 | 24075 | char *zErr = 0; |
| 23326 | 24076 | rc = sqlite3_exec(pAr->db, "SAVEPOINT ar;", 0, 0, 0); |
| 23327 | 24077 | if( rc==SQLITE_OK ){ |
| 23328 | 24078 | rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr); |
| | @@ -23331,11 +24081,11 @@ |
| 23331 | 24081 | }else{ |
| 23332 | 24082 | rc = sqlite3_exec(pAr->db, "RELEASE ar;", 0, 0, 0); |
| 23333 | 24083 | } |
| 23334 | 24084 | } |
| 23335 | 24085 | if( zErr ){ |
| 23336 | | - utf8_printf(stdout, "ERROR: %s\n", zErr); |
| 24086 | + sputf(stdout, "ERROR: %s\n", zErr); /* stdout? */ |
| 23337 | 24087 | sqlite3_free(zErr); |
| 23338 | 24088 | } |
| 23339 | 24089 | } |
| 23340 | 24090 | } |
| 23341 | 24091 | sqlite3_free(zWhere); |
| | @@ -23395,15 +24145,15 @@ |
| 23395 | 24145 | ** populating them changes the timestamp). */ |
| 23396 | 24146 | for(i=0; i<2; i++){ |
| 23397 | 24147 | j = sqlite3_bind_parameter_index(pSql, "$dirOnly"); |
| 23398 | 24148 | sqlite3_bind_int(pSql, j, i); |
| 23399 | 24149 | if( pAr->bDryRun ){ |
| 23400 | | - utf8_printf(pAr->p->out, "%s\n", sqlite3_sql(pSql)); |
| 24150 | + oputf("%s\n", sqlite3_sql(pSql)); |
| 23401 | 24151 | }else{ |
| 23402 | 24152 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ |
| 23403 | 24153 | if( i==0 && pAr->bVerbose ){ |
| 23404 | | - utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0)); |
| 24154 | + oputf("%s\n", sqlite3_column_text(pSql, 0)); |
| 23405 | 24155 | } |
| 23406 | 24156 | } |
| 23407 | 24157 | } |
| 23408 | 24158 | shellReset(&rc, pSql); |
| 23409 | 24159 | } |
| | @@ -23419,17 +24169,17 @@ |
| 23419 | 24169 | ** Run the SQL statement in zSql. Or if doing a --dryrun, merely print it out. |
| 23420 | 24170 | */ |
| 23421 | 24171 | static int arExecSql(ArCommand *pAr, const char *zSql){ |
| 23422 | 24172 | int rc; |
| 23423 | 24173 | if( pAr->bDryRun ){ |
| 23424 | | - utf8_printf(pAr->p->out, "%s\n", zSql); |
| 24174 | + oputf("%s\n", zSql); |
| 23425 | 24175 | rc = SQLITE_OK; |
| 23426 | 24176 | }else{ |
| 23427 | 24177 | char *zErr = 0; |
| 23428 | 24178 | rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr); |
| 23429 | 24179 | if( zErr ){ |
| 23430 | | - utf8_printf(stdout, "ERROR: %s\n", zErr); |
| 24180 | + sputf(stdout, "ERROR: %s\n", zErr); |
| 23431 | 24181 | sqlite3_free(zErr); |
| 23432 | 24182 | } |
| 23433 | 24183 | } |
| 23434 | 24184 | return rc; |
| 23435 | 24185 | } |
| | @@ -23600,19 +24350,17 @@ |
| 23600 | 24350 | }else{ |
| 23601 | 24351 | flags = SQLITE_OPEN_READONLY; |
| 23602 | 24352 | } |
| 23603 | 24353 | cmd.db = 0; |
| 23604 | 24354 | if( cmd.bDryRun ){ |
| 23605 | | - utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile, |
| 23606 | | - eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : ""); |
| 24355 | + oputf("-- open database '%s'%s\n", cmd.zFile, |
| 24356 | + eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : ""); |
| 23607 | 24357 | } |
| 23608 | 24358 | rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags, |
| 23609 | 24359 | eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0); |
| 23610 | 24360 | if( rc!=SQLITE_OK ){ |
| 23611 | | - utf8_printf(stderr, "cannot open file: %s (%s)\n", |
| 23612 | | - cmd.zFile, sqlite3_errmsg(cmd.db) |
| 23613 | | - ); |
| 24361 | + eputf("cannot open file: %s (%s)\n", cmd.zFile, sqlite3_errmsg(cmd.db)); |
| 23614 | 24362 | goto end_ar_command; |
| 23615 | 24363 | } |
| 23616 | 24364 | sqlite3_fileio_init(cmd.db, 0, 0); |
| 23617 | 24365 | sqlite3_sqlar_init(cmd.db, 0, 0); |
| 23618 | 24366 | sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p, |
| | @@ -23621,11 +24369,11 @@ |
| 23621 | 24369 | } |
| 23622 | 24370 | if( cmd.zSrcTable==0 && cmd.bZip==0 && cmd.eCmd!=AR_CMD_HELP ){ |
| 23623 | 24371 | if( cmd.eCmd!=AR_CMD_CREATE |
| 23624 | 24372 | && sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0) |
| 23625 | 24373 | ){ |
| 23626 | | - utf8_printf(stderr, "database does not contain an 'sqlar' table\n"); |
| 24374 | + eputz("database does not contain an 'sqlar' table\n"); |
| 23627 | 24375 | rc = SQLITE_ERROR; |
| 23628 | 24376 | goto end_ar_command; |
| 23629 | 24377 | } |
| 23630 | 24378 | cmd.zSrcTable = sqlite3_mprintf("sqlar"); |
| 23631 | 24379 | } |
| | @@ -23679,11 +24427,11 @@ |
| 23679 | 24427 | ** This function is used as a callback by the recover extension. Simply |
| 23680 | 24428 | ** print the supplied SQL statement to stdout. |
| 23681 | 24429 | */ |
| 23682 | 24430 | static int recoverSqlCb(void *pCtx, const char *zSql){ |
| 23683 | 24431 | ShellState *pState = (ShellState*)pCtx; |
| 23684 | | - utf8_printf(pState->out, "%s;\n", zSql); |
| 24432 | + sputf(pState->out, "%s;\n", zSql); |
| 23685 | 24433 | return SQLITE_OK; |
| 23686 | 24434 | } |
| 23687 | 24435 | |
| 23688 | 24436 | /* |
| 23689 | 24437 | ** This function is called to recover data from the database. A script |
| | @@ -23722,11 +24470,11 @@ |
| 23722 | 24470 | }else |
| 23723 | 24471 | if( n<=10 && memcmp("-no-rowids", z, n)==0 ){ |
| 23724 | 24472 | bRowids = 0; |
| 23725 | 24473 | } |
| 23726 | 24474 | else{ |
| 23727 | | - utf8_printf(stderr, "unexpected option: %s\n", azArg[i]); |
| 24475 | + eputf("unexpected option: %s\n", azArg[i]); |
| 23728 | 24476 | showHelp(pState->out, azArg[0]); |
| 23729 | 24477 | return 1; |
| 23730 | 24478 | } |
| 23731 | 24479 | } |
| 23732 | 24480 | |
| | @@ -23741,11 +24489,11 @@ |
| 23741 | 24489 | |
| 23742 | 24490 | sqlite3_recover_run(p); |
| 23743 | 24491 | if( sqlite3_recover_errcode(p)!=SQLITE_OK ){ |
| 23744 | 24492 | const char *zErr = sqlite3_recover_errmsg(p); |
| 23745 | 24493 | int errCode = sqlite3_recover_errcode(p); |
| 23746 | | - raw_printf(stderr, "sql error: %s (%d)\n", zErr, errCode); |
| 24494 | + eputf("sql error: %s (%d)\n", zErr, errCode); |
| 23747 | 24495 | } |
| 23748 | 24496 | rc = sqlite3_recover_finish(p); |
| 23749 | 24497 | return rc; |
| 23750 | 24498 | } |
| 23751 | 24499 | #endif /* SQLITE_SHELL_HAVE_RECOVER */ |
| | @@ -23766,11 +24514,11 @@ |
| 23766 | 24514 | */ |
| 23767 | 24515 | #ifdef SHELL_DEBUG |
| 23768 | 24516 | #define rc_err_oom_die(rc) \ |
| 23769 | 24517 | if( rc==SQLITE_NOMEM ) shell_check_oom(0); \ |
| 23770 | 24518 | else if(!(rc==SQLITE_OK||rc==SQLITE_DONE)) \ |
| 23771 | | - fprintf(stderr,"E:%d\n",rc), assert(0) |
| 24519 | + eputf("E:%d\n",rc), assert(0) |
| 23772 | 24520 | #else |
| 23773 | 24521 | static void rc_err_oom_die(int rc){ |
| 23774 | 24522 | if( rc==SQLITE_NOMEM ) shell_check_oom(0); |
| 23775 | 24523 | assert(rc==SQLITE_OK||rc==SQLITE_DONE); |
| 23776 | 24524 | } |
| | @@ -23906,10 +24654,11 @@ |
| 23906 | 24654 | #ifdef SHELL_COLFIX_DB |
| 23907 | 24655 | if(*zCOL_DB!=':') |
| 23908 | 24656 | sqlite3_exec(*pDb,"drop table if exists ColNames;" |
| 23909 | 24657 | "drop view if exists RepeatedNames;",0,0,0); |
| 23910 | 24658 | #endif |
| 24659 | +#undef SHELL_COLFIX_DB |
| 23911 | 24660 | rc = sqlite3_exec(*pDb, zTabMake, 0, 0, 0); |
| 23912 | 24661 | rc_err_oom_die(rc); |
| 23913 | 24662 | } |
| 23914 | 24663 | assert(*pDb!=0); |
| 23915 | 24664 | rc = sqlite3_prepare_v2(*pDb, zTabFill, -1, &pStmt, 0); |
| | @@ -24019,11 +24768,11 @@ |
| 24019 | 24768 | clearTempFile(p); |
| 24020 | 24769 | |
| 24021 | 24770 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 24022 | 24771 | if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){ |
| 24023 | 24772 | if( nArg!=2 ){ |
| 24024 | | - raw_printf(stderr, "Usage: .auth ON|OFF\n"); |
| 24773 | + eputz("Usage: .auth ON|OFF\n"); |
| 24025 | 24774 | rc = 1; |
| 24026 | 24775 | goto meta_command_exit; |
| 24027 | 24776 | } |
| 24028 | 24777 | open_db(p, 0); |
| 24029 | 24778 | if( booleanValue(azArg[1]) ){ |
| | @@ -24066,32 +24815,32 @@ |
| 24066 | 24815 | }else |
| 24067 | 24816 | if( cli_strcmp(z, "-async")==0 ){ |
| 24068 | 24817 | bAsync = 1; |
| 24069 | 24818 | }else |
| 24070 | 24819 | { |
| 24071 | | - utf8_printf(stderr, "unknown option: %s\n", azArg[j]); |
| 24820 | + eputf("unknown option: %s\n", azArg[j]); |
| 24072 | 24821 | return 1; |
| 24073 | 24822 | } |
| 24074 | 24823 | }else if( zDestFile==0 ){ |
| 24075 | 24824 | zDestFile = azArg[j]; |
| 24076 | 24825 | }else if( zDb==0 ){ |
| 24077 | 24826 | zDb = zDestFile; |
| 24078 | 24827 | zDestFile = azArg[j]; |
| 24079 | 24828 | }else{ |
| 24080 | | - raw_printf(stderr, "Usage: .backup ?DB? ?OPTIONS? FILENAME\n"); |
| 24829 | + eputz("Usage: .backup ?DB? ?OPTIONS? FILENAME\n"); |
| 24081 | 24830 | return 1; |
| 24082 | 24831 | } |
| 24083 | 24832 | } |
| 24084 | 24833 | if( zDestFile==0 ){ |
| 24085 | | - raw_printf(stderr, "missing FILENAME argument on .backup\n"); |
| 24834 | + eputz("missing FILENAME argument on .backup\n"); |
| 24086 | 24835 | return 1; |
| 24087 | 24836 | } |
| 24088 | 24837 | if( zDb==0 ) zDb = "main"; |
| 24089 | 24838 | rc = sqlite3_open_v2(zDestFile, &pDest, |
| 24090 | 24839 | SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs); |
| 24091 | 24840 | if( rc!=SQLITE_OK ){ |
| 24092 | | - utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile); |
| 24841 | + eputf("Error: cannot open \"%s\"\n", zDestFile); |
| 24093 | 24842 | close_db(pDest); |
| 24094 | 24843 | return 1; |
| 24095 | 24844 | } |
| 24096 | 24845 | if( bAsync ){ |
| 24097 | 24846 | sqlite3_exec(pDest, "PRAGMA synchronous=OFF; PRAGMA journal_mode=OFF;", |
| | @@ -24098,20 +24847,20 @@ |
| 24098 | 24847 | 0, 0, 0); |
| 24099 | 24848 | } |
| 24100 | 24849 | open_db(p, 0); |
| 24101 | 24850 | pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb); |
| 24102 | 24851 | if( pBackup==0 ){ |
| 24103 | | - utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest)); |
| 24852 | + eputf("Error: %s\n", sqlite3_errmsg(pDest)); |
| 24104 | 24853 | close_db(pDest); |
| 24105 | 24854 | return 1; |
| 24106 | 24855 | } |
| 24107 | 24856 | while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){} |
| 24108 | 24857 | sqlite3_backup_finish(pBackup); |
| 24109 | 24858 | if( rc==SQLITE_DONE ){ |
| 24110 | 24859 | rc = 0; |
| 24111 | 24860 | }else{ |
| 24112 | | - utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest)); |
| 24861 | + eputf("Error: %s\n", sqlite3_errmsg(pDest)); |
| 24113 | 24862 | rc = 1; |
| 24114 | 24863 | } |
| 24115 | 24864 | close_db(pDest); |
| 24116 | 24865 | }else |
| 24117 | 24866 | #endif /* !defined(SQLITE_SHELL_FIDDLE) */ |
| | @@ -24118,11 +24867,11 @@ |
| 24118 | 24867 | |
| 24119 | 24868 | if( c=='b' && n>=3 && cli_strncmp(azArg[0], "bail", n)==0 ){ |
| 24120 | 24869 | if( nArg==2 ){ |
| 24121 | 24870 | bail_on_error = booleanValue(azArg[1]); |
| 24122 | 24871 | }else{ |
| 24123 | | - raw_printf(stderr, "Usage: .bail on|off\n"); |
| 24872 | + eputz("Usage: .bail on|off\n"); |
| 24124 | 24873 | rc = 1; |
| 24125 | 24874 | } |
| 24126 | 24875 | }else |
| 24127 | 24876 | |
| 24128 | 24877 | /* Undocumented. Legacy only. See "crnl" below */ |
| | @@ -24132,13 +24881,12 @@ |
| 24132 | 24881 | setBinaryMode(p->out, 1); |
| 24133 | 24882 | }else{ |
| 24134 | 24883 | setTextMode(p->out, 1); |
| 24135 | 24884 | } |
| 24136 | 24885 | }else{ |
| 24137 | | - raw_printf(stderr, "The \".binary\" command is deprecated." |
| 24138 | | - " Use \".crnl\" instead.\n"); |
| 24139 | | - raw_printf(stderr, "Usage: .binary on|off\n"); |
| 24886 | + eputz("The \".binary\" command is deprecated. Use \".crnl\" instead.\n" |
| 24887 | + "Usage: .binary on|off\n"); |
| 24140 | 24888 | rc = 1; |
| 24141 | 24889 | } |
| 24142 | 24890 | }else |
| 24143 | 24891 | |
| 24144 | 24892 | /* The undocumented ".breakpoint" command causes a call to the no-op |
| | @@ -24158,25 +24906,25 @@ |
| 24158 | 24906 | sqlite3_free(z); |
| 24159 | 24907 | #else |
| 24160 | 24908 | rc = chdir(azArg[1]); |
| 24161 | 24909 | #endif |
| 24162 | 24910 | if( rc ){ |
| 24163 | | - utf8_printf(stderr, "Cannot change to directory \"%s\"\n", azArg[1]); |
| 24911 | + eputf("Cannot change to directory \"%s\"\n", azArg[1]); |
| 24164 | 24912 | rc = 1; |
| 24165 | 24913 | } |
| 24166 | 24914 | }else{ |
| 24167 | | - raw_printf(stderr, "Usage: .cd DIRECTORY\n"); |
| 24915 | + eputz("Usage: .cd DIRECTORY\n"); |
| 24168 | 24916 | rc = 1; |
| 24169 | 24917 | } |
| 24170 | 24918 | }else |
| 24171 | 24919 | #endif /* !defined(SQLITE_SHELL_FIDDLE) */ |
| 24172 | 24920 | |
| 24173 | 24921 | if( c=='c' && n>=3 && cli_strncmp(azArg[0], "changes", n)==0 ){ |
| 24174 | 24922 | if( nArg==2 ){ |
| 24175 | 24923 | setOrClearFlag(p, SHFLG_CountChanges, azArg[1]); |
| 24176 | 24924 | }else{ |
| 24177 | | - raw_printf(stderr, "Usage: .changes on|off\n"); |
| 24925 | + eputz("Usage: .changes on|off\n"); |
| 24178 | 24926 | rc = 1; |
| 24179 | 24927 | } |
| 24180 | 24928 | }else |
| 24181 | 24929 | |
| 24182 | 24930 | #ifndef SQLITE_SHELL_FIDDLE |
| | @@ -24186,21 +24934,20 @@ |
| 24186 | 24934 | */ |
| 24187 | 24935 | if( c=='c' && n>=3 && cli_strncmp(azArg[0], "check", n)==0 ){ |
| 24188 | 24936 | char *zRes = 0; |
| 24189 | 24937 | output_reset(p); |
| 24190 | 24938 | if( nArg!=2 ){ |
| 24191 | | - raw_printf(stderr, "Usage: .check GLOB-PATTERN\n"); |
| 24939 | + eputz("Usage: .check GLOB-PATTERN\n"); |
| 24192 | 24940 | rc = 2; |
| 24193 | 24941 | }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){ |
| 24194 | 24942 | rc = 2; |
| 24195 | 24943 | }else if( testcase_glob(azArg[1],zRes)==0 ){ |
| 24196 | | - utf8_printf(stderr, |
| 24197 | | - "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n", |
| 24198 | | - p->zTestcase, azArg[1], zRes); |
| 24944 | + eputf("testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n", |
| 24945 | + p->zTestcase, azArg[1], zRes); |
| 24199 | 24946 | rc = 1; |
| 24200 | 24947 | }else{ |
| 24201 | | - utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase); |
| 24948 | + oputf("testcase-%s ok\n", p->zTestcase); |
| 24202 | 24949 | p->nCheck++; |
| 24203 | 24950 | } |
| 24204 | 24951 | sqlite3_free(zRes); |
| 24205 | 24952 | }else |
| 24206 | 24953 | #endif /* !defined(SQLITE_SHELL_FIDDLE) */ |
| | @@ -24209,11 +24956,11 @@ |
| 24209 | 24956 | if( c=='c' && cli_strncmp(azArg[0], "clone", n)==0 ){ |
| 24210 | 24957 | failIfSafeMode(p, "cannot run .clone in safe mode"); |
| 24211 | 24958 | if( nArg==2 ){ |
| 24212 | 24959 | tryToClone(p, azArg[1]); |
| 24213 | 24960 | }else{ |
| 24214 | | - raw_printf(stderr, "Usage: .clone FILENAME\n"); |
| 24961 | + eputz("Usage: .clone FILENAME\n"); |
| 24215 | 24962 | rc = 1; |
| 24216 | 24963 | } |
| 24217 | 24964 | }else |
| 24218 | 24965 | #endif /* !defined(SQLITE_SHELL_FIDDLE) */ |
| 24219 | 24966 | |
| | @@ -24229,13 +24976,13 @@ |
| 24229 | 24976 | zFile = "(memory)"; |
| 24230 | 24977 | }else if( zFile[0]==0 ){ |
| 24231 | 24978 | zFile = "(temporary-file)"; |
| 24232 | 24979 | } |
| 24233 | 24980 | if( p->pAuxDb == &p->aAuxDb[i] ){ |
| 24234 | | - utf8_printf(stdout, "ACTIVE %d: %s\n", i, zFile); |
| 24981 | + sputf(stdout, "ACTIVE %d: %s\n", i, zFile); |
| 24235 | 24982 | }else if( p->aAuxDb[i].db!=0 ){ |
| 24236 | | - utf8_printf(stdout, " %d: %s\n", i, zFile); |
| 24983 | + sputf(stdout, " %d: %s\n", i, zFile); |
| 24237 | 24984 | } |
| 24238 | 24985 | } |
| 24239 | 24986 | }else if( nArg==2 && IsDigit(azArg[1][0]) && azArg[1][1]==0 ){ |
| 24240 | 24987 | int i = azArg[1][0] - '0'; |
| 24241 | 24988 | if( p->pAuxDb != &p->aAuxDb[i] && i>=0 && i<ArraySize(p->aAuxDb) ){ |
| | @@ -24248,19 +24995,19 @@ |
| 24248 | 24995 | && IsDigit(azArg[2][0]) && azArg[2][1]==0 ){ |
| 24249 | 24996 | int i = azArg[2][0] - '0'; |
| 24250 | 24997 | if( i<0 || i>=ArraySize(p->aAuxDb) ){ |
| 24251 | 24998 | /* No-op */ |
| 24252 | 24999 | }else if( p->pAuxDb == &p->aAuxDb[i] ){ |
| 24253 | | - raw_printf(stderr, "cannot close the active database connection\n"); |
| 25000 | + eputz("cannot close the active database connection\n"); |
| 24254 | 25001 | rc = 1; |
| 24255 | 25002 | }else if( p->aAuxDb[i].db ){ |
| 24256 | 25003 | session_close_all(p, i); |
| 24257 | 25004 | close_db(p->aAuxDb[i].db); |
| 24258 | 25005 | p->aAuxDb[i].db = 0; |
| 24259 | 25006 | } |
| 24260 | 25007 | }else{ |
| 24261 | | - raw_printf(stderr, "Usage: .connection [close] [CONNECTION-NUMBER]\n"); |
| 25008 | + eputz("Usage: .connection [close] [CONNECTION-NUMBER]\n"); |
| 24262 | 25009 | rc = 1; |
| 24263 | 25010 | } |
| 24264 | 25011 | }else |
| 24265 | 25012 | |
| 24266 | 25013 | if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){ |
| | @@ -24270,13 +25017,13 @@ |
| 24270 | 25017 | }else{ |
| 24271 | 25018 | setBinaryMode(p->out, 1); |
| 24272 | 25019 | } |
| 24273 | 25020 | }else{ |
| 24274 | 25021 | #if !defined(_WIN32) && !defined(WIN32) |
| 24275 | | - raw_printf(stderr, "The \".crnl\" is a no-op on non-Windows machines.\n"); |
| 25022 | + eputz("The \".crnl\" is a no-op on non-Windows machines.\n"); |
| 24276 | 25023 | #endif |
| 24277 | | - raw_printf(stderr, "Usage: .crnl on|off\n"); |
| 25024 | + eputz("Usage: .crnl on|off\n"); |
| 24278 | 25025 | rc = 1; |
| 24279 | 25026 | } |
| 24280 | 25027 | }else |
| 24281 | 25028 | |
| 24282 | 25029 | if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){ |
| | @@ -24285,11 +25032,11 @@ |
| 24285 | 25032 | sqlite3_stmt *pStmt; |
| 24286 | 25033 | int i; |
| 24287 | 25034 | open_db(p, 0); |
| 24288 | 25035 | rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); |
| 24289 | 25036 | if( rc ){ |
| 24290 | | - utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); |
| 25037 | + eputf("Error: %s\n", sqlite3_errmsg(p->db)); |
| 24291 | 25038 | rc = 1; |
| 24292 | 25039 | }else{ |
| 24293 | 25040 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 24294 | 25041 | const char *zSchema = (const char *)sqlite3_column_text(pStmt,1); |
| 24295 | 25042 | const char *zFile = (const char*)sqlite3_column_text(pStmt,2); |
| | @@ -24304,15 +25051,13 @@ |
| 24304 | 25051 | sqlite3_finalize(pStmt); |
| 24305 | 25052 | for(i=0; i<nName; i++){ |
| 24306 | 25053 | int eTxn = sqlite3_txn_state(p->db, azName[i*2]); |
| 24307 | 25054 | int bRdonly = sqlite3_db_readonly(p->db, azName[i*2]); |
| 24308 | 25055 | const char *z = azName[i*2+1]; |
| 24309 | | - utf8_printf(p->out, "%s: %s %s%s\n", |
| 24310 | | - azName[i*2], |
| 24311 | | - z && z[0] ? z : "\"\"", |
| 24312 | | - bRdonly ? "r/o" : "r/w", |
| 24313 | | - eTxn==SQLITE_TXN_NONE ? "" : |
| 25056 | + oputf("%s: %s %s%s\n", |
| 25057 | + azName[i*2], z && z[0] ? z : "\"\"", bRdonly ? "r/o" : "r/w", |
| 25058 | + eTxn==SQLITE_TXN_NONE ? "" : |
| 24314 | 25059 | eTxn==SQLITE_TXN_READ ? " read-txn" : " write-txn"); |
| 24315 | 25060 | free(azName[i*2]); |
| 24316 | 25061 | free(azName[i*2+1]); |
| 24317 | 25062 | } |
| 24318 | 25063 | sqlite3_free(azName); |
| | @@ -24348,16 +25093,16 @@ |
| 24348 | 25093 | if( nArg>1 && cli_strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue; |
| 24349 | 25094 | if( nArg>=3 ){ |
| 24350 | 25095 | sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0); |
| 24351 | 25096 | } |
| 24352 | 25097 | sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v); |
| 24353 | | - utf8_printf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off"); |
| 25098 | + oputf("%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off"); |
| 24354 | 25099 | if( nArg>1 ) break; |
| 24355 | 25100 | } |
| 24356 | 25101 | if( nArg>1 && ii==ArraySize(aDbConfig) ){ |
| 24357 | | - utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]); |
| 24358 | | - utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n"); |
| 25102 | + eputf("Error: unknown dbconfig \"%s\"\n", azArg[1]); |
| 25103 | + eputz("Enter \".dbconfig\" with no arguments for a list\n"); |
| 24359 | 25104 | } |
| 24360 | 25105 | }else |
| 24361 | 25106 | |
| 24362 | 25107 | #if SQLITE_SHELL_HAVE_RECOVER |
| 24363 | 25108 | if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){ |
| | @@ -24383,12 +25128,12 @@ |
| 24383 | 25128 | if( azArg[i][0]=='-' ){ |
| 24384 | 25129 | const char *z = azArg[i]+1; |
| 24385 | 25130 | if( z[0]=='-' ) z++; |
| 24386 | 25131 | if( cli_strcmp(z,"preserve-rowids")==0 ){ |
| 24387 | 25132 | #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 24388 | | - raw_printf(stderr, "The --preserve-rowids option is not compatible" |
| 24389 | | - " with SQLITE_OMIT_VIRTUALTABLE\n"); |
| 25133 | + eputz("The --preserve-rowids option is not compatible" |
| 25134 | + " with SQLITE_OMIT_VIRTUALTABLE\n"); |
| 24390 | 25135 | rc = 1; |
| 24391 | 25136 | sqlite3_free(zLike); |
| 24392 | 25137 | goto meta_command_exit; |
| 24393 | 25138 | #else |
| 24394 | 25139 | ShellSetFlag(p, SHFLG_PreserveRowid); |
| | @@ -24402,11 +25147,11 @@ |
| 24402 | 25147 | }else |
| 24403 | 25148 | if( cli_strcmp(z,"nosys")==0 ){ |
| 24404 | 25149 | ShellSetFlag(p, SHFLG_DumpNoSys); |
| 24405 | 25150 | }else |
| 24406 | 25151 | { |
| 24407 | | - raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]); |
| 25152 | + eputf("Unknown option \"%s\" on \".dump\"\n", azArg[i]); |
| 24408 | 25153 | rc = 1; |
| 24409 | 25154 | sqlite3_free(zLike); |
| 24410 | 25155 | goto meta_command_exit; |
| 24411 | 25156 | } |
| 24412 | 25157 | }else{ |
| | @@ -24436,12 +25181,12 @@ |
| 24436 | 25181 | |
| 24437 | 25182 | if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ |
| 24438 | 25183 | /* When playing back a "dump", the content might appear in an order |
| 24439 | 25184 | ** which causes immediate foreign key constraints to be violated. |
| 24440 | 25185 | ** So disable foreign-key constraint enforcement to prevent problems. */ |
| 24441 | | - raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n"); |
| 24442 | | - raw_printf(p->out, "BEGIN TRANSACTION;\n"); |
| 25186 | + oputz("PRAGMA foreign_keys=OFF;\n"); |
| 25187 | + oputz("BEGIN TRANSACTION;\n"); |
| 24443 | 25188 | } |
| 24444 | 25189 | p->writableSchema = 0; |
| 24445 | 25190 | p->showHeader = 0; |
| 24446 | 25191 | /* Set writable_schema=ON since doing so forces SQLite to initialize |
| 24447 | 25192 | ** as much of the schema as it can even if the sqlite_schema table is |
| | @@ -24468,27 +25213,27 @@ |
| 24468 | 25213 | run_table_dump_query(p, zSql); |
| 24469 | 25214 | sqlite3_free(zSql); |
| 24470 | 25215 | } |
| 24471 | 25216 | sqlite3_free(zLike); |
| 24472 | 25217 | if( p->writableSchema ){ |
| 24473 | | - raw_printf(p->out, "PRAGMA writable_schema=OFF;\n"); |
| 25218 | + oputz("PRAGMA writable_schema=OFF;\n"); |
| 24474 | 25219 | p->writableSchema = 0; |
| 24475 | 25220 | } |
| 24476 | 25221 | sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); |
| 24477 | 25222 | sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0); |
| 24478 | 25223 | if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ |
| 24479 | | - raw_printf(p->out, p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n"); |
| 25224 | + oputz(p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n"); |
| 24480 | 25225 | } |
| 24481 | 25226 | p->showHeader = savedShowHeader; |
| 24482 | 25227 | p->shellFlgs = savedShellFlags; |
| 24483 | 25228 | }else |
| 24484 | 25229 | |
| 24485 | 25230 | if( c=='e' && cli_strncmp(azArg[0], "echo", n)==0 ){ |
| 24486 | 25231 | if( nArg==2 ){ |
| 24487 | 25232 | setOrClearFlag(p, SHFLG_Echo, azArg[1]); |
| 24488 | 25233 | }else{ |
| 24489 | | - raw_printf(stderr, "Usage: .echo on|off\n"); |
| 25234 | + eputz("Usage: .echo on|off\n"); |
| 24490 | 25235 | rc = 1; |
| 24491 | 25236 | } |
| 24492 | 25237 | }else |
| 24493 | 25238 | |
| 24494 | 25239 | if( c=='e' && cli_strncmp(azArg[0], "eqp", n)==0 ){ |
| | @@ -24515,11 +25260,11 @@ |
| 24515 | 25260 | #endif |
| 24516 | 25261 | }else{ |
| 24517 | 25262 | p->autoEQP = (u8)booleanValue(azArg[1]); |
| 24518 | 25263 | } |
| 24519 | 25264 | }else{ |
| 24520 | | - raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n"); |
| 25265 | + eputz("Usage: .eqp off|on|trace|trigger|full\n"); |
| 24521 | 25266 | rc = 1; |
| 24522 | 25267 | } |
| 24523 | 25268 | }else |
| 24524 | 25269 | |
| 24525 | 25270 | #ifndef SQLITE_SHELL_FIDDLE |
| | @@ -24554,13 +25299,12 @@ |
| 24554 | 25299 | }else |
| 24555 | 25300 | |
| 24556 | 25301 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 24557 | 25302 | if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){ |
| 24558 | 25303 | if( p->bSafeMode ){ |
| 24559 | | - raw_printf(stderr, |
| 24560 | | - "Cannot run experimental commands such as \"%s\" in safe mode\n", |
| 24561 | | - azArg[0]); |
| 25304 | + eputf("Cannot run experimental commands such as \"%s\" in safe mode\n", |
| 25305 | + azArg[0]); |
| 24562 | 25306 | rc = 1; |
| 24563 | 25307 | }else{ |
| 24564 | 25308 | open_db(p, 0); |
| 24565 | 25309 | expertDotCommand(p, azArg, nArg); |
| 24566 | 25310 | } |
| | @@ -24612,14 +25356,13 @@ |
| 24612 | 25356 | if( zCmd[0]=='-' && zCmd[1] ) zCmd++; |
| 24613 | 25357 | } |
| 24614 | 25358 | |
| 24615 | 25359 | /* --help lists all file-controls */ |
| 24616 | 25360 | if( cli_strcmp(zCmd,"help")==0 ){ |
| 24617 | | - utf8_printf(p->out, "Available file-controls:\n"); |
| 25361 | + oputz("Available file-controls:\n"); |
| 24618 | 25362 | for(i=0; i<ArraySize(aCtrl); i++){ |
| 24619 | | - utf8_printf(p->out, " .filectrl %s %s\n", |
| 24620 | | - aCtrl[i].zCtrlName, aCtrl[i].zUsage); |
| 25363 | + oputf(" .filectrl %s %s\n", aCtrl[i].zCtrlName, aCtrl[i].zUsage); |
| 24621 | 25364 | } |
| 24622 | 25365 | rc = 1; |
| 24623 | 25366 | goto meta_command_exit; |
| 24624 | 25367 | } |
| 24625 | 25368 | |
| | @@ -24630,20 +25373,20 @@ |
| 24630 | 25373 | if( cli_strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){ |
| 24631 | 25374 | if( filectrl<0 ){ |
| 24632 | 25375 | filectrl = aCtrl[i].ctrlCode; |
| 24633 | 25376 | iCtrl = i; |
| 24634 | 25377 | }else{ |
| 24635 | | - utf8_printf(stderr, "Error: ambiguous file-control: \"%s\"\n" |
| 24636 | | - "Use \".filectrl --help\" for help\n", zCmd); |
| 25378 | + eputf("Error: ambiguous file-control: \"%s\"\n" |
| 25379 | + "Use \".filectrl --help\" for help\n", zCmd); |
| 24637 | 25380 | rc = 1; |
| 24638 | 25381 | goto meta_command_exit; |
| 24639 | 25382 | } |
| 24640 | 25383 | } |
| 24641 | 25384 | } |
| 24642 | 25385 | if( filectrl<0 ){ |
| 24643 | | - utf8_printf(stderr,"Error: unknown file-control: %s\n" |
| 24644 | | - "Use \".filectrl --help\" for help\n", zCmd); |
| 25386 | + eputf("Error: unknown file-control: %s\n" |
| 25387 | + "Use \".filectrl --help\" for help\n", zCmd); |
| 24645 | 25388 | }else{ |
| 24646 | 25389 | switch(filectrl){ |
| 24647 | 25390 | case SQLITE_FCNTL_SIZE_LIMIT: { |
| 24648 | 25391 | if( nArg!=2 && nArg!=3 ) break; |
| 24649 | 25392 | iRes = nArg==3 ? integerValue(azArg[2]) : -1; |
| | @@ -24682,11 +25425,11 @@ |
| 24682 | 25425 | case SQLITE_FCNTL_TEMPFILENAME: { |
| 24683 | 25426 | char *z = 0; |
| 24684 | 25427 | if( nArg!=2 ) break; |
| 24685 | 25428 | sqlite3_file_control(p->db, zSchema, filectrl, &z); |
| 24686 | 25429 | if( z ){ |
| 24687 | | - utf8_printf(p->out, "%s\n", z); |
| 25430 | + oputf("%s\n", z); |
| 24688 | 25431 | sqlite3_free(z); |
| 24689 | 25432 | } |
| 24690 | 25433 | isOk = 2; |
| 24691 | 25434 | break; |
| 24692 | 25435 | } |
| | @@ -24696,23 +25439,23 @@ |
| 24696 | 25439 | x = atoi(azArg[2]); |
| 24697 | 25440 | sqlite3_file_control(p->db, zSchema, filectrl, &x); |
| 24698 | 25441 | } |
| 24699 | 25442 | x = -1; |
| 24700 | 25443 | sqlite3_file_control(p->db, zSchema, filectrl, &x); |
| 24701 | | - utf8_printf(p->out,"%d\n", x); |
| 25444 | + oputf("%d\n", x); |
| 24702 | 25445 | isOk = 2; |
| 24703 | 25446 | break; |
| 24704 | 25447 | } |
| 24705 | 25448 | } |
| 24706 | 25449 | } |
| 24707 | 25450 | if( isOk==0 && iCtrl>=0 ){ |
| 24708 | | - utf8_printf(p->out, "Usage: .filectrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); |
| 25451 | + oputf("Usage: .filectrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); |
| 24709 | 25452 | rc = 1; |
| 24710 | 25453 | }else if( isOk==1 ){ |
| 24711 | 25454 | char zBuf[100]; |
| 24712 | 25455 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", iRes); |
| 24713 | | - raw_printf(p->out, "%s\n", zBuf); |
| 25456 | + oputf("%s\n", zBuf); |
| 24714 | 25457 | } |
| 24715 | 25458 | }else |
| 24716 | 25459 | |
| 24717 | 25460 | if( c=='f' && cli_strncmp(azArg[0], "fullschema", n)==0 ){ |
| 24718 | 25461 | ShellState data; |
| | @@ -24723,11 +25466,11 @@ |
| 24723 | 25466 | if( nArg==2 && optionMatch(azArg[1], "indent") ){ |
| 24724 | 25467 | data.cMode = data.mode = MODE_Pretty; |
| 24725 | 25468 | nArg = 1; |
| 24726 | 25469 | } |
| 24727 | 25470 | if( nArg!=1 ){ |
| 24728 | | - raw_printf(stderr, "Usage: .fullschema ?--indent?\n"); |
| 25471 | + eputz("Usage: .fullschema ?--indent?\n"); |
| 24729 | 25472 | rc = 1; |
| 24730 | 25473 | goto meta_command_exit; |
| 24731 | 25474 | } |
| 24732 | 25475 | open_db(p, 0); |
| 24733 | 25476 | rc = sqlite3_exec(p->db, |
| | @@ -24749,37 +25492,37 @@ |
| 24749 | 25492 | doStats = sqlite3_step(pStmt)==SQLITE_ROW; |
| 24750 | 25493 | sqlite3_finalize(pStmt); |
| 24751 | 25494 | } |
| 24752 | 25495 | } |
| 24753 | 25496 | if( doStats==0 ){ |
| 24754 | | - raw_printf(p->out, "/* No STAT tables available */\n"); |
| 25497 | + oputz("/* No STAT tables available */\n"); |
| 24755 | 25498 | }else{ |
| 24756 | | - raw_printf(p->out, "ANALYZE sqlite_schema;\n"); |
| 25499 | + oputz("ANALYZE sqlite_schema;\n"); |
| 24757 | 25500 | data.cMode = data.mode = MODE_Insert; |
| 24758 | 25501 | data.zDestTable = "sqlite_stat1"; |
| 24759 | 25502 | shell_exec(&data, "SELECT * FROM sqlite_stat1", 0); |
| 24760 | 25503 | data.zDestTable = "sqlite_stat4"; |
| 24761 | 25504 | shell_exec(&data, "SELECT * FROM sqlite_stat4", 0); |
| 24762 | | - raw_printf(p->out, "ANALYZE sqlite_schema;\n"); |
| 25505 | + oputz("ANALYZE sqlite_schema;\n"); |
| 24763 | 25506 | } |
| 24764 | 25507 | }else |
| 24765 | 25508 | |
| 24766 | 25509 | if( c=='h' && cli_strncmp(azArg[0], "headers", n)==0 ){ |
| 24767 | 25510 | if( nArg==2 ){ |
| 24768 | 25511 | p->showHeader = booleanValue(azArg[1]); |
| 24769 | 25512 | p->shellFlgs |= SHFLG_HeaderSet; |
| 24770 | 25513 | }else{ |
| 24771 | | - raw_printf(stderr, "Usage: .headers on|off\n"); |
| 25514 | + eputz("Usage: .headers on|off\n"); |
| 24772 | 25515 | rc = 1; |
| 24773 | 25516 | } |
| 24774 | 25517 | }else |
| 24775 | 25518 | |
| 24776 | 25519 | if( c=='h' && cli_strncmp(azArg[0], "help", n)==0 ){ |
| 24777 | 25520 | if( nArg>=2 ){ |
| 24778 | 25521 | n = showHelp(p->out, azArg[1]); |
| 24779 | 25522 | if( n==0 ){ |
| 24780 | | - utf8_printf(p->out, "Nothing matches '%s'\n", azArg[1]); |
| 25523 | + oputf("Nothing matches '%s'\n", azArg[1]); |
| 24781 | 25524 | } |
| 24782 | 25525 | }else{ |
| 24783 | 25526 | showHelp(p->out, 0); |
| 24784 | 25527 | } |
| 24785 | 25528 | }else |
| | @@ -24819,11 +25562,11 @@ |
| 24819 | 25562 | if( zFile==0 ){ |
| 24820 | 25563 | zFile = z; |
| 24821 | 25564 | }else if( zTable==0 ){ |
| 24822 | 25565 | zTable = z; |
| 24823 | 25566 | }else{ |
| 24824 | | - utf8_printf(p->out, "ERROR: extra argument: \"%s\". Usage:\n", z); |
| 25567 | + oputf("ERROR: extra argument: \"%s\". Usage:\n", z); |
| 24825 | 25568 | showHelp(p->out, "import"); |
| 24826 | 25569 | goto meta_command_exit; |
| 24827 | 25570 | } |
| 24828 | 25571 | }else if( cli_strcmp(z,"-v")==0 ){ |
| 24829 | 25572 | eVerbose++; |
| | @@ -24840,18 +25583,18 @@ |
| 24840 | 25583 | sCtx.cColSep = ','; |
| 24841 | 25584 | sCtx.cRowSep = '\n'; |
| 24842 | 25585 | xRead = csv_read_one_field; |
| 24843 | 25586 | useOutputMode = 0; |
| 24844 | 25587 | }else{ |
| 24845 | | - utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", z); |
| 25588 | + oputf("ERROR: unknown option: \"%s\". Usage:\n", z); |
| 24846 | 25589 | showHelp(p->out, "import"); |
| 24847 | 25590 | goto meta_command_exit; |
| 24848 | 25591 | } |
| 24849 | 25592 | } |
| 24850 | 25593 | if( zTable==0 ){ |
| 24851 | | - utf8_printf(p->out, "ERROR: missing %s argument. Usage:\n", |
| 24852 | | - zFile==0 ? "FILE" : "TABLE"); |
| 25594 | + oputf("ERROR: missing %s argument. Usage:\n", |
| 25595 | + zFile==0 ? "FILE" : "TABLE"); |
| 24853 | 25596 | showHelp(p->out, "import"); |
| 24854 | 25597 | goto meta_command_exit; |
| 24855 | 25598 | } |
| 24856 | 25599 | seenInterrupt = 0; |
| 24857 | 25600 | open_db(p, 0); |
| | @@ -24858,24 +25601,21 @@ |
| 24858 | 25601 | if( useOutputMode ){ |
| 24859 | 25602 | /* If neither the --csv or --ascii options are specified, then set |
| 24860 | 25603 | ** the column and row separator characters from the output mode. */ |
| 24861 | 25604 | nSep = strlen30(p->colSeparator); |
| 24862 | 25605 | if( nSep==0 ){ |
| 24863 | | - raw_printf(stderr, |
| 24864 | | - "Error: non-null column separator required for import\n"); |
| 25606 | + eputz("Error: non-null column separator required for import\n"); |
| 24865 | 25607 | goto meta_command_exit; |
| 24866 | 25608 | } |
| 24867 | 25609 | if( nSep>1 ){ |
| 24868 | | - raw_printf(stderr, |
| 24869 | | - "Error: multi-character column separators not allowed" |
| 25610 | + eputz("Error: multi-character column separators not allowed" |
| 24870 | 25611 | " for import\n"); |
| 24871 | 25612 | goto meta_command_exit; |
| 24872 | 25613 | } |
| 24873 | 25614 | nSep = strlen30(p->rowSeparator); |
| 24874 | 25615 | if( nSep==0 ){ |
| 24875 | | - raw_printf(stderr, |
| 24876 | | - "Error: non-null row separator required for import\n"); |
| 25616 | + eputz("Error: non-null row separator required for import\n"); |
| 24877 | 25617 | goto meta_command_exit; |
| 24878 | 25618 | } |
| 24879 | 25619 | if( nSep==2 && p->mode==MODE_Csv |
| 24880 | 25620 | && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 |
| 24881 | 25621 | ){ |
| | @@ -24885,22 +25625,22 @@ |
| 24885 | 25625 | ** and output row separators. */ |
| 24886 | 25626 | sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); |
| 24887 | 25627 | nSep = strlen30(p->rowSeparator); |
| 24888 | 25628 | } |
| 24889 | 25629 | if( nSep>1 ){ |
| 24890 | | - raw_printf(stderr, "Error: multi-character row separators not allowed" |
| 24891 | | - " for import\n"); |
| 25630 | + eputz("Error: multi-character row separators not allowed" |
| 25631 | + " for import\n"); |
| 24892 | 25632 | goto meta_command_exit; |
| 24893 | 25633 | } |
| 24894 | 25634 | sCtx.cColSep = (u8)p->colSeparator[0]; |
| 24895 | 25635 | sCtx.cRowSep = (u8)p->rowSeparator[0]; |
| 24896 | 25636 | } |
| 24897 | 25637 | sCtx.zFile = zFile; |
| 24898 | 25638 | sCtx.nLine = 1; |
| 24899 | 25639 | if( sCtx.zFile[0]=='|' ){ |
| 24900 | 25640 | #ifdef SQLITE_OMIT_POPEN |
| 24901 | | - raw_printf(stderr, "Error: pipes are not supported in this OS\n"); |
| 25641 | + eputz("Error: pipes are not supported in this OS\n"); |
| 24902 | 25642 | goto meta_command_exit; |
| 24903 | 25643 | #else |
| 24904 | 25644 | sCtx.in = popen(sCtx.zFile+1, "r"); |
| 24905 | 25645 | sCtx.zFile = "<pipe>"; |
| 24906 | 25646 | sCtx.xCloser = pclose; |
| | @@ -24908,23 +25648,23 @@ |
| 24908 | 25648 | }else{ |
| 24909 | 25649 | sCtx.in = fopen(sCtx.zFile, "rb"); |
| 24910 | 25650 | sCtx.xCloser = fclose; |
| 24911 | 25651 | } |
| 24912 | 25652 | if( sCtx.in==0 ){ |
| 24913 | | - utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile); |
| 25653 | + eputf("Error: cannot open \"%s\"\n", zFile); |
| 24914 | 25654 | goto meta_command_exit; |
| 24915 | 25655 | } |
| 24916 | 25656 | if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){ |
| 24917 | 25657 | char zSep[2]; |
| 24918 | 25658 | zSep[1] = 0; |
| 24919 | 25659 | zSep[0] = sCtx.cColSep; |
| 24920 | | - utf8_printf(p->out, "Column separator "); |
| 24921 | | - output_c_string(p->out, zSep); |
| 24922 | | - utf8_printf(p->out, ", row separator "); |
| 25660 | + oputz("Column separator "); |
| 25661 | + output_c_string(zSep); |
| 25662 | + oputz(", row separator "); |
| 24923 | 25663 | zSep[0] = sCtx.cRowSep; |
| 24924 | | - output_c_string(p->out, zSep); |
| 24925 | | - utf8_printf(p->out, "\n"); |
| 25664 | + output_c_string(zSep); |
| 25665 | + oputz("\n"); |
| 24926 | 25666 | } |
| 24927 | 25667 | sCtx.z = sqlite3_malloc64(120); |
| 24928 | 25668 | if( sCtx.z==0 ){ |
| 24929 | 25669 | import_cleanup(&sCtx); |
| 24930 | 25670 | shell_out_of_memory(); |
| | @@ -24955,18 +25695,18 @@ |
| 24955 | 25695 | zAutoColumn(sCtx.z, &dbCols, 0); |
| 24956 | 25696 | if( sCtx.cTerm!=sCtx.cColSep ) break; |
| 24957 | 25697 | } |
| 24958 | 25698 | zColDefs = zAutoColumn(0, &dbCols, &zRenames); |
| 24959 | 25699 | if( zRenames!=0 ){ |
| 24960 | | - utf8_printf((stdin_is_interactive && p->in==stdin)? p->out : stderr, |
| 24961 | | - "Columns renamed during .import %s due to duplicates:\n" |
| 24962 | | - "%s\n", sCtx.zFile, zRenames); |
| 25700 | + sputf((stdin_is_interactive && p->in==stdin)? p->out : stderr, |
| 25701 | + "Columns renamed during .import %s due to duplicates:\n" |
| 25702 | + "%s\n", sCtx.zFile, zRenames); |
| 24963 | 25703 | sqlite3_free(zRenames); |
| 24964 | 25704 | } |
| 24965 | 25705 | assert(dbCols==0); |
| 24966 | 25706 | if( zColDefs==0 ){ |
| 24967 | | - utf8_printf(stderr,"%s: empty file\n", sCtx.zFile); |
| 25707 | + eputf("%s: empty file\n", sCtx.zFile); |
| 24968 | 25708 | import_fail: |
| 24969 | 25709 | sqlite3_free(zCreate); |
| 24970 | 25710 | sqlite3_free(zSql); |
| 24971 | 25711 | sqlite3_free(zFullTabName); |
| 24972 | 25712 | import_cleanup(&sCtx); |
| | @@ -24973,24 +25713,24 @@ |
| 24973 | 25713 | rc = 1; |
| 24974 | 25714 | goto meta_command_exit; |
| 24975 | 25715 | } |
| 24976 | 25716 | zCreate = sqlite3_mprintf("%z%z\n", zCreate, zColDefs); |
| 24977 | 25717 | if( eVerbose>=1 ){ |
| 24978 | | - utf8_printf(p->out, "%s\n", zCreate); |
| 25718 | + oputf("%s\n", zCreate); |
| 24979 | 25719 | } |
| 24980 | 25720 | rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); |
| 24981 | 25721 | if( rc ){ |
| 24982 | | - utf8_printf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); |
| 25722 | + eputf("%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); |
| 24983 | 25723 | goto import_fail; |
| 24984 | 25724 | } |
| 24985 | 25725 | sqlite3_free(zCreate); |
| 24986 | 25726 | zCreate = 0; |
| 24987 | 25727 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 24988 | 25728 | } |
| 24989 | 25729 | if( rc ){ |
| 24990 | 25730 | if (pStmt) sqlite3_finalize(pStmt); |
| 24991 | | - utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db)); |
| 25731 | + eputf("Error: %s\n", sqlite3_errmsg(p->db)); |
| 24992 | 25732 | goto import_fail; |
| 24993 | 25733 | } |
| 24994 | 25734 | sqlite3_free(zSql); |
| 24995 | 25735 | nCol = sqlite3_column_count(pStmt); |
| 24996 | 25736 | sqlite3_finalize(pStmt); |
| | @@ -25008,15 +25748,15 @@ |
| 25008 | 25748 | zSql[j++] = '?'; |
| 25009 | 25749 | } |
| 25010 | 25750 | zSql[j++] = ')'; |
| 25011 | 25751 | zSql[j] = 0; |
| 25012 | 25752 | if( eVerbose>=2 ){ |
| 25013 | | - utf8_printf(p->out, "Insert using: %s\n", zSql); |
| 25753 | + oputf("Insert using: %s\n", zSql); |
| 25014 | 25754 | } |
| 25015 | 25755 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 25016 | 25756 | if( rc ){ |
| 25017 | | - utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); |
| 25757 | + eputf("Error: %s\n", sqlite3_errmsg(p->db)); |
| 25018 | 25758 | if (pStmt) sqlite3_finalize(pStmt); |
| 25019 | 25759 | goto import_fail; |
| 25020 | 25760 | } |
| 25021 | 25761 | sqlite3_free(zSql); |
| 25022 | 25762 | sqlite3_free(zFullTabName); |
| | @@ -25045,32 +25785,31 @@ |
| 25045 | 25785 | if( z==0 && (xRead==csv_read_one_field) && i==nCol-1 && i>0 ){ |
| 25046 | 25786 | z = ""; |
| 25047 | 25787 | } |
| 25048 | 25788 | sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT); |
| 25049 | 25789 | if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){ |
| 25050 | | - utf8_printf(stderr, "%s:%d: expected %d columns but found %d - " |
| 25051 | | - "filling the rest with NULL\n", |
| 25052 | | - sCtx.zFile, startLine, nCol, i+1); |
| 25790 | + eputf("%s:%d: expected %d columns but found %d" |
| 25791 | + " - filling the rest with NULL\n", |
| 25792 | + sCtx.zFile, startLine, nCol, i+1); |
| 25053 | 25793 | i += 2; |
| 25054 | 25794 | while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; } |
| 25055 | 25795 | } |
| 25056 | 25796 | } |
| 25057 | 25797 | if( sCtx.cTerm==sCtx.cColSep ){ |
| 25058 | 25798 | do{ |
| 25059 | 25799 | xRead(&sCtx); |
| 25060 | 25800 | i++; |
| 25061 | 25801 | }while( sCtx.cTerm==sCtx.cColSep ); |
| 25062 | | - utf8_printf(stderr, "%s:%d: expected %d columns but found %d - " |
| 25063 | | - "extras ignored\n", |
| 25064 | | - sCtx.zFile, startLine, nCol, i); |
| 25802 | + eputf("%s:%d: expected %d columns but found %d - extras ignored\n", |
| 25803 | + sCtx.zFile, startLine, nCol, i); |
| 25065 | 25804 | } |
| 25066 | 25805 | if( i>=nCol ){ |
| 25067 | 25806 | sqlite3_step(pStmt); |
| 25068 | 25807 | rc = sqlite3_reset(pStmt); |
| 25069 | 25808 | if( rc!=SQLITE_OK ){ |
| 25070 | | - utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, |
| 25071 | | - startLine, sqlite3_errmsg(p->db)); |
| 25809 | + eputf("%s:%d: INSERT failed: %s\n", |
| 25810 | + sCtx.zFile, startLine, sqlite3_errmsg(p->db)); |
| 25072 | 25811 | sCtx.nErr++; |
| 25073 | 25812 | }else{ |
| 25074 | 25813 | sCtx.nRow++; |
| 25075 | 25814 | } |
| 25076 | 25815 | } |
| | @@ -25078,13 +25817,12 @@ |
| 25078 | 25817 | |
| 25079 | 25818 | import_cleanup(&sCtx); |
| 25080 | 25819 | sqlite3_finalize(pStmt); |
| 25081 | 25820 | if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); |
| 25082 | 25821 | if( eVerbose>0 ){ |
| 25083 | | - utf8_printf(p->out, |
| 25084 | | - "Added %d rows with %d errors using %d lines of input\n", |
| 25085 | | - sCtx.nRow, sCtx.nErr, sCtx.nLine-1); |
| 25822 | + oputf("Added %d rows with %d errors using %d lines of input\n", |
| 25823 | + sCtx.nRow, sCtx.nErr, sCtx.nLine-1); |
| 25086 | 25824 | } |
| 25087 | 25825 | }else |
| 25088 | 25826 | #endif /* !defined(SQLITE_SHELL_FIDDLE) */ |
| 25089 | 25827 | |
| 25090 | 25828 | #ifndef SQLITE_UNTESTABLE |
| | @@ -25095,18 +25833,18 @@ |
| 25095 | 25833 | int tnum = 0; |
| 25096 | 25834 | int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */ |
| 25097 | 25835 | int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */ |
| 25098 | 25836 | int i; |
| 25099 | 25837 | if( !ShellHasFlag(p,SHFLG_TestingMode) ){ |
| 25100 | | - utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n", |
| 25101 | | - "imposter"); |
| 25838 | + eputf(".%s unavailable without --unsafe-testing\n", |
| 25839 | + "imposter"); |
| 25102 | 25840 | rc = 1; |
| 25103 | 25841 | goto meta_command_exit; |
| 25104 | 25842 | } |
| 25105 | 25843 | if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){ |
| 25106 | | - utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n" |
| 25107 | | - " .imposter off\n"); |
| 25844 | + eputz("Usage: .imposter INDEX IMPOSTER\n" |
| 25845 | + " .imposter off\n"); |
| 25108 | 25846 | /* Also allowed, but not documented: |
| 25109 | 25847 | ** |
| 25110 | 25848 | ** .imposter TABLE IMPOSTER |
| 25111 | 25849 | ** |
| 25112 | 25850 | ** where TABLE is a WITHOUT ROWID table. In that case, the |
| | @@ -25161,11 +25899,11 @@ |
| 25161 | 25899 | zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol); |
| 25162 | 25900 | } |
| 25163 | 25901 | } |
| 25164 | 25902 | sqlite3_finalize(pStmt); |
| 25165 | 25903 | if( i==0 || tnum==0 ){ |
| 25166 | | - utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]); |
| 25904 | + eputf("no such index: \"%s\"\n", azArg[1]); |
| 25167 | 25905 | rc = 1; |
| 25168 | 25906 | sqlite3_free(zCollist); |
| 25169 | 25907 | goto meta_command_exit; |
| 25170 | 25908 | } |
| 25171 | 25909 | if( lenPK==0 ) lenPK = 100000; |
| | @@ -25176,20 +25914,18 @@ |
| 25176 | 25914 | rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum); |
| 25177 | 25915 | if( rc==SQLITE_OK ){ |
| 25178 | 25916 | rc = sqlite3_exec(p->db, zSql, 0, 0, 0); |
| 25179 | 25917 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0); |
| 25180 | 25918 | if( rc ){ |
| 25181 | | - utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db)); |
| 25919 | + eputf("Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db)); |
| 25182 | 25920 | }else{ |
| 25183 | | - utf8_printf(stdout, "%s;\n", zSql); |
| 25184 | | - raw_printf(stdout, |
| 25185 | | - "WARNING: writing to an imposter table will corrupt the \"%s\" %s!\n", |
| 25186 | | - azArg[1], isWO ? "table" : "index" |
| 25187 | | - ); |
| 25921 | + sputf(stdout, "%s;\n", zSql); |
| 25922 | + sputf(stdout, "WARNING: writing to an imposter table will corrupt" |
| 25923 | + " the \"%s\" %s!\n", azArg[1], isWO ? "table" : "index"); |
| 25188 | 25924 | } |
| 25189 | 25925 | }else{ |
| 25190 | | - raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc); |
| 25926 | + eputf("SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc); |
| 25191 | 25927 | rc = 1; |
| 25192 | 25928 | } |
| 25193 | 25929 | sqlite3_free(zSql); |
| 25194 | 25930 | }else |
| 25195 | 25931 | #endif /* !defined(SQLITE_OMIT_TEST_CONTROL) */ |
| | @@ -25205,11 +25941,11 @@ |
| 25205 | 25941 | sqlite3IoTrace = iotracePrintf; |
| 25206 | 25942 | iotrace = stdout; |
| 25207 | 25943 | }else{ |
| 25208 | 25944 | iotrace = fopen(azArg[1], "w"); |
| 25209 | 25945 | if( iotrace==0 ){ |
| 25210 | | - utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]); |
| 25946 | + eputf("Error: cannot open \"%s\"\n", azArg[1]); |
| 25211 | 25947 | sqlite3IoTrace = 0; |
| 25212 | 25948 | rc = 1; |
| 25213 | 25949 | }else{ |
| 25214 | 25950 | sqlite3IoTrace = iotracePrintf; |
| 25215 | 25951 | } |
| | @@ -25237,15 +25973,15 @@ |
| 25237 | 25973 | }; |
| 25238 | 25974 | int i, n2; |
| 25239 | 25975 | open_db(p, 0); |
| 25240 | 25976 | if( nArg==1 ){ |
| 25241 | 25977 | for(i=0; i<ArraySize(aLimit); i++){ |
| 25242 | | - printf("%20s %d\n", aLimit[i].zLimitName, |
| 25243 | | - sqlite3_limit(p->db, aLimit[i].limitCode, -1)); |
| 25978 | + sputf(stdout, "%20s %d\n", aLimit[i].zLimitName, |
| 25979 | + sqlite3_limit(p->db, aLimit[i].limitCode, -1)); |
| 25244 | 25980 | } |
| 25245 | 25981 | }else if( nArg>3 ){ |
| 25246 | | - raw_printf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n"); |
| 25982 | + eputz("Usage: .limit NAME ?NEW-VALUE?\n"); |
| 25247 | 25983 | rc = 1; |
| 25248 | 25984 | goto meta_command_exit; |
| 25249 | 25985 | }else{ |
| 25250 | 25986 | int iLimit = -1; |
| 25251 | 25987 | n2 = strlen30(azArg[1]); |
| | @@ -25252,29 +25988,29 @@ |
| 25252 | 25988 | for(i=0; i<ArraySize(aLimit); i++){ |
| 25253 | 25989 | if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){ |
| 25254 | 25990 | if( iLimit<0 ){ |
| 25255 | 25991 | iLimit = i; |
| 25256 | 25992 | }else{ |
| 25257 | | - utf8_printf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]); |
| 25993 | + eputf("ambiguous limit: \"%s\"\n", azArg[1]); |
| 25258 | 25994 | rc = 1; |
| 25259 | 25995 | goto meta_command_exit; |
| 25260 | 25996 | } |
| 25261 | 25997 | } |
| 25262 | 25998 | } |
| 25263 | 25999 | if( iLimit<0 ){ |
| 25264 | | - utf8_printf(stderr, "unknown limit: \"%s\"\n" |
| 25265 | | - "enter \".limits\" with no arguments for a list.\n", |
| 25266 | | - azArg[1]); |
| 26000 | + eputf("unknown limit: \"%s\"\n" |
| 26001 | + "enter \".limits\" with no arguments for a list.\n", |
| 26002 | + azArg[1]); |
| 25267 | 26003 | rc = 1; |
| 25268 | 26004 | goto meta_command_exit; |
| 25269 | 26005 | } |
| 25270 | 26006 | if( nArg==3 ){ |
| 25271 | 26007 | sqlite3_limit(p->db, aLimit[iLimit].limitCode, |
| 25272 | 26008 | (int)integerValue(azArg[2])); |
| 25273 | 26009 | } |
| 25274 | | - printf("%20s %d\n", aLimit[iLimit].zLimitName, |
| 25275 | | - sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1)); |
| 26010 | + sputf(stdout, "%20s %d\n", aLimit[iLimit].zLimitName, |
| 26011 | + sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1)); |
| 25276 | 26012 | } |
| 25277 | 26013 | }else |
| 25278 | 26014 | |
| 25279 | 26015 | if( c=='l' && n>2 && cli_strncmp(azArg[0], "lint", n)==0 ){ |
| 25280 | 26016 | open_db(p, 0); |
| | @@ -25286,38 +26022,38 @@ |
| 25286 | 26022 | const char *zFile, *zProc; |
| 25287 | 26023 | char *zErrMsg = 0; |
| 25288 | 26024 | failIfSafeMode(p, "cannot run .load in safe mode"); |
| 25289 | 26025 | if( nArg<2 || azArg[1][0]==0 ){ |
| 25290 | 26026 | /* Must have a non-empty FILE. (Will not load self.) */ |
| 25291 | | - raw_printf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n"); |
| 26027 | + eputz("Usage: .load FILE ?ENTRYPOINT?\n"); |
| 25292 | 26028 | rc = 1; |
| 25293 | 26029 | goto meta_command_exit; |
| 25294 | 26030 | } |
| 25295 | 26031 | zFile = azArg[1]; |
| 25296 | 26032 | zProc = nArg>=3 ? azArg[2] : 0; |
| 25297 | 26033 | open_db(p, 0); |
| 25298 | 26034 | rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg); |
| 25299 | 26035 | if( rc!=SQLITE_OK ){ |
| 25300 | | - utf8_printf(stderr, "Error: %s\n", zErrMsg); |
| 26036 | + eputf("Error: %s\n", zErrMsg); |
| 25301 | 26037 | sqlite3_free(zErrMsg); |
| 25302 | 26038 | rc = 1; |
| 25303 | 26039 | } |
| 25304 | 26040 | }else |
| 25305 | 26041 | #endif |
| 25306 | 26042 | |
| 25307 | 26043 | if( c=='l' && cli_strncmp(azArg[0], "log", n)==0 ){ |
| 25308 | 26044 | if( nArg!=2 ){ |
| 25309 | | - raw_printf(stderr, "Usage: .log FILENAME\n"); |
| 26045 | + eputz("Usage: .log FILENAME\n"); |
| 25310 | 26046 | rc = 1; |
| 25311 | 26047 | }else{ |
| 25312 | 26048 | const char *zFile = azArg[1]; |
| 25313 | 26049 | if( p->bSafeMode |
| 25314 | 26050 | && cli_strcmp(zFile,"on")!=0 |
| 25315 | 26051 | && cli_strcmp(zFile,"off")!=0 |
| 25316 | 26052 | ){ |
| 25317 | | - raw_printf(stdout, "cannot set .log to anything other " |
| 25318 | | - "than \"on\" or \"off\"\n"); |
| 26053 | + sputz(stdout, "cannot set .log to anything other" |
| 26054 | + " than \"on\" or \"off\"\n"); |
| 25319 | 26055 | zFile = "off"; |
| 25320 | 26056 | } |
| 25321 | 26057 | output_file_close(p->pLog); |
| 25322 | 26058 | if( cli_strcmp(zFile,"on")==0 ) zFile = "stdout"; |
| 25323 | 26059 | p->pLog = output_file_open(zFile, 0); |
| | @@ -25352,37 +26088,35 @@ |
| 25352 | 26088 | cmOpts = cmo; |
| 25353 | 26089 | } |
| 25354 | 26090 | }else if( zTabname==0 ){ |
| 25355 | 26091 | zTabname = z; |
| 25356 | 26092 | }else if( z[0]=='-' ){ |
| 25357 | | - utf8_printf(stderr, "unknown option: %s\n", z); |
| 25358 | | - utf8_printf(stderr, "options:\n" |
| 25359 | | - " --noquote\n" |
| 25360 | | - " --quote\n" |
| 25361 | | - " --wordwrap on/off\n" |
| 25362 | | - " --wrap N\n" |
| 25363 | | - " --ww\n"); |
| 26093 | + eputf("unknown option: %s\n", z); |
| 26094 | + eputz("options:\n" |
| 26095 | + " --noquote\n" |
| 26096 | + " --quote\n" |
| 26097 | + " --wordwrap on/off\n" |
| 26098 | + " --wrap N\n" |
| 26099 | + " --ww\n"); |
| 25364 | 26100 | rc = 1; |
| 25365 | 26101 | goto meta_command_exit; |
| 25366 | 26102 | }else{ |
| 25367 | | - utf8_printf(stderr, "extra argument: \"%s\"\n", z); |
| 26103 | + eputf("extra argument: \"%s\"\n", z); |
| 25368 | 26104 | rc = 1; |
| 25369 | 26105 | goto meta_command_exit; |
| 25370 | 26106 | } |
| 25371 | 26107 | } |
| 25372 | 26108 | if( zMode==0 ){ |
| 25373 | 26109 | if( p->mode==MODE_Column |
| 25374 | 26110 | || (p->mode>=MODE_Markdown && p->mode<=MODE_Box) |
| 25375 | 26111 | ){ |
| 25376 | | - raw_printf |
| 25377 | | - (p->out, |
| 25378 | | - "current output mode: %s --wrap %d --wordwrap %s --%squote\n", |
| 25379 | | - modeDescr[p->mode], p->cmOpts.iWrap, |
| 25380 | | - p->cmOpts.bWordWrap ? "on" : "off", |
| 25381 | | - p->cmOpts.bQuote ? "" : "no"); |
| 26112 | + oputf("current output mode: %s --wrap %d --wordwrap %s --%squote\n", |
| 26113 | + modeDescr[p->mode], p->cmOpts.iWrap, |
| 26114 | + p->cmOpts.bWordWrap ? "on" : "off", |
| 26115 | + p->cmOpts.bQuote ? "" : "no"); |
| 25382 | 26116 | }else{ |
| 25383 | | - raw_printf(p->out, "current output mode: %s\n", modeDescr[p->mode]); |
| 26117 | + oputf("current output mode: %s\n", modeDescr[p->mode]); |
| 25384 | 26118 | } |
| 25385 | 26119 | zMode = modeDescr[p->mode]; |
| 25386 | 26120 | } |
| 25387 | 26121 | n2 = strlen30(zMode); |
| 25388 | 26122 | if( cli_strncmp(zMode,"lines",n2)==0 ){ |
| | @@ -25437,26 +26171,26 @@ |
| 25437 | 26171 | }else if( cli_strncmp(zMode,"off",n2)==0 ){ |
| 25438 | 26172 | p->mode = MODE_Off; |
| 25439 | 26173 | }else if( cli_strncmp(zMode,"json",n2)==0 ){ |
| 25440 | 26174 | p->mode = MODE_Json; |
| 25441 | 26175 | }else{ |
| 25442 | | - raw_printf(stderr, "Error: mode should be one of: " |
| 25443 | | - "ascii box column csv html insert json line list markdown " |
| 25444 | | - "qbox quote table tabs tcl\n"); |
| 26176 | + eputz("Error: mode should be one of: " |
| 26177 | + "ascii box column csv html insert json line list markdown " |
| 26178 | + "qbox quote table tabs tcl\n"); |
| 25445 | 26179 | rc = 1; |
| 25446 | 26180 | } |
| 25447 | 26181 | p->cMode = p->mode; |
| 25448 | 26182 | }else |
| 25449 | 26183 | |
| 25450 | 26184 | #ifndef SQLITE_SHELL_FIDDLE |
| 25451 | 26185 | if( c=='n' && cli_strcmp(azArg[0], "nonce")==0 ){ |
| 25452 | 26186 | if( nArg!=2 ){ |
| 25453 | | - raw_printf(stderr, "Usage: .nonce NONCE\n"); |
| 26187 | + eputz("Usage: .nonce NONCE\n"); |
| 25454 | 26188 | rc = 1; |
| 25455 | 26189 | }else if( p->zNonce==0 || cli_strcmp(azArg[1],p->zNonce)!=0 ){ |
| 25456 | | - raw_printf(stderr, "line %d: incorrect nonce: \"%s\"\n", |
| 25457 | | - p->lineno, azArg[1]); |
| 26190 | + eputf("line %d: incorrect nonce: \"%s\"\n", |
| 26191 | + p->lineno, azArg[1]); |
| 25458 | 26192 | exit(1); |
| 25459 | 26193 | }else{ |
| 25460 | 26194 | p->bSafeMode = 0; |
| 25461 | 26195 | return 0; /* Return immediately to bypass the safe mode reset |
| 25462 | 26196 | ** at the end of this procedure */ |
| | @@ -25467,11 +26201,11 @@ |
| 25467 | 26201 | if( c=='n' && cli_strncmp(azArg[0], "nullvalue", n)==0 ){ |
| 25468 | 26202 | if( nArg==2 ){ |
| 25469 | 26203 | sqlite3_snprintf(sizeof(p->nullValue), p->nullValue, |
| 25470 | 26204 | "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]); |
| 25471 | 26205 | }else{ |
| 25472 | | - raw_printf(stderr, "Usage: .nullvalue STRING\n"); |
| 26206 | + eputz("Usage: .nullvalue STRING\n"); |
| 25473 | 26207 | rc = 1; |
| 25474 | 26208 | } |
| 25475 | 26209 | }else |
| 25476 | 26210 | |
| 25477 | 26211 | if( c=='o' && cli_strncmp(azArg[0], "open", n)==0 && n>=2 ){ |
| | @@ -25506,15 +26240,15 @@ |
| 25506 | 26240 | p->szMax = integerValue(azArg[++iName]); |
| 25507 | 26241 | #endif /* SQLITE_OMIT_DESERIALIZE */ |
| 25508 | 26242 | }else |
| 25509 | 26243 | #endif /* !SQLITE_SHELL_FIDDLE */ |
| 25510 | 26244 | if( z[0]=='-' ){ |
| 25511 | | - utf8_printf(stderr, "unknown option: %s\n", z); |
| 26245 | + eputf("unknown option: %s\n", z); |
| 25512 | 26246 | rc = 1; |
| 25513 | 26247 | goto meta_command_exit; |
| 25514 | 26248 | }else if( zFN ){ |
| 25515 | | - utf8_printf(stderr, "extra argument: \"%s\"\n", z); |
| 26249 | + eputf("extra argument: \"%s\"\n", z); |
| 25516 | 26250 | rc = 1; |
| 25517 | 26251 | goto meta_command_exit; |
| 25518 | 26252 | }else{ |
| 25519 | 26253 | zFN = z; |
| 25520 | 26254 | } |
| | @@ -25552,11 +26286,11 @@ |
| 25552 | 26286 | zNewFilename = 0; |
| 25553 | 26287 | } |
| 25554 | 26288 | p->pAuxDb->zDbFilename = zNewFilename; |
| 25555 | 26289 | open_db(p, OPEN_DB_KEEPALIVE); |
| 25556 | 26290 | if( p->db==0 ){ |
| 25557 | | - utf8_printf(stderr, "Error: cannot open '%s'\n", zNewFilename); |
| 26291 | + eputf("Error: cannot open '%s'\n", zNewFilename); |
| 25558 | 26292 | sqlite3_free(zNewFilename); |
| 25559 | 26293 | }else{ |
| 25560 | 26294 | p->pAuxDb->zFreeOnClose = zNewFilename; |
| 25561 | 26295 | } |
| 25562 | 26296 | } |
| | @@ -25576,13 +26310,13 @@ |
| 25576 | 26310 | char *zFile = 0; |
| 25577 | 26311 | int bTxtMode = 0; |
| 25578 | 26312 | int i; |
| 25579 | 26313 | int eMode = 0; |
| 25580 | 26314 | int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */ |
| 25581 | | - unsigned char zBOM[4]; /* Byte-order mark to using if --bom is present */ |
| 26315 | + static const char *zBomUtf8 = "\xef\xbb\xbf"; |
| 26316 | + const char *zBom = 0; |
| 25582 | 26317 | |
| 25583 | | - zBOM[0] = 0; |
| 25584 | 26318 | failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]); |
| 25585 | 26319 | if( c=='e' ){ |
| 25586 | 26320 | eMode = 'x'; |
| 25587 | 26321 | bOnce = 2; |
| 25588 | 26322 | }else if( cli_strncmp(azArg[0],"once",n)==0 ){ |
| | @@ -25591,21 +26325,17 @@ |
| 25591 | 26325 | for(i=1; i<nArg; i++){ |
| 25592 | 26326 | char *z = azArg[i]; |
| 25593 | 26327 | if( z[0]=='-' ){ |
| 25594 | 26328 | if( z[1]=='-' ) z++; |
| 25595 | 26329 | if( cli_strcmp(z,"-bom")==0 ){ |
| 25596 | | - zBOM[0] = 0xef; |
| 25597 | | - zBOM[1] = 0xbb; |
| 25598 | | - zBOM[2] = 0xbf; |
| 25599 | | - zBOM[3] = 0; |
| 26330 | + zBom = zBomUtf8; |
| 25600 | 26331 | }else if( c!='e' && cli_strcmp(z,"-x")==0 ){ |
| 25601 | 26332 | eMode = 'x'; /* spreadsheet */ |
| 25602 | 26333 | }else if( c!='e' && cli_strcmp(z,"-e")==0 ){ |
| 25603 | 26334 | eMode = 'e'; /* text editor */ |
| 25604 | 26335 | }else{ |
| 25605 | | - utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", |
| 25606 | | - azArg[i]); |
| 26336 | + oputf("ERROR: unknown option: \"%s\". Usage:\n", azArg[i]); |
| 25607 | 26337 | showHelp(p->out, azArg[0]); |
| 25608 | 26338 | rc = 1; |
| 25609 | 26339 | goto meta_command_exit; |
| 25610 | 26340 | } |
| 25611 | 26341 | }else if( zFile==0 && eMode!='e' && eMode!='x' ){ |
| | @@ -25613,12 +26343,11 @@ |
| 25613 | 26343 | if( zFile && zFile[0]=='|' ){ |
| 25614 | 26344 | while( i+1<nArg ) zFile = sqlite3_mprintf("%z %s", zFile, azArg[++i]); |
| 25615 | 26345 | break; |
| 25616 | 26346 | } |
| 25617 | 26347 | }else{ |
| 25618 | | - utf8_printf(p->out,"ERROR: extra parameter: \"%s\". Usage:\n", |
| 25619 | | - azArg[i]); |
| 26348 | + oputf("ERROR: extra parameter: \"%s\". Usage:\n", azArg[i]); |
| 25620 | 26349 | showHelp(p->out, azArg[0]); |
| 25621 | 26350 | rc = 1; |
| 25622 | 26351 | sqlite3_free(zFile); |
| 25623 | 26352 | goto meta_command_exit; |
| 25624 | 26353 | } |
| | @@ -25653,34 +26382,34 @@ |
| 25653 | 26382 | } |
| 25654 | 26383 | #endif /* SQLITE_NOHAVE_SYSTEM */ |
| 25655 | 26384 | shell_check_oom(zFile); |
| 25656 | 26385 | if( zFile[0]=='|' ){ |
| 25657 | 26386 | #ifdef SQLITE_OMIT_POPEN |
| 25658 | | - raw_printf(stderr, "Error: pipes are not supported in this OS\n"); |
| 26387 | + eputz("Error: pipes are not supported in this OS\n"); |
| 25659 | 26388 | rc = 1; |
| 25660 | | - p->out = stdout; |
| 26389 | + output_redir(p, stdout); |
| 25661 | 26390 | #else |
| 25662 | | - p->out = popen(zFile + 1, "w"); |
| 25663 | | - if( p->out==0 ){ |
| 25664 | | - utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1); |
| 25665 | | - p->out = stdout; |
| 26391 | + FILE *pfPipe = popen(zFile + 1, "w"); |
| 26392 | + if( pfPipe==0 ){ |
| 26393 | + eputf("Error: cannot open pipe \"%s\"\n", zFile + 1); |
| 25666 | 26394 | rc = 1; |
| 25667 | 26395 | }else{ |
| 25668 | | - if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out); |
| 26396 | + output_redir(p, pfPipe); |
| 26397 | + if( zBom ) oputz(zBom); |
| 25669 | 26398 | sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); |
| 25670 | 26399 | } |
| 25671 | 26400 | #endif |
| 25672 | 26401 | }else{ |
| 25673 | | - p->out = output_file_open(zFile, bTxtMode); |
| 25674 | | - if( p->out==0 ){ |
| 26402 | + FILE *pfFile = output_file_open(zFile, bTxtMode); |
| 26403 | + if( pfFile==0 ){ |
| 25675 | 26404 | if( cli_strcmp(zFile,"off")!=0 ){ |
| 25676 | | - utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile); |
| 26405 | + eputf("Error: cannot write to \"%s\"\n", zFile); |
| 25677 | 26406 | } |
| 25678 | | - p->out = stdout; |
| 25679 | 26407 | rc = 1; |
| 25680 | 26408 | } else { |
| 25681 | | - if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out); |
| 26409 | + output_redir(p, pfFile); |
| 26410 | + if( zBom ) oputz(zBom); |
| 25682 | 26411 | sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); |
| 25683 | 26412 | } |
| 25684 | 26413 | } |
| 25685 | 26414 | sqlite3_free(zFile); |
| 25686 | 26415 | }else |
| | @@ -25717,12 +26446,12 @@ |
| 25717 | 26446 | if( len ){ |
| 25718 | 26447 | rx = sqlite3_prepare_v2(p->db, |
| 25719 | 26448 | "SELECT key, quote(value) " |
| 25720 | 26449 | "FROM temp.sqlite_parameters;", -1, &pStmt, 0); |
| 25721 | 26450 | while( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 25722 | | - utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0), |
| 25723 | | - sqlite3_column_text(pStmt,1)); |
| 26451 | + oputf("%-*s %s\n", len, sqlite3_column_text(pStmt,0), |
| 26452 | + sqlite3_column_text(pStmt,1)); |
| 25724 | 26453 | } |
| 25725 | 26454 | sqlite3_finalize(pStmt); |
| 25726 | 26455 | } |
| 25727 | 26456 | }else |
| 25728 | 26457 | |
| | @@ -25762,11 +26491,11 @@ |
| 25762 | 26491 | "VALUES(%Q,%Q);", zKey, zValue); |
| 25763 | 26492 | shell_check_oom(zSql); |
| 25764 | 26493 | rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 25765 | 26494 | sqlite3_free(zSql); |
| 25766 | 26495 | if( rx!=SQLITE_OK ){ |
| 25767 | | - utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db)); |
| 26496 | + oputf("Error: %s\n", sqlite3_errmsg(p->db)); |
| 25768 | 26497 | sqlite3_finalize(pStmt); |
| 25769 | 26498 | pStmt = 0; |
| 25770 | 26499 | rc = 1; |
| 25771 | 26500 | } |
| 25772 | 26501 | } |
| | @@ -25791,14 +26520,14 @@ |
| 25791 | 26520 | }else |
| 25792 | 26521 | |
| 25793 | 26522 | if( c=='p' && n>=3 && cli_strncmp(azArg[0], "print", n)==0 ){ |
| 25794 | 26523 | int i; |
| 25795 | 26524 | for(i=1; i<nArg; i++){ |
| 25796 | | - if( i>1 ) raw_printf(p->out, " "); |
| 25797 | | - utf8_printf(p->out, "%s", azArg[i]); |
| 26525 | + if( i>1 ) oputz(" "); |
| 26526 | + oputz(azArg[i]); |
| 25798 | 26527 | } |
| 25799 | | - raw_printf(p->out, "\n"); |
| 26528 | + oputz("\n"); |
| 25800 | 26529 | }else |
| 25801 | 26530 | |
| 25802 | 26531 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 25803 | 26532 | if( c=='p' && n>=3 && cli_strncmp(azArg[0], "progress", n)==0 ){ |
| 25804 | 26533 | int i; |
| | @@ -25823,19 +26552,19 @@ |
| 25823 | 26552 | p->flgProgress |= SHELL_PROGRESS_ONCE; |
| 25824 | 26553 | continue; |
| 25825 | 26554 | } |
| 25826 | 26555 | if( cli_strcmp(z,"limit")==0 ){ |
| 25827 | 26556 | if( i+1>=nArg ){ |
| 25828 | | - utf8_printf(stderr, "Error: missing argument on --limit\n"); |
| 26557 | + eputz("Error: missing argument on --limit\n"); |
| 25829 | 26558 | rc = 1; |
| 25830 | 26559 | goto meta_command_exit; |
| 25831 | 26560 | }else{ |
| 25832 | 26561 | p->mxProgress = (int)integerValue(azArg[++i]); |
| 25833 | 26562 | } |
| 25834 | 26563 | continue; |
| 25835 | 26564 | } |
| 25836 | | - utf8_printf(stderr, "Error: unknown option: \"%s\"\n", azArg[i]); |
| 26565 | + eputf("Error: unknown option: \"%s\"\n", azArg[i]); |
| 25837 | 26566 | rc = 1; |
| 25838 | 26567 | goto meta_command_exit; |
| 25839 | 26568 | }else{ |
| 25840 | 26569 | nn = (int)integerValue(z); |
| 25841 | 26570 | } |
| | @@ -25864,31 +26593,31 @@ |
| 25864 | 26593 | if( c=='r' && n>=3 && cli_strncmp(azArg[0], "read", n)==0 ){ |
| 25865 | 26594 | FILE *inSaved = p->in; |
| 25866 | 26595 | int savedLineno = p->lineno; |
| 25867 | 26596 | failIfSafeMode(p, "cannot run .read in safe mode"); |
| 25868 | 26597 | if( nArg!=2 ){ |
| 25869 | | - raw_printf(stderr, "Usage: .read FILE\n"); |
| 26598 | + eputz("Usage: .read FILE\n"); |
| 25870 | 26599 | rc = 1; |
| 25871 | 26600 | goto meta_command_exit; |
| 25872 | 26601 | } |
| 25873 | 26602 | if( azArg[1][0]=='|' ){ |
| 25874 | 26603 | #ifdef SQLITE_OMIT_POPEN |
| 25875 | | - raw_printf(stderr, "Error: pipes are not supported in this OS\n"); |
| 26604 | + eputz("Error: pipes are not supported in this OS\n"); |
| 25876 | 26605 | rc = 1; |
| 25877 | 26606 | p->out = stdout; |
| 25878 | 26607 | #else |
| 25879 | 26608 | p->in = popen(azArg[1]+1, "r"); |
| 25880 | 26609 | if( p->in==0 ){ |
| 25881 | | - utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]); |
| 26610 | + eputf("Error: cannot open \"%s\"\n", azArg[1]); |
| 25882 | 26611 | rc = 1; |
| 25883 | 26612 | }else{ |
| 25884 | 26613 | rc = process_input(p); |
| 25885 | 26614 | pclose(p->in); |
| 25886 | 26615 | } |
| 25887 | 26616 | #endif |
| 25888 | 26617 | }else if( (p->in = openChrSource(azArg[1]))==0 ){ |
| 25889 | | - utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); |
| 26618 | + eputf("Error: cannot open \"%s\"\n", azArg[1]); |
| 25890 | 26619 | rc = 1; |
| 25891 | 26620 | }else{ |
| 25892 | 26621 | rc = process_input(p); |
| 25893 | 26622 | fclose(p->in); |
| 25894 | 26623 | } |
| | @@ -25911,24 +26640,24 @@ |
| 25911 | 26640 | zDb = "main"; |
| 25912 | 26641 | }else if( nArg==3 ){ |
| 25913 | 26642 | zSrcFile = azArg[2]; |
| 25914 | 26643 | zDb = azArg[1]; |
| 25915 | 26644 | }else{ |
| 25916 | | - raw_printf(stderr, "Usage: .restore ?DB? FILE\n"); |
| 26645 | + eputz("Usage: .restore ?DB? FILE\n"); |
| 25917 | 26646 | rc = 1; |
| 25918 | 26647 | goto meta_command_exit; |
| 25919 | 26648 | } |
| 25920 | 26649 | rc = sqlite3_open(zSrcFile, &pSrc); |
| 25921 | 26650 | if( rc!=SQLITE_OK ){ |
| 25922 | | - utf8_printf(stderr, "Error: cannot open \"%s\"\n", zSrcFile); |
| 26651 | + eputf("Error: cannot open \"%s\"\n", zSrcFile); |
| 25923 | 26652 | close_db(pSrc); |
| 25924 | 26653 | return 1; |
| 25925 | 26654 | } |
| 25926 | 26655 | open_db(p, 0); |
| 25927 | 26656 | pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main"); |
| 25928 | 26657 | if( pBackup==0 ){ |
| 25929 | | - utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); |
| 26658 | + eputf("Error: %s\n", sqlite3_errmsg(p->db)); |
| 25930 | 26659 | close_db(pSrc); |
| 25931 | 26660 | return 1; |
| 25932 | 26661 | } |
| 25933 | 26662 | while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK |
| 25934 | 26663 | || rc==SQLITE_BUSY ){ |
| | @@ -25939,14 +26668,14 @@ |
| 25939 | 26668 | } |
| 25940 | 26669 | sqlite3_backup_finish(pBackup); |
| 25941 | 26670 | if( rc==SQLITE_DONE ){ |
| 25942 | 26671 | rc = 0; |
| 25943 | 26672 | }else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){ |
| 25944 | | - raw_printf(stderr, "Error: source database is busy\n"); |
| 26673 | + eputz("Error: source database is busy\n"); |
| 25945 | 26674 | rc = 1; |
| 25946 | 26675 | }else{ |
| 25947 | | - utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); |
| 26676 | + eputf("Error: %s\n", sqlite3_errmsg(p->db)); |
| 25948 | 26677 | rc = 1; |
| 25949 | 26678 | } |
| 25950 | 26679 | close_db(pSrc); |
| 25951 | 26680 | }else |
| 25952 | 26681 | #endif /* !defined(SQLITE_SHELL_FIDDLE) */ |
| | @@ -25963,15 +26692,19 @@ |
| 25963 | 26692 | } |
| 25964 | 26693 | open_db(p, 0); |
| 25965 | 26694 | sqlite3_db_config( |
| 25966 | 26695 | p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0 |
| 25967 | 26696 | ); |
| 25968 | | -#ifndef SQLITE_ENABLE_STMT_SCANSTATUS |
| 25969 | | - raw_printf(stderr, "Warning: .scanstats not available in this build.\n"); |
| 26697 | +#if !defined(SQLITE_ENABLE_STMT_SCANSTATUS) |
| 26698 | + eputz("Warning: .scanstats not available in this build.\n"); |
| 26699 | +#elif !defined(SQLITE_ENABLE_BYTECODE_VTAB) |
| 26700 | + if( p->scanstatsOn==3 ){ |
| 26701 | + eputz("Warning: \".scanstats vm\" not available in this build.\n"); |
| 26702 | + } |
| 25970 | 26703 | #endif |
| 25971 | 26704 | }else{ |
| 25972 | | - raw_printf(stderr, "Usage: .scanstats on|off|est\n"); |
| 26705 | + eputz("Usage: .scanstats on|off|est\n"); |
| 25973 | 26706 | rc = 1; |
| 25974 | 26707 | } |
| 25975 | 26708 | }else |
| 25976 | 26709 | |
| 25977 | 26710 | if( c=='s' && cli_strncmp(azArg[0], "schema", n)==0 ){ |
| | @@ -25996,18 +26729,17 @@ |
| 25996 | 26729 | }else if( optionMatch(azArg[ii],"debug") ){ |
| 25997 | 26730 | bDebug = 1; |
| 25998 | 26731 | }else if( optionMatch(azArg[ii],"nosys") ){ |
| 25999 | 26732 | bNoSystemTabs = 1; |
| 26000 | 26733 | }else if( azArg[ii][0]=='-' ){ |
| 26001 | | - utf8_printf(stderr, "Unknown option: \"%s\"\n", azArg[ii]); |
| 26734 | + eputf("Unknown option: \"%s\"\n", azArg[ii]); |
| 26002 | 26735 | rc = 1; |
| 26003 | 26736 | goto meta_command_exit; |
| 26004 | 26737 | }else if( zName==0 ){ |
| 26005 | 26738 | zName = azArg[ii]; |
| 26006 | 26739 | }else{ |
| 26007 | | - raw_printf(stderr, |
| 26008 | | - "Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n"); |
| 26740 | + eputz("Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n"); |
| 26009 | 26741 | rc = 1; |
| 26010 | 26742 | goto meta_command_exit; |
| 26011 | 26743 | } |
| 26012 | 26744 | } |
| 26013 | 26745 | if( zName!=0 ){ |
| | @@ -26036,11 +26768,11 @@ |
| 26036 | 26768 | if( zDiv ){ |
| 26037 | 26769 | sqlite3_stmt *pStmt = 0; |
| 26038 | 26770 | rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list", |
| 26039 | 26771 | -1, &pStmt, 0); |
| 26040 | 26772 | if( rc ){ |
| 26041 | | - utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); |
| 26773 | + eputf("Error: %s\n", sqlite3_errmsg(p->db)); |
| 26042 | 26774 | sqlite3_finalize(pStmt); |
| 26043 | 26775 | rc = 1; |
| 26044 | 26776 | goto meta_command_exit; |
| 26045 | 26777 | } |
| 26046 | 26778 | appendText(&sSelect, "SELECT sql FROM", 0); |
| | @@ -26098,22 +26830,22 @@ |
| 26098 | 26830 | appendText(&sSelect, "name NOT LIKE 'sqlite_%%' AND ", 0); |
| 26099 | 26831 | } |
| 26100 | 26832 | appendText(&sSelect, "sql IS NOT NULL" |
| 26101 | 26833 | " ORDER BY snum, rowid", 0); |
| 26102 | 26834 | if( bDebug ){ |
| 26103 | | - utf8_printf(p->out, "SQL: %s;\n", sSelect.z); |
| 26835 | + oputf("SQL: %s;\n", sSelect.z); |
| 26104 | 26836 | }else{ |
| 26105 | 26837 | rc = sqlite3_exec(p->db, sSelect.z, callback, &data, &zErrMsg); |
| 26106 | 26838 | } |
| 26107 | 26839 | freeText(&sSelect); |
| 26108 | 26840 | } |
| 26109 | 26841 | if( zErrMsg ){ |
| 26110 | | - utf8_printf(stderr,"Error: %s\n", zErrMsg); |
| 26842 | + eputf("Error: %s\n", zErrMsg); |
| 26111 | 26843 | sqlite3_free(zErrMsg); |
| 26112 | 26844 | rc = 1; |
| 26113 | 26845 | }else if( rc != SQLITE_OK ){ |
| 26114 | | - raw_printf(stderr,"Error: querying schema information\n"); |
| 26846 | + eputz("Error: querying schema information\n"); |
| 26115 | 26847 | rc = 1; |
| 26116 | 26848 | }else{ |
| 26117 | 26849 | rc = 0; |
| 26118 | 26850 | } |
| 26119 | 26851 | }else |
| | @@ -26155,15 +26887,15 @@ |
| 26155 | 26887 | */ |
| 26156 | 26888 | if( cli_strcmp(azCmd[0],"attach")==0 ){ |
| 26157 | 26889 | if( nCmd!=2 ) goto session_syntax_error; |
| 26158 | 26890 | if( pSession->p==0 ){ |
| 26159 | 26891 | session_not_open: |
| 26160 | | - raw_printf(stderr, "ERROR: No sessions are open\n"); |
| 26892 | + eputz("ERROR: No sessions are open\n"); |
| 26161 | 26893 | }else{ |
| 26162 | 26894 | rc = sqlite3session_attach(pSession->p, azCmd[1]); |
| 26163 | 26895 | if( rc ){ |
| 26164 | | - raw_printf(stderr, "ERROR: sqlite3session_attach() returns %d\n", rc); |
| 26896 | + eputf("ERROR: sqlite3session_attach() returns %d\n",rc); |
| 26165 | 26897 | rc = 0; |
| 26166 | 26898 | } |
| 26167 | 26899 | } |
| 26168 | 26900 | }else |
| 26169 | 26901 | |
| | @@ -26178,28 +26910,27 @@ |
| 26178 | 26910 | failIfSafeMode(p, "cannot run \".session %s\" in safe mode", azCmd[0]); |
| 26179 | 26911 | if( nCmd!=2 ) goto session_syntax_error; |
| 26180 | 26912 | if( pSession->p==0 ) goto session_not_open; |
| 26181 | 26913 | out = fopen(azCmd[1], "wb"); |
| 26182 | 26914 | if( out==0 ){ |
| 26183 | | - utf8_printf(stderr, "ERROR: cannot open \"%s\" for writing\n", |
| 26184 | | - azCmd[1]); |
| 26915 | + eputf("ERROR: cannot open \"%s\" for writing\n", |
| 26916 | + azCmd[1]); |
| 26185 | 26917 | }else{ |
| 26186 | 26918 | int szChng; |
| 26187 | 26919 | void *pChng; |
| 26188 | 26920 | if( azCmd[0][0]=='c' ){ |
| 26189 | 26921 | rc = sqlite3session_changeset(pSession->p, &szChng, &pChng); |
| 26190 | 26922 | }else{ |
| 26191 | 26923 | rc = sqlite3session_patchset(pSession->p, &szChng, &pChng); |
| 26192 | 26924 | } |
| 26193 | 26925 | if( rc ){ |
| 26194 | | - printf("Error: error code %d\n", rc); |
| 26926 | + sputf(stdout, "Error: error code %d\n", rc); |
| 26195 | 26927 | rc = 0; |
| 26196 | 26928 | } |
| 26197 | 26929 | if( pChng |
| 26198 | 26930 | && fwrite(pChng, szChng, 1, out)!=1 ){ |
| 26199 | | - raw_printf(stderr, "ERROR: Failed to write entire %d-byte output\n", |
| 26200 | | - szChng); |
| 26931 | + eputf("ERROR: Failed to write entire %d-byte output\n", szChng); |
| 26201 | 26932 | } |
| 26202 | 26933 | sqlite3_free(pChng); |
| 26203 | 26934 | fclose(out); |
| 26204 | 26935 | } |
| 26205 | 26936 | }else |
| | @@ -26222,12 +26953,11 @@ |
| 26222 | 26953 | int ii; |
| 26223 | 26954 | if( nCmd>2 ) goto session_syntax_error; |
| 26224 | 26955 | ii = nCmd==1 ? -1 : booleanValue(azCmd[1]); |
| 26225 | 26956 | if( pAuxDb->nSession ){ |
| 26226 | 26957 | ii = sqlite3session_enable(pSession->p, ii); |
| 26227 | | - utf8_printf(p->out, "session %s enable flag = %d\n", |
| 26228 | | - pSession->zName, ii); |
| 26958 | + oputf("session %s enable flag = %d\n", pSession->zName, ii); |
| 26229 | 26959 | } |
| 26230 | 26960 | }else |
| 26231 | 26961 | |
| 26232 | 26962 | /* .session filter GLOB .... |
| 26233 | 26963 | ** Set a list of GLOB patterns of table names to be excluded. |
| | @@ -26240,14 +26970,11 @@ |
| 26240 | 26970 | sqlite3_free(pSession->azFilter[ii]); |
| 26241 | 26971 | } |
| 26242 | 26972 | sqlite3_free(pSession->azFilter); |
| 26243 | 26973 | nByte = sizeof(pSession->azFilter[0])*(nCmd-1); |
| 26244 | 26974 | pSession->azFilter = sqlite3_malloc( nByte ); |
| 26245 | | - if( pSession->azFilter==0 ){ |
| 26246 | | - raw_printf(stderr, "Error: out or memory\n"); |
| 26247 | | - exit(1); |
| 26248 | | - } |
| 26975 | + shell_check_oom( pSession->azFilter ); |
| 26249 | 26976 | for(ii=1; ii<nCmd; ii++){ |
| 26250 | 26977 | char *x = pSession->azFilter[ii-1] = sqlite3_mprintf("%s", azCmd[ii]); |
| 26251 | 26978 | shell_check_oom(x); |
| 26252 | 26979 | } |
| 26253 | 26980 | pSession->nFilter = ii-1; |
| | @@ -26261,12 +26988,11 @@ |
| 26261 | 26988 | int ii; |
| 26262 | 26989 | if( nCmd>2 ) goto session_syntax_error; |
| 26263 | 26990 | ii = nCmd==1 ? -1 : booleanValue(azCmd[1]); |
| 26264 | 26991 | if( pAuxDb->nSession ){ |
| 26265 | 26992 | ii = sqlite3session_indirect(pSession->p, ii); |
| 26266 | | - utf8_printf(p->out, "session %s indirect flag = %d\n", |
| 26267 | | - pSession->zName, ii); |
| 26993 | + oputf("session %s indirect flag = %d\n", pSession->zName, ii); |
| 26268 | 26994 | } |
| 26269 | 26995 | }else |
| 26270 | 26996 | |
| 26271 | 26997 | /* .session isempty |
| 26272 | 26998 | ** Determine if the session is empty |
| | @@ -26274,21 +27000,20 @@ |
| 26274 | 27000 | if( cli_strcmp(azCmd[0], "isempty")==0 ){ |
| 26275 | 27001 | int ii; |
| 26276 | 27002 | if( nCmd!=1 ) goto session_syntax_error; |
| 26277 | 27003 | if( pAuxDb->nSession ){ |
| 26278 | 27004 | ii = sqlite3session_isempty(pSession->p); |
| 26279 | | - utf8_printf(p->out, "session %s isempty flag = %d\n", |
| 26280 | | - pSession->zName, ii); |
| 27005 | + oputf("session %s isempty flag = %d\n", pSession->zName, ii); |
| 26281 | 27006 | } |
| 26282 | 27007 | }else |
| 26283 | 27008 | |
| 26284 | 27009 | /* .session list |
| 26285 | 27010 | ** List all currently open sessions |
| 26286 | 27011 | */ |
| 26287 | 27012 | if( cli_strcmp(azCmd[0],"list")==0 ){ |
| 26288 | 27013 | for(i=0; i<pAuxDb->nSession; i++){ |
| 26289 | | - utf8_printf(p->out, "%d %s\n", i, pAuxDb->aSession[i].zName); |
| 27014 | + oputf("%d %s\n", i, pAuxDb->aSession[i].zName); |
| 26290 | 27015 | } |
| 26291 | 27016 | }else |
| 26292 | 27017 | |
| 26293 | 27018 | /* .session open DB NAME |
| 26294 | 27019 | ** Open a new session called NAME on the attached database DB. |
| | @@ -26299,23 +27024,22 @@ |
| 26299 | 27024 | if( nCmd!=3 ) goto session_syntax_error; |
| 26300 | 27025 | zName = azCmd[2]; |
| 26301 | 27026 | if( zName[0]==0 ) goto session_syntax_error; |
| 26302 | 27027 | for(i=0; i<pAuxDb->nSession; i++){ |
| 26303 | 27028 | if( cli_strcmp(pAuxDb->aSession[i].zName,zName)==0 ){ |
| 26304 | | - utf8_printf(stderr, "Session \"%s\" already exists\n", zName); |
| 27029 | + eputf("Session \"%s\" already exists\n", zName); |
| 26305 | 27030 | goto meta_command_exit; |
| 26306 | 27031 | } |
| 26307 | 27032 | } |
| 26308 | 27033 | if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){ |
| 26309 | | - raw_printf(stderr, |
| 26310 | | - "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession)); |
| 27034 | + eputf("Maximum of %d sessions\n", ArraySize(pAuxDb->aSession)); |
| 26311 | 27035 | goto meta_command_exit; |
| 26312 | 27036 | } |
| 26313 | 27037 | pSession = &pAuxDb->aSession[pAuxDb->nSession]; |
| 26314 | 27038 | rc = sqlite3session_create(p->db, azCmd[1], &pSession->p); |
| 26315 | 27039 | if( rc ){ |
| 26316 | | - raw_printf(stderr, "Cannot open session: error code=%d\n", rc); |
| 27040 | + eputf("Cannot open session: error code=%d\n", rc); |
| 26317 | 27041 | rc = 0; |
| 26318 | 27042 | goto meta_command_exit; |
| 26319 | 27043 | } |
| 26320 | 27044 | pSession->nFilter = 0; |
| 26321 | 27045 | sqlite3session_table_filter(pSession->p, session_filter, pSession); |
| | @@ -26335,20 +27059,20 @@ |
| 26335 | 27059 | if( c=='s' && n>=10 && cli_strncmp(azArg[0], "selftest-", 9)==0 ){ |
| 26336 | 27060 | if( cli_strncmp(azArg[0]+9, "boolean", n-9)==0 ){ |
| 26337 | 27061 | int i, v; |
| 26338 | 27062 | for(i=1; i<nArg; i++){ |
| 26339 | 27063 | v = booleanValue(azArg[i]); |
| 26340 | | - utf8_printf(p->out, "%s: %d 0x%x\n", azArg[i], v, v); |
| 27064 | + oputf("%s: %d 0x%x\n", azArg[i], v, v); |
| 26341 | 27065 | } |
| 26342 | 27066 | } |
| 26343 | 27067 | if( cli_strncmp(azArg[0]+9, "integer", n-9)==0 ){ |
| 26344 | 27068 | int i; sqlite3_int64 v; |
| 26345 | 27069 | for(i=1; i<nArg; i++){ |
| 26346 | 27070 | char zBuf[200]; |
| 26347 | 27071 | v = integerValue(azArg[i]); |
| 26348 | 27072 | sqlite3_snprintf(sizeof(zBuf),zBuf,"%s: %lld 0x%llx\n", azArg[i],v,v); |
| 26349 | | - utf8_printf(p->out, "%s", zBuf); |
| 27073 | + oputz(zBuf); |
| 26350 | 27074 | } |
| 26351 | 27075 | } |
| 26352 | 27076 | }else |
| 26353 | 27077 | #endif |
| 26354 | 27078 | |
| | @@ -26371,13 +27095,12 @@ |
| 26371 | 27095 | }else |
| 26372 | 27096 | if( cli_strcmp(z,"-v")==0 ){ |
| 26373 | 27097 | bVerbose++; |
| 26374 | 27098 | }else |
| 26375 | 27099 | { |
| 26376 | | - utf8_printf(stderr, "Unknown option \"%s\" on \"%s\"\n", |
| 26377 | | - azArg[i], azArg[0]); |
| 26378 | | - raw_printf(stderr, "Should be one of: --init -v\n"); |
| 27100 | + eputf("Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); |
| 27101 | + eputz("Should be one of: --init -v\n"); |
| 26379 | 27102 | rc = 1; |
| 26380 | 27103 | goto meta_command_exit; |
| 26381 | 27104 | } |
| 26382 | 27105 | } |
| 26383 | 27106 | if( sqlite3_table_column_metadata(p->db,"main","selftest",0,0,0,0,0,0) |
| | @@ -26402,11 +27125,11 @@ |
| 26402 | 27125 | "VALUES(0,'memo','Missing SELFTEST table - default checks only','')," |
| 26403 | 27126 | " (1,'run','PRAGMA integrity_check','ok')", |
| 26404 | 27127 | -1, &pStmt, 0); |
| 26405 | 27128 | } |
| 26406 | 27129 | if( rc ){ |
| 26407 | | - raw_printf(stderr, "Error querying the selftest table\n"); |
| 27130 | + eputz("Error querying the selftest table\n"); |
| 26408 | 27131 | rc = 1; |
| 26409 | 27132 | sqlite3_finalize(pStmt); |
| 26410 | 27133 | goto meta_command_exit; |
| 26411 | 27134 | } |
| 26412 | 27135 | for(i=1; sqlite3_step(pStmt)==SQLITE_ROW; i++){ |
| | @@ -26418,52 +27141,51 @@ |
| 26418 | 27141 | if( zOp==0 ) continue; |
| 26419 | 27142 | if( zSql==0 ) continue; |
| 26420 | 27143 | if( zAns==0 ) continue; |
| 26421 | 27144 | k = 0; |
| 26422 | 27145 | if( bVerbose>0 ){ |
| 26423 | | - printf("%d: %s %s\n", tno, zOp, zSql); |
| 27146 | + sputf(stdout, "%d: %s %s\n", tno, zOp, zSql); |
| 26424 | 27147 | } |
| 26425 | 27148 | if( cli_strcmp(zOp,"memo")==0 ){ |
| 26426 | | - utf8_printf(p->out, "%s\n", zSql); |
| 27149 | + oputf("%s\n", zSql); |
| 26427 | 27150 | }else |
| 26428 | 27151 | if( cli_strcmp(zOp,"run")==0 ){ |
| 26429 | 27152 | char *zErrMsg = 0; |
| 26430 | 27153 | str.n = 0; |
| 26431 | 27154 | str.z[0] = 0; |
| 26432 | 27155 | rc = sqlite3_exec(p->db, zSql, captureOutputCallback, &str, &zErrMsg); |
| 26433 | 27156 | nTest++; |
| 26434 | 27157 | if( bVerbose ){ |
| 26435 | | - utf8_printf(p->out, "Result: %s\n", str.z); |
| 27158 | + oputf("Result: %s\n", str.z); |
| 26436 | 27159 | } |
| 26437 | 27160 | if( rc || zErrMsg ){ |
| 26438 | 27161 | nErr++; |
| 26439 | 27162 | rc = 1; |
| 26440 | | - utf8_printf(p->out, "%d: error-code-%d: %s\n", tno, rc, zErrMsg); |
| 27163 | + oputf("%d: error-code-%d: %s\n", tno, rc, zErrMsg); |
| 26441 | 27164 | sqlite3_free(zErrMsg); |
| 26442 | 27165 | }else if( cli_strcmp(zAns,str.z)!=0 ){ |
| 26443 | 27166 | nErr++; |
| 26444 | 27167 | rc = 1; |
| 26445 | | - utf8_printf(p->out, "%d: Expected: [%s]\n", tno, zAns); |
| 26446 | | - utf8_printf(p->out, "%d: Got: [%s]\n", tno, str.z); |
| 27168 | + oputf("%d: Expected: [%s]\n", tno, zAns); |
| 27169 | + oputf("%d: Got: [%s]\n", tno, str.z); |
| 26447 | 27170 | } |
| 26448 | | - }else |
| 26449 | | - { |
| 26450 | | - utf8_printf(stderr, |
| 26451 | | - "Unknown operation \"%s\" on selftest line %d\n", zOp, tno); |
| 27171 | + } |
| 27172 | + else{ |
| 27173 | + eputf("Unknown operation \"%s\" on selftest line %d\n", zOp, tno); |
| 26452 | 27174 | rc = 1; |
| 26453 | 27175 | break; |
| 26454 | 27176 | } |
| 26455 | 27177 | } /* End loop over rows of content from SELFTEST */ |
| 26456 | 27178 | sqlite3_finalize(pStmt); |
| 26457 | 27179 | } /* End loop over k */ |
| 26458 | 27180 | freeText(&str); |
| 26459 | | - utf8_printf(p->out, "%d errors out of %d tests\n", nErr, nTest); |
| 27181 | + oputf("%d errors out of %d tests\n", nErr, nTest); |
| 26460 | 27182 | }else |
| 26461 | 27183 | |
| 26462 | 27184 | if( c=='s' && cli_strncmp(azArg[0], "separator", n)==0 ){ |
| 26463 | 27185 | if( nArg<2 || nArg>3 ){ |
| 26464 | | - raw_printf(stderr, "Usage: .separator COL ?ROW?\n"); |
| 27186 | + eputz("Usage: .separator COL ?ROW?\n"); |
| 26465 | 27187 | rc = 1; |
| 26466 | 27188 | } |
| 26467 | 27189 | if( nArg>=2 ){ |
| 26468 | 27190 | sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, |
| 26469 | 27191 | "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]); |
| | @@ -26502,18 +27224,17 @@ |
| 26502 | 27224 | }else |
| 26503 | 27225 | if( cli_strcmp(z,"debug")==0 ){ |
| 26504 | 27226 | bDebug = 1; |
| 26505 | 27227 | }else |
| 26506 | 27228 | { |
| 26507 | | - utf8_printf(stderr, "Unknown option \"%s\" on \"%s\"\n", |
| 26508 | | - azArg[i], azArg[0]); |
| 27229 | + eputf("Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); |
| 26509 | 27230 | showHelp(p->out, azArg[0]); |
| 26510 | 27231 | rc = 1; |
| 26511 | 27232 | goto meta_command_exit; |
| 26512 | 27233 | } |
| 26513 | 27234 | }else if( zLike ){ |
| 26514 | | - raw_printf(stderr, "Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n"); |
| 27235 | + eputz("Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n"); |
| 26515 | 27236 | rc = 1; |
| 26516 | 27237 | goto meta_command_exit; |
| 26517 | 27238 | }else{ |
| 26518 | 27239 | zLike = z; |
| 26519 | 27240 | bSeparate = 1; |
| | @@ -26581,11 +27302,11 @@ |
| 26581 | 27302 | } |
| 26582 | 27303 | shell_check_oom(zSql); |
| 26583 | 27304 | freeText(&sQuery); |
| 26584 | 27305 | freeText(&sSql); |
| 26585 | 27306 | if( bDebug ){ |
| 26586 | | - utf8_printf(p->out, "%s\n", zSql); |
| 27307 | + oputf("%s\n", zSql); |
| 26587 | 27308 | }else{ |
| 26588 | 27309 | shell_exec(p, zSql, 0); |
| 26589 | 27310 | } |
| 26590 | 27311 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 26591 | 27312 | { |
| | @@ -26611,11 +27332,11 @@ |
| 26611 | 27332 | "||group_concat('CAST(CAST('||cname||' AS BLOB) AS TEXT)<>'||cname\n" |
| 26612 | 27333 | "|| ' AND typeof('||cname||')=''text'' ',\n" |
| 26613 | 27334 | "' OR ') as query, tname from tabcols group by tname)" |
| 26614 | 27335 | , zRevText); |
| 26615 | 27336 | shell_check_oom(zRevText); |
| 26616 | | - if( bDebug ) utf8_printf(p->out, "%s\n", zRevText); |
| 27337 | + if( bDebug ) oputf("%s\n", zRevText); |
| 26617 | 27338 | lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0); |
| 26618 | 27339 | if( lrc!=SQLITE_OK ){ |
| 26619 | 27340 | /* assert(lrc==SQLITE_NOMEM); // might also be SQLITE_ERROR if the |
| 26620 | 27341 | ** user does cruel and unnatural things like ".limit expr_depth 0". */ |
| 26621 | 27342 | rc = 1; |
| | @@ -26624,29 +27345,28 @@ |
| 26624 | 27345 | lrc = SQLITE_ROW==sqlite3_step(pStmt); |
| 26625 | 27346 | if( lrc ){ |
| 26626 | 27347 | const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0); |
| 26627 | 27348 | sqlite3_stmt *pCheckStmt; |
| 26628 | 27349 | lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0); |
| 26629 | | - if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery); |
| 27350 | + if( bDebug ) oputf("%s\n", zGenQuery); |
| 26630 | 27351 | if( lrc!=SQLITE_OK ){ |
| 26631 | 27352 | rc = 1; |
| 26632 | 27353 | }else{ |
| 26633 | 27354 | if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){ |
| 26634 | 27355 | double countIrreversible = sqlite3_column_double(pCheckStmt, 0); |
| 26635 | 27356 | if( countIrreversible>0 ){ |
| 26636 | 27357 | int sz = (int)(countIrreversible + 0.5); |
| 26637 | | - utf8_printf(stderr, |
| 26638 | | - "Digest includes %d invalidly encoded text field%s.\n", |
| 26639 | | - sz, (sz>1)? "s": ""); |
| 27358 | + eputf("Digest includes %d invalidly encoded text field%s.\n", |
| 27359 | + sz, (sz>1)? "s": ""); |
| 26640 | 27360 | } |
| 26641 | 27361 | } |
| 26642 | 27362 | sqlite3_finalize(pCheckStmt); |
| 26643 | 27363 | } |
| 26644 | 27364 | sqlite3_finalize(pStmt); |
| 26645 | 27365 | } |
| 26646 | 27366 | } |
| 26647 | | - if( rc ) utf8_printf(stderr, ".sha3sum failed.\n"); |
| 27367 | + if( rc ) eputz(".sha3sum failed.\n"); |
| 26648 | 27368 | sqlite3_free(zRevText); |
| 26649 | 27369 | } |
| 26650 | 27370 | #endif /* !defined(*_OMIT_SCHEMA_PRAGMAS) && !defined(*_OMIT_VIRTUALTABLE) */ |
| 26651 | 27371 | sqlite3_free(zSql); |
| 26652 | 27372 | }else |
| | @@ -26658,76 +27378,77 @@ |
| 26658 | 27378 | ){ |
| 26659 | 27379 | char *zCmd; |
| 26660 | 27380 | int i, x; |
| 26661 | 27381 | failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]); |
| 26662 | 27382 | if( nArg<2 ){ |
| 26663 | | - raw_printf(stderr, "Usage: .system COMMAND\n"); |
| 27383 | + eputz("Usage: .system COMMAND\n"); |
| 26664 | 27384 | rc = 1; |
| 26665 | 27385 | goto meta_command_exit; |
| 26666 | 27386 | } |
| 26667 | 27387 | zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]); |
| 26668 | 27388 | for(i=2; i<nArg && zCmd!=0; i++){ |
| 26669 | 27389 | zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"", |
| 26670 | 27390 | zCmd, azArg[i]); |
| 26671 | 27391 | } |
| 27392 | + consoleRestore(); |
| 26672 | 27393 | x = zCmd!=0 ? system(zCmd) : 1; |
| 27394 | + consoleRenewSetup(); |
| 26673 | 27395 | sqlite3_free(zCmd); |
| 26674 | | - if( x ) raw_printf(stderr, "System command returns %d\n", x); |
| 27396 | + if( x ) eputf("System command returns %d\n", x); |
| 26675 | 27397 | }else |
| 26676 | 27398 | #endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE) */ |
| 26677 | 27399 | |
| 26678 | 27400 | if( c=='s' && cli_strncmp(azArg[0], "show", n)==0 ){ |
| 26679 | 27401 | static const char *azBool[] = { "off", "on", "trigger", "full"}; |
| 26680 | 27402 | const char *zOut; |
| 26681 | 27403 | int i; |
| 26682 | 27404 | if( nArg!=1 ){ |
| 26683 | | - raw_printf(stderr, "Usage: .show\n"); |
| 27405 | + eputz("Usage: .show\n"); |
| 26684 | 27406 | rc = 1; |
| 26685 | 27407 | goto meta_command_exit; |
| 26686 | 27408 | } |
| 26687 | | - utf8_printf(p->out, "%12.12s: %s\n","echo", |
| 26688 | | - azBool[ShellHasFlag(p, SHFLG_Echo)]); |
| 26689 | | - utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]); |
| 26690 | | - utf8_printf(p->out, "%12.12s: %s\n","explain", |
| 26691 | | - p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off"); |
| 26692 | | - utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]); |
| 27409 | + oputf("%12.12s: %s\n","echo", |
| 27410 | + azBool[ShellHasFlag(p, SHFLG_Echo)]); |
| 27411 | + oputf("%12.12s: %s\n","eqp", azBool[p->autoEQP&3]); |
| 27412 | + oputf("%12.12s: %s\n","explain", |
| 27413 | + p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off"); |
| 27414 | + oputf("%12.12s: %s\n","headers", azBool[p->showHeader!=0]); |
| 26693 | 27415 | if( p->mode==MODE_Column |
| 26694 | 27416 | || (p->mode>=MODE_Markdown && p->mode<=MODE_Box) |
| 26695 | 27417 | ){ |
| 26696 | | - utf8_printf |
| 26697 | | - (p->out, "%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode", |
| 26698 | | - modeDescr[p->mode], p->cmOpts.iWrap, |
| 26699 | | - p->cmOpts.bWordWrap ? "on" : "off", |
| 26700 | | - p->cmOpts.bQuote ? "" : "no"); |
| 27418 | + oputf("%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode", |
| 27419 | + modeDescr[p->mode], p->cmOpts.iWrap, |
| 27420 | + p->cmOpts.bWordWrap ? "on" : "off", |
| 27421 | + p->cmOpts.bQuote ? "" : "no"); |
| 26701 | 27422 | }else{ |
| 26702 | | - utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]); |
| 26703 | | - } |
| 26704 | | - utf8_printf(p->out, "%12.12s: ", "nullvalue"); |
| 26705 | | - output_c_string(p->out, p->nullValue); |
| 26706 | | - raw_printf(p->out, "\n"); |
| 26707 | | - utf8_printf(p->out,"%12.12s: %s\n","output", |
| 26708 | | - strlen30(p->outfile) ? p->outfile : "stdout"); |
| 26709 | | - utf8_printf(p->out,"%12.12s: ", "colseparator"); |
| 26710 | | - output_c_string(p->out, p->colSeparator); |
| 26711 | | - raw_printf(p->out, "\n"); |
| 26712 | | - utf8_printf(p->out,"%12.12s: ", "rowseparator"); |
| 26713 | | - output_c_string(p->out, p->rowSeparator); |
| 26714 | | - raw_printf(p->out, "\n"); |
| 27423 | + oputf("%12.12s: %s\n","mode", modeDescr[p->mode]); |
| 27424 | + } |
| 27425 | + oputf("%12.12s: ", "nullvalue"); |
| 27426 | + output_c_string(p->nullValue); |
| 27427 | + oputz("\n"); |
| 27428 | + oputf("%12.12s: %s\n","output", |
| 27429 | + strlen30(p->outfile) ? p->outfile : "stdout"); |
| 27430 | + oputf("%12.12s: ", "colseparator"); |
| 27431 | + output_c_string(p->colSeparator); |
| 27432 | + oputz("\n"); |
| 27433 | + oputf("%12.12s: ", "rowseparator"); |
| 27434 | + output_c_string(p->rowSeparator); |
| 27435 | + oputz("\n"); |
| 26715 | 27436 | switch( p->statsOn ){ |
| 26716 | 27437 | case 0: zOut = "off"; break; |
| 26717 | 27438 | default: zOut = "on"; break; |
| 26718 | 27439 | case 2: zOut = "stmt"; break; |
| 26719 | 27440 | case 3: zOut = "vmstep"; break; |
| 26720 | 27441 | } |
| 26721 | | - utf8_printf(p->out, "%12.12s: %s\n","stats", zOut); |
| 26722 | | - utf8_printf(p->out, "%12.12s: ", "width"); |
| 27442 | + oputf("%12.12s: %s\n","stats", zOut); |
| 27443 | + oputf("%12.12s: ", "width"); |
| 26723 | 27444 | for (i=0;i<p->nWidth;i++) { |
| 26724 | | - raw_printf(p->out, "%d ", p->colWidth[i]); |
| 27445 | + oputf("%d ", p->colWidth[i]); |
| 26725 | 27446 | } |
| 26726 | | - raw_printf(p->out, "\n"); |
| 26727 | | - utf8_printf(p->out, "%12.12s: %s\n", "filename", |
| 26728 | | - p->pAuxDb->zDbFilename ? p->pAuxDb->zDbFilename : ""); |
| 27447 | + oputz("\n"); |
| 27448 | + oputf("%12.12s: %s\n", "filename", |
| 27449 | + p->pAuxDb->zDbFilename ? p->pAuxDb->zDbFilename : ""); |
| 26729 | 27450 | }else |
| 26730 | 27451 | |
| 26731 | 27452 | if( c=='s' && cli_strncmp(azArg[0], "stats", n)==0 ){ |
| 26732 | 27453 | if( nArg==2 ){ |
| 26733 | 27454 | if( cli_strcmp(azArg[1],"stmt")==0 ){ |
| | @@ -26738,11 +27459,11 @@ |
| 26738 | 27459 | p->statsOn = (u8)booleanValue(azArg[1]); |
| 26739 | 27460 | } |
| 26740 | 27461 | }else if( nArg==1 ){ |
| 26741 | 27462 | display_stats(p->db, p, 0); |
| 26742 | 27463 | }else{ |
| 26743 | | - raw_printf(stderr, "Usage: .stats ?on|off|stmt|vmstep?\n"); |
| 27464 | + eputz("Usage: .stats ?on|off|stmt|vmstep?\n"); |
| 26744 | 27465 | rc = 1; |
| 26745 | 27466 | } |
| 26746 | 27467 | }else |
| 26747 | 27468 | |
| 26748 | 27469 | if( (c=='t' && n>1 && cli_strncmp(azArg[0], "tables", n)==0) |
| | @@ -26764,11 +27485,11 @@ |
| 26764 | 27485 | |
| 26765 | 27486 | if( nArg>2 && c=='i' ){ |
| 26766 | 27487 | /* It is an historical accident that the .indexes command shows an error |
| 26767 | 27488 | ** when called with the wrong number of arguments whereas the .tables |
| 26768 | 27489 | ** command does not. */ |
| 26769 | | - raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n"); |
| 27490 | + eputz("Usage: .indexes ?LIKE-PATTERN?\n"); |
| 26770 | 27491 | rc = 1; |
| 26771 | 27492 | sqlite3_finalize(pStmt); |
| 26772 | 27493 | goto meta_command_exit; |
| 26773 | 27494 | } |
| 26774 | 27495 | for(ii=0; sqlite3_step(pStmt)==SQLITE_ROW; ii++){ |
| | @@ -26840,14 +27561,13 @@ |
| 26840 | 27561 | if( nPrintCol<1 ) nPrintCol = 1; |
| 26841 | 27562 | nPrintRow = (nRow + nPrintCol - 1)/nPrintCol; |
| 26842 | 27563 | for(i=0; i<nPrintRow; i++){ |
| 26843 | 27564 | for(j=i; j<nRow; j+=nPrintRow){ |
| 26844 | 27565 | char *zSp = j<nPrintRow ? "" : " "; |
| 26845 | | - utf8_printf(p->out, "%s%-*s", zSp, maxlen, |
| 26846 | | - azResult[j] ? azResult[j]:""); |
| 27566 | + oputf("%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:""); |
| 26847 | 27567 | } |
| 26848 | | - raw_printf(p->out, "\n"); |
| 27568 | + oputz("\n"); |
| 26849 | 27569 | } |
| 26850 | 27570 | } |
| 26851 | 27571 | |
| 26852 | 27572 | for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]); |
| 26853 | 27573 | sqlite3_free(azResult); |
| | @@ -26857,11 +27577,11 @@ |
| 26857 | 27577 | /* Begin redirecting output to the file "testcase-out.txt" */ |
| 26858 | 27578 | if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){ |
| 26859 | 27579 | output_reset(p); |
| 26860 | 27580 | p->out = output_file_open("testcase-out.txt", 0); |
| 26861 | 27581 | if( p->out==0 ){ |
| 26862 | | - raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n"); |
| 27582 | + eputz("Error: cannot open 'testcase-out.txt'\n"); |
| 26863 | 27583 | } |
| 26864 | 27584 | if( nArg>=2 ){ |
| 26865 | 27585 | sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]); |
| 26866 | 27586 | }else{ |
| 26867 | 27587 | sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?"); |
| | @@ -26898,11 +27618,11 @@ |
| 26898 | 27618 | {"prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" }, |
| 26899 | 27619 | {"prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" }, |
| 26900 | 27620 | {"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" }, |
| 26901 | 27621 | {"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" }, |
| 26902 | 27622 | {"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" }, |
| 26903 | | - {"uselongdouble", SQLITE_TESTCTRL_USELONGDOUBLE,0,"?BOOLEAN|\"default\"?"}, |
| 27623 | + {"uselongdouble", SQLITE_TESTCTRL_USELONGDOUBLE,0,"?BOOLEAN|\"default\"?"}, |
| 26904 | 27624 | }; |
| 26905 | 27625 | int testctrl = -1; |
| 26906 | 27626 | int iCtrl = -1; |
| 26907 | 27627 | int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */ |
| 26908 | 27628 | int isOk = 0; |
| | @@ -26918,15 +27638,15 @@ |
| 26918 | 27638 | if( zCmd[0]=='-' && zCmd[1] ) zCmd++; |
| 26919 | 27639 | } |
| 26920 | 27640 | |
| 26921 | 27641 | /* --help lists all test-controls */ |
| 26922 | 27642 | if( cli_strcmp(zCmd,"help")==0 ){ |
| 26923 | | - utf8_printf(p->out, "Available test-controls:\n"); |
| 27643 | + oputz("Available test-controls:\n"); |
| 26924 | 27644 | for(i=0; i<ArraySize(aCtrl); i++){ |
| 26925 | 27645 | if( aCtrl[i].unSafe && !ShellHasFlag(p,SHFLG_TestingMode) ) continue; |
| 26926 | | - utf8_printf(p->out, " .testctrl %s %s\n", |
| 26927 | | - aCtrl[i].zCtrlName, aCtrl[i].zUsage); |
| 27646 | + oputf(" .testctrl %s %s\n", |
| 27647 | + aCtrl[i].zCtrlName, aCtrl[i].zUsage); |
| 26928 | 27648 | } |
| 26929 | 27649 | rc = 1; |
| 26930 | 27650 | goto meta_command_exit; |
| 26931 | 27651 | } |
| 26932 | 27652 | |
| | @@ -26938,20 +27658,20 @@ |
| 26938 | 27658 | if( cli_strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){ |
| 26939 | 27659 | if( testctrl<0 ){ |
| 26940 | 27660 | testctrl = aCtrl[i].ctrlCode; |
| 26941 | 27661 | iCtrl = i; |
| 26942 | 27662 | }else{ |
| 26943 | | - utf8_printf(stderr, "Error: ambiguous test-control: \"%s\"\n" |
| 26944 | | - "Use \".testctrl --help\" for help\n", zCmd); |
| 27663 | + eputf("Error: ambiguous test-control: \"%s\"\n" |
| 27664 | + "Use \".testctrl --help\" for help\n", zCmd); |
| 26945 | 27665 | rc = 1; |
| 26946 | 27666 | goto meta_command_exit; |
| 26947 | 27667 | } |
| 26948 | 27668 | } |
| 26949 | 27669 | } |
| 26950 | 27670 | if( testctrl<0 ){ |
| 26951 | | - utf8_printf(stderr,"Error: unknown test-control: %s\n" |
| 26952 | | - "Use \".testctrl --help\" for help\n", zCmd); |
| 27671 | + eputf("Error: unknown test-control: %s\n" |
| 27672 | + "Use \".testctrl --help\" for help\n", zCmd); |
| 26953 | 27673 | }else{ |
| 26954 | 27674 | switch(testctrl){ |
| 26955 | 27675 | |
| 26956 | 27676 | /* sqlite3_test_control(int, db, int) */ |
| 26957 | 27677 | case SQLITE_TESTCTRL_OPTIMIZATIONS: |
| | @@ -26987,11 +27707,11 @@ |
| 26987 | 27707 | if( nArg==3 || nArg==4 ){ |
| 26988 | 27708 | int ii = (int)integerValue(azArg[2]); |
| 26989 | 27709 | sqlite3 *db; |
| 26990 | 27710 | if( ii==0 && cli_strcmp(azArg[2],"random")==0 ){ |
| 26991 | 27711 | sqlite3_randomness(sizeof(ii),&ii); |
| 26992 | | - printf("-- random seed: %d\n", ii); |
| 27712 | + sputf(stdout, "-- random seed: %d\n", ii); |
| 26993 | 27713 | } |
| 26994 | 27714 | if( nArg==3 ){ |
| 26995 | 27715 | db = 0; |
| 26996 | 27716 | }else{ |
| 26997 | 27717 | db = p->db; |
| | @@ -27055,11 +27775,11 @@ |
| 27055 | 27775 | break; |
| 27056 | 27776 | |
| 27057 | 27777 | case SQLITE_TESTCTRL_SEEK_COUNT: { |
| 27058 | 27778 | u64 x = 0; |
| 27059 | 27779 | rc2 = sqlite3_test_control(testctrl, p->db, &x); |
| 27060 | | - utf8_printf(p->out, "%llu\n", x); |
| 27780 | + oputf("%llu\n", x); |
| 27061 | 27781 | isOk = 3; |
| 27062 | 27782 | break; |
| 27063 | 27783 | } |
| 27064 | 27784 | |
| 27065 | 27785 | #ifdef YYCOVERAGE |
| | @@ -27086,15 +27806,15 @@ |
| 27086 | 27806 | int id = 1; |
| 27087 | 27807 | while(1){ |
| 27088 | 27808 | int val = 0; |
| 27089 | 27809 | rc2 = sqlite3_test_control(testctrl, -id, &val); |
| 27090 | 27810 | if( rc2!=SQLITE_OK ) break; |
| 27091 | | - if( id>1 ) utf8_printf(p->out, " "); |
| 27092 | | - utf8_printf(p->out, "%d: %d", id, val); |
| 27811 | + if( id>1 ) oputz(" "); |
| 27812 | + oputf("%d: %d", id, val); |
| 27093 | 27813 | id++; |
| 27094 | 27814 | } |
| 27095 | | - if( id>1 ) utf8_printf(p->out, "\n"); |
| 27815 | + if( id>1 ) oputz("\n"); |
| 27096 | 27816 | isOk = 3; |
| 27097 | 27817 | } |
| 27098 | 27818 | break; |
| 27099 | 27819 | } |
| 27100 | 27820 | #endif |
| | @@ -27106,16 +27826,16 @@ |
| 27106 | 27826 | } |
| 27107 | 27827 | break; |
| 27108 | 27828 | } |
| 27109 | 27829 | } |
| 27110 | 27830 | if( isOk==0 && iCtrl>=0 ){ |
| 27111 | | - utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); |
| 27831 | + oputf("Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); |
| 27112 | 27832 | rc = 1; |
| 27113 | 27833 | }else if( isOk==1 ){ |
| 27114 | | - raw_printf(p->out, "%d\n", rc2); |
| 27834 | + oputf("%d\n", rc2); |
| 27115 | 27835 | }else if( isOk==2 ){ |
| 27116 | | - raw_printf(p->out, "0x%08x\n", rc2); |
| 27836 | + oputf("0x%08x\n", rc2); |
| 27117 | 27837 | } |
| 27118 | 27838 | }else |
| 27119 | 27839 | #endif /* !defined(SQLITE_UNTESTABLE) */ |
| 27120 | 27840 | |
| 27121 | 27841 | if( c=='t' && n>4 && cli_strncmp(azArg[0], "timeout", n)==0 ){ |
| | @@ -27125,15 +27845,15 @@ |
| 27125 | 27845 | |
| 27126 | 27846 | if( c=='t' && n>=5 && cli_strncmp(azArg[0], "timer", n)==0 ){ |
| 27127 | 27847 | if( nArg==2 ){ |
| 27128 | 27848 | enableTimer = booleanValue(azArg[1]); |
| 27129 | 27849 | if( enableTimer && !HAS_TIMER ){ |
| 27130 | | - raw_printf(stderr, "Error: timer not available on this system.\n"); |
| 27850 | + eputz("Error: timer not available on this system.\n"); |
| 27131 | 27851 | enableTimer = 0; |
| 27132 | 27852 | } |
| 27133 | 27853 | }else{ |
| 27134 | | - raw_printf(stderr, "Usage: .timer on|off\n"); |
| 27854 | + eputz("Usage: .timer on|off\n"); |
| 27135 | 27855 | rc = 1; |
| 27136 | 27856 | } |
| 27137 | 27857 | }else |
| 27138 | 27858 | |
| 27139 | 27859 | #ifndef SQLITE_OMIT_TRACE |
| | @@ -27166,11 +27886,11 @@ |
| 27166 | 27886 | } |
| 27167 | 27887 | else if( optionMatch(z, "close") ){ |
| 27168 | 27888 | mType |= SQLITE_TRACE_CLOSE; |
| 27169 | 27889 | } |
| 27170 | 27890 | else { |
| 27171 | | - raw_printf(stderr, "Unknown option \"%s\" on \".trace\"\n", z); |
| 27891 | + eputf("Unknown option \"%s\" on \".trace\"\n", z); |
| 27172 | 27892 | rc = 1; |
| 27173 | 27893 | goto meta_command_exit; |
| 27174 | 27894 | } |
| 27175 | 27895 | }else{ |
| 27176 | 27896 | output_file_close(p->traceOut); |
| | @@ -27190,11 +27910,11 @@ |
| 27190 | 27910 | if( c=='u' && cli_strncmp(azArg[0], "unmodule", n)==0 ){ |
| 27191 | 27911 | int ii; |
| 27192 | 27912 | int lenOpt; |
| 27193 | 27913 | char *zOpt; |
| 27194 | 27914 | if( nArg<2 ){ |
| 27195 | | - raw_printf(stderr, "Usage: .unmodule [--allexcept] NAME ...\n"); |
| 27915 | + eputz("Usage: .unmodule [--allexcept] NAME ...\n"); |
| 27196 | 27916 | rc = 1; |
| 27197 | 27917 | goto meta_command_exit; |
| 27198 | 27918 | } |
| 27199 | 27919 | open_db(p, 0); |
| 27200 | 27920 | zOpt = azArg[1]; |
| | @@ -27212,100 +27932,100 @@ |
| 27212 | 27932 | #endif |
| 27213 | 27933 | |
| 27214 | 27934 | #if SQLITE_USER_AUTHENTICATION |
| 27215 | 27935 | if( c=='u' && cli_strncmp(azArg[0], "user", n)==0 ){ |
| 27216 | 27936 | if( nArg<2 ){ |
| 27217 | | - raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n"); |
| 27937 | + eputz("Usage: .user SUBCOMMAND ...\n"); |
| 27218 | 27938 | rc = 1; |
| 27219 | 27939 | goto meta_command_exit; |
| 27220 | 27940 | } |
| 27221 | 27941 | open_db(p, 0); |
| 27222 | 27942 | if( cli_strcmp(azArg[1],"login")==0 ){ |
| 27223 | 27943 | if( nArg!=4 ){ |
| 27224 | | - raw_printf(stderr, "Usage: .user login USER PASSWORD\n"); |
| 27944 | + eputz("Usage: .user login USER PASSWORD\n"); |
| 27225 | 27945 | rc = 1; |
| 27226 | 27946 | goto meta_command_exit; |
| 27227 | 27947 | } |
| 27228 | 27948 | rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3], |
| 27229 | 27949 | strlen30(azArg[3])); |
| 27230 | 27950 | if( rc ){ |
| 27231 | | - utf8_printf(stderr, "Authentication failed for user %s\n", azArg[2]); |
| 27951 | + eputf("Authentication failed for user %s\n", azArg[2]); |
| 27232 | 27952 | rc = 1; |
| 27233 | 27953 | } |
| 27234 | 27954 | }else if( cli_strcmp(azArg[1],"add")==0 ){ |
| 27235 | 27955 | if( nArg!=5 ){ |
| 27236 | | - raw_printf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n"); |
| 27956 | + eputz("Usage: .user add USER PASSWORD ISADMIN\n"); |
| 27237 | 27957 | rc = 1; |
| 27238 | 27958 | goto meta_command_exit; |
| 27239 | 27959 | } |
| 27240 | 27960 | rc = sqlite3_user_add(p->db, azArg[2], azArg[3], strlen30(azArg[3]), |
| 27241 | 27961 | booleanValue(azArg[4])); |
| 27242 | 27962 | if( rc ){ |
| 27243 | | - raw_printf(stderr, "User-Add failed: %d\n", rc); |
| 27963 | + eputf("User-Add failed: %d\n", rc); |
| 27244 | 27964 | rc = 1; |
| 27245 | 27965 | } |
| 27246 | 27966 | }else if( cli_strcmp(azArg[1],"edit")==0 ){ |
| 27247 | 27967 | if( nArg!=5 ){ |
| 27248 | | - raw_printf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n"); |
| 27968 | + eputz("Usage: .user edit USER PASSWORD ISADMIN\n"); |
| 27249 | 27969 | rc = 1; |
| 27250 | 27970 | goto meta_command_exit; |
| 27251 | 27971 | } |
| 27252 | 27972 | rc = sqlite3_user_change(p->db, azArg[2], azArg[3], strlen30(azArg[3]), |
| 27253 | 27973 | booleanValue(azArg[4])); |
| 27254 | 27974 | if( rc ){ |
| 27255 | | - raw_printf(stderr, "User-Edit failed: %d\n", rc); |
| 27975 | + eputf("User-Edit failed: %d\n", rc); |
| 27256 | 27976 | rc = 1; |
| 27257 | 27977 | } |
| 27258 | 27978 | }else if( cli_strcmp(azArg[1],"delete")==0 ){ |
| 27259 | 27979 | if( nArg!=3 ){ |
| 27260 | | - raw_printf(stderr, "Usage: .user delete USER\n"); |
| 27980 | + eputz("Usage: .user delete USER\n"); |
| 27261 | 27981 | rc = 1; |
| 27262 | 27982 | goto meta_command_exit; |
| 27263 | 27983 | } |
| 27264 | 27984 | rc = sqlite3_user_delete(p->db, azArg[2]); |
| 27265 | 27985 | if( rc ){ |
| 27266 | | - raw_printf(stderr, "User-Delete failed: %d\n", rc); |
| 27986 | + eputf("User-Delete failed: %d\n", rc); |
| 27267 | 27987 | rc = 1; |
| 27268 | 27988 | } |
| 27269 | 27989 | }else{ |
| 27270 | | - raw_printf(stderr, "Usage: .user login|add|edit|delete ...\n"); |
| 27990 | + eputz("Usage: .user login|add|edit|delete ...\n"); |
| 27271 | 27991 | rc = 1; |
| 27272 | 27992 | goto meta_command_exit; |
| 27273 | 27993 | } |
| 27274 | 27994 | }else |
| 27275 | 27995 | #endif /* SQLITE_USER_AUTHENTICATION */ |
| 27276 | 27996 | |
| 27277 | 27997 | if( c=='v' && cli_strncmp(azArg[0], "version", n)==0 ){ |
| 27278 | 27998 | char *zPtrSz = sizeof(void*)==8 ? "64-bit" : "32-bit"; |
| 27279 | | - utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/, |
| 27280 | | - sqlite3_libversion(), sqlite3_sourceid()); |
| 27999 | + oputf("SQLite %s %s\n" /*extra-version-info*/, |
| 28000 | + sqlite3_libversion(), sqlite3_sourceid()); |
| 27281 | 28001 | #if SQLITE_HAVE_ZLIB |
| 27282 | | - utf8_printf(p->out, "zlib version %s\n", zlibVersion()); |
| 28002 | + oputf("zlib version %s\n", zlibVersion()); |
| 27283 | 28003 | #endif |
| 27284 | 28004 | #define CTIMEOPT_VAL_(opt) #opt |
| 27285 | 28005 | #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt) |
| 27286 | 28006 | #if defined(__clang__) && defined(__clang_major__) |
| 27287 | | - utf8_printf(p->out, "clang-" CTIMEOPT_VAL(__clang_major__) "." |
| 27288 | | - CTIMEOPT_VAL(__clang_minor__) "." |
| 27289 | | - CTIMEOPT_VAL(__clang_patchlevel__) " (%s)\n", zPtrSz); |
| 28007 | + oputf("clang-" CTIMEOPT_VAL(__clang_major__) "." |
| 28008 | + CTIMEOPT_VAL(__clang_minor__) "." |
| 28009 | + CTIMEOPT_VAL(__clang_patchlevel__) " (%s)\n", zPtrSz); |
| 27290 | 28010 | #elif defined(_MSC_VER) |
| 27291 | | - utf8_printf(p->out, "msvc-" CTIMEOPT_VAL(_MSC_VER) " (%s)\n", zPtrSz); |
| 28011 | + oputf("msvc-" CTIMEOPT_VAL(_MSC_VER) " (%s)\n", zPtrSz); |
| 27292 | 28012 | #elif defined(__GNUC__) && defined(__VERSION__) |
| 27293 | | - utf8_printf(p->out, "gcc-" __VERSION__ " (%s)\n", zPtrSz); |
| 28013 | + oputf("gcc-" __VERSION__ " (%s)\n", zPtrSz); |
| 27294 | 28014 | #endif |
| 27295 | 28015 | }else |
| 27296 | 28016 | |
| 27297 | 28017 | if( c=='v' && cli_strncmp(azArg[0], "vfsinfo", n)==0 ){ |
| 27298 | 28018 | const char *zDbName = nArg==2 ? azArg[1] : "main"; |
| 27299 | 28019 | sqlite3_vfs *pVfs = 0; |
| 27300 | 28020 | if( p->db ){ |
| 27301 | 28021 | sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs); |
| 27302 | 28022 | if( pVfs ){ |
| 27303 | | - utf8_printf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName); |
| 27304 | | - raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion); |
| 27305 | | - raw_printf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile); |
| 27306 | | - raw_printf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname); |
| 28023 | + oputf("vfs.zName = \"%s\"\n", pVfs->zName); |
| 28024 | + oputf("vfs.iVersion = %d\n", pVfs->iVersion); |
| 28025 | + oputf("vfs.szOsFile = %d\n", pVfs->szOsFile); |
| 28026 | + oputf("vfs.mxPathname = %d\n", pVfs->mxPathname); |
| 27307 | 28027 | } |
| 27308 | 28028 | } |
| 27309 | 28029 | }else |
| 27310 | 28030 | |
| 27311 | 28031 | if( c=='v' && cli_strncmp(azArg[0], "vfslist", n)==0 ){ |
| | @@ -27313,17 +28033,17 @@ |
| 27313 | 28033 | sqlite3_vfs *pCurrent = 0; |
| 27314 | 28034 | if( p->db ){ |
| 27315 | 28035 | sqlite3_file_control(p->db, "main", SQLITE_FCNTL_VFS_POINTER, &pCurrent); |
| 27316 | 28036 | } |
| 27317 | 28037 | for(pVfs=sqlite3_vfs_find(0); pVfs; pVfs=pVfs->pNext){ |
| 27318 | | - utf8_printf(p->out, "vfs.zName = \"%s\"%s\n", pVfs->zName, |
| 27319 | | - pVfs==pCurrent ? " <--- CURRENT" : ""); |
| 27320 | | - raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion); |
| 27321 | | - raw_printf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile); |
| 27322 | | - raw_printf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname); |
| 28038 | + oputf("vfs.zName = \"%s\"%s\n", pVfs->zName, |
| 28039 | + pVfs==pCurrent ? " <--- CURRENT" : ""); |
| 28040 | + oputf("vfs.iVersion = %d\n", pVfs->iVersion); |
| 28041 | + oputf("vfs.szOsFile = %d\n", pVfs->szOsFile); |
| 28042 | + oputf("vfs.mxPathname = %d\n", pVfs->mxPathname); |
| 27323 | 28043 | if( pVfs->pNext ){ |
| 27324 | | - raw_printf(p->out, "-----------------------------------\n"); |
| 28044 | + oputz("-----------------------------------\n"); |
| 27325 | 28045 | } |
| 27326 | 28046 | } |
| 27327 | 28047 | }else |
| 27328 | 28048 | |
| 27329 | 28049 | if( c=='v' && cli_strncmp(azArg[0], "vfsname", n)==0 ){ |
| | @@ -27330,11 +28050,11 @@ |
| 27330 | 28050 | const char *zDbName = nArg==2 ? azArg[1] : "main"; |
| 27331 | 28051 | char *zVfsName = 0; |
| 27332 | 28052 | if( p->db ){ |
| 27333 | 28053 | sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName); |
| 27334 | 28054 | if( zVfsName ){ |
| 27335 | | - utf8_printf(p->out, "%s\n", zVfsName); |
| 28055 | + oputf("%s\n", zVfsName); |
| 27336 | 28056 | sqlite3_free(zVfsName); |
| 27337 | 28057 | } |
| 27338 | 28058 | } |
| 27339 | 28059 | }else |
| 27340 | 28060 | |
| | @@ -27354,12 +28074,12 @@ |
| 27354 | 28074 | p->colWidth[j-1] = (int)integerValue(azArg[j]); |
| 27355 | 28075 | } |
| 27356 | 28076 | }else |
| 27357 | 28077 | |
| 27358 | 28078 | { |
| 27359 | | - utf8_printf(stderr, "Error: unknown command or invalid arguments: " |
| 27360 | | - " \"%s\". Enter \".help\" for help\n", azArg[0]); |
| 28079 | + eputf("Error: unknown command or invalid arguments: " |
| 28080 | + " \"%s\". Enter \".help\" for help\n", azArg[0]); |
| 27361 | 28081 | rc = 1; |
| 27362 | 28082 | } |
| 27363 | 28083 | |
| 27364 | 28084 | meta_command_exit: |
| 27365 | 28085 | if( p->outCount ){ |
| | @@ -27545,26 +28265,26 @@ |
| 27545 | 28265 | sqlite3_snprintf(sizeof(zPrefix), zPrefix, |
| 27546 | 28266 | "%s near line %d:", zErrorType, startline); |
| 27547 | 28267 | }else{ |
| 27548 | 28268 | sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType); |
| 27549 | 28269 | } |
| 27550 | | - utf8_printf(stderr, "%s %s\n", zPrefix, zErrorTail); |
| 28270 | + eputf("%s %s\n", zPrefix, zErrorTail); |
| 27551 | 28271 | sqlite3_free(zErrMsg); |
| 27552 | 28272 | zErrMsg = 0; |
| 27553 | 28273 | return 1; |
| 27554 | 28274 | }else if( ShellHasFlag(p, SHFLG_CountChanges) ){ |
| 27555 | 28275 | char zLineBuf[2000]; |
| 27556 | 28276 | sqlite3_snprintf(sizeof(zLineBuf), zLineBuf, |
| 27557 | 28277 | "changes: %lld total_changes: %lld", |
| 27558 | 28278 | sqlite3_changes64(p->db), sqlite3_total_changes64(p->db)); |
| 27559 | | - raw_printf(p->out, "%s\n", zLineBuf); |
| 28279 | + oputf("%s\n", zLineBuf); |
| 27560 | 28280 | } |
| 27561 | 28281 | return 0; |
| 27562 | 28282 | } |
| 27563 | 28283 | |
| 27564 | 28284 | static void echo_group_input(ShellState *p, const char *zDo){ |
| 27565 | | - if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo); |
| 28285 | + if( ShellHasFlag(p, SHFLG_Echo) ) oputf("%s\n", zDo); |
| 27566 | 28286 | } |
| 27567 | 28287 | |
| 27568 | 28288 | #ifdef SQLITE_SHELL_FIDDLE |
| 27569 | 28289 | /* |
| 27570 | 28290 | ** Alternate one_input_line() impl for wasm mode. This is not in the primary |
| | @@ -27618,12 +28338,12 @@ |
| 27618 | 28338 | i64 startline = 0; /* Line number for start of current input */ |
| 27619 | 28339 | QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */ |
| 27620 | 28340 | |
| 27621 | 28341 | if( p->inputNesting==MAX_INPUT_NESTING ){ |
| 27622 | 28342 | /* This will be more informative in a later version. */ |
| 27623 | | - utf8_printf(stderr,"Input nesting limit (%d) reached at line %d." |
| 27624 | | - " Check recursion.\n", MAX_INPUT_NESTING, p->lineno); |
| 28343 | + eputf("Input nesting limit (%d) reached at line %d." |
| 28344 | + " Check recursion.\n", MAX_INPUT_NESTING, p->lineno); |
| 27625 | 28345 | return 1; |
| 27626 | 28346 | } |
| 27627 | 28347 | ++p->inputNesting; |
| 27628 | 28348 | p->lineno = 0; |
| 27629 | 28349 | CONTINUE_PROMPT_RESET; |
| | @@ -27630,11 +28350,11 @@ |
| 27630 | 28350 | while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){ |
| 27631 | 28351 | fflush(p->out); |
| 27632 | 28352 | zLine = one_input_line(p->in, zLine, nSql>0); |
| 27633 | 28353 | if( zLine==0 ){ |
| 27634 | 28354 | /* End of input */ |
| 27635 | | - if( p->in==0 && stdin_is_interactive ) printf("\n"); |
| 28355 | + if( p->in==0 && stdin_is_interactive ) oputz("\n"); |
| 27636 | 28356 | break; |
| 27637 | 28357 | } |
| 27638 | 28358 | if( seenInterrupt ){ |
| 27639 | 28359 | if( p->in!=0 ) break; |
| 27640 | 28360 | seenInterrupt = 0; |
| | @@ -27840,27 +28560,27 @@ |
| 27840 | 28560 | sqliterc = find_xdg_config(); |
| 27841 | 28561 | } |
| 27842 | 28562 | if( sqliterc == NULL ){ |
| 27843 | 28563 | home_dir = find_home_dir(0); |
| 27844 | 28564 | if( home_dir==0 ){ |
| 27845 | | - raw_printf(stderr, "-- warning: cannot find home directory;" |
| 27846 | | - " cannot read ~/.sqliterc\n"); |
| 28565 | + eputz("-- warning: cannot find home directory;" |
| 28566 | + " cannot read ~/.sqliterc\n"); |
| 27847 | 28567 | return; |
| 27848 | 28568 | } |
| 27849 | 28569 | zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir); |
| 27850 | 28570 | shell_check_oom(zBuf); |
| 27851 | 28571 | sqliterc = zBuf; |
| 27852 | 28572 | } |
| 27853 | 28573 | p->in = fopen(sqliterc,"rb"); |
| 27854 | 28574 | if( p->in ){ |
| 27855 | 28575 | if( stdin_is_interactive ){ |
| 27856 | | - utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc); |
| 28576 | + eputf("-- Loading resources from %s\n", sqliterc); |
| 27857 | 28577 | } |
| 27858 | 28578 | if( process_input(p) && bail_on_error ) exit(1); |
| 27859 | 28579 | fclose(p->in); |
| 27860 | 28580 | }else if( sqliterc_override!=0 ){ |
| 27861 | | - utf8_printf(stderr,"cannot open: \"%s\"\n", sqliterc); |
| 28581 | + eputf("cannot open: \"%s\"\n", sqliterc); |
| 27862 | 28582 | if( bail_on_error ) exit(1); |
| 27863 | 28583 | } |
| 27864 | 28584 | p->in = inSaved; |
| 27865 | 28585 | p->lineno = savedLineno; |
| 27866 | 28586 | sqlite3_free(zBuf); |
| | @@ -27906,13 +28626,10 @@ |
| 27906 | 28626 | " -mmap N default mmap size set to N\n" |
| 27907 | 28627 | #ifdef SQLITE_ENABLE_MULTIPLEX |
| 27908 | 28628 | " -multiplex enable the multiplexor VFS\n" |
| 27909 | 28629 | #endif |
| 27910 | 28630 | " -newline SEP set output row separator. Default: '\\n'\n" |
| 27911 | | -#if SHELL_WIN_UTF8_OPT |
| 27912 | | - " -no-utf8 do not try to set up UTF-8 output (for legacy)\n" |
| 27913 | | -#endif |
| 27914 | 28631 | " -nofollow refuse to open symbolic links to database files\n" |
| 27915 | 28632 | " -nonce STRING set the safe-mode escape nonce\n" |
| 27916 | 28633 | " -nullvalue TEXT set text string for NULL values. Default ''\n" |
| 27917 | 28634 | " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n" |
| 27918 | 28635 | " -pcachetrace trace all page cache operations\n" |
| | @@ -27925,13 +28642,10 @@ |
| 27925 | 28642 | #endif |
| 27926 | 28643 | " -stats print memory stats before each finalize\n" |
| 27927 | 28644 | " -table set output mode to 'table'\n" |
| 27928 | 28645 | " -tabs set output mode to 'tabs'\n" |
| 27929 | 28646 | " -unsafe-testing allow unsafe commands and modes for testing\n" |
| 27930 | | -#if SHELL_WIN_UTF8_OPT && 0 /* Option is accepted, but is now the default. */ |
| 27931 | | - " -utf8 setup interactive console code page for UTF-8\n" |
| 27932 | | -#endif |
| 27933 | 28647 | " -version show SQLite version\n" |
| 27934 | 28648 | " -vfs NAME use NAME as the default VFS\n" |
| 27935 | 28649 | #ifdef SQLITE_ENABLE_VFSTRACE |
| 27936 | 28650 | " -vfstrace enable tracing of all VFS calls\n" |
| 27937 | 28651 | #endif |
| | @@ -27938,18 +28652,17 @@ |
| 27938 | 28652 | #ifdef SQLITE_HAVE_ZLIB |
| 27939 | 28653 | " -zip open the file as a ZIP Archive\n" |
| 27940 | 28654 | #endif |
| 27941 | 28655 | ; |
| 27942 | 28656 | static void usage(int showDetail){ |
| 27943 | | - utf8_printf(stderr, |
| 27944 | | - "Usage: %s [OPTIONS] [FILENAME [SQL]]\n" |
| 27945 | | - "FILENAME is the name of an SQLite database. A new database is created\n" |
| 27946 | | - "if the file does not previously exist. Defaults to :memory:.\n", Argv0); |
| 28657 | + eputf("Usage: %s [OPTIONS] [FILENAME [SQL]]\n" |
| 28658 | + "FILENAME is the name of an SQLite database. A new database is created\n" |
| 28659 | + "if the file does not previously exist. Defaults to :memory:.\n", Argv0); |
| 27947 | 28660 | if( showDetail ){ |
| 27948 | | - utf8_printf(stderr, "OPTIONS include:\n%s", zOptions); |
| 28661 | + eputf("OPTIONS include:\n%s", zOptions); |
| 27949 | 28662 | }else{ |
| 27950 | | - raw_printf(stderr, "Use the -help option for additional information\n"); |
| 28663 | + eputz("Use the -help option for additional information\n"); |
| 27951 | 28664 | } |
| 27952 | 28665 | exit(1); |
| 27953 | 28666 | } |
| 27954 | 28667 | |
| 27955 | 28668 | /* |
| | @@ -27956,12 +28669,12 @@ |
| 27956 | 28669 | ** Internal check: Verify that the SQLite is uninitialized. Print a |
| 27957 | 28670 | ** error message if it is initialized. |
| 27958 | 28671 | */ |
| 27959 | 28672 | static void verify_uninitialized(void){ |
| 27960 | 28673 | if( sqlite3_config(-1)==SQLITE_MISUSE ){ |
| 27961 | | - utf8_printf(stdout, "WARNING: attempt to configure SQLite after" |
| 27962 | | - " initialization.\n"); |
| 28674 | + sputz(stdout, "WARNING: attempt to configure SQLite after" |
| 28675 | + " initialization.\n"); |
| 27963 | 28676 | } |
| 27964 | 28677 | } |
| 27965 | 28678 | |
| 27966 | 28679 | /* |
| 27967 | 28680 | ** Initialize the state information in data |
| | @@ -27986,46 +28699,45 @@ |
| 27986 | 28699 | } |
| 27987 | 28700 | |
| 27988 | 28701 | /* |
| 27989 | 28702 | ** Output text to the console in a font that attracts extra attention. |
| 27990 | 28703 | */ |
| 27991 | | -#ifdef _WIN32 |
| 28704 | +#if defined(_WIN32) || defined(WIN32) |
| 27992 | 28705 | static void printBold(const char *zText){ |
| 27993 | 28706 | #if !SQLITE_OS_WINRT |
| 27994 | 28707 | HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); |
| 27995 | 28708 | CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo; |
| 27996 | 28709 | GetConsoleScreenBufferInfo(out, &defaultScreenInfo); |
| 27997 | 28710 | SetConsoleTextAttribute(out, |
| 27998 | 28711 | FOREGROUND_RED|FOREGROUND_INTENSITY |
| 27999 | 28712 | ); |
| 28000 | 28713 | #endif |
| 28001 | | - printf("%s", zText); |
| 28714 | + oputz(zText); |
| 28002 | 28715 | #if !SQLITE_OS_WINRT |
| 28003 | 28716 | SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes); |
| 28004 | 28717 | #endif |
| 28005 | 28718 | } |
| 28006 | 28719 | #else |
| 28007 | 28720 | static void printBold(const char *zText){ |
| 28008 | | - printf("\033[1m%s\033[0m", zText); |
| 28721 | + oputf("\033[1m%s\033[0m", zText); |
| 28009 | 28722 | } |
| 28010 | 28723 | #endif |
| 28011 | 28724 | |
| 28012 | 28725 | /* |
| 28013 | 28726 | ** Get the argument to an --option. Throw an error and die if no argument |
| 28014 | 28727 | ** is available. |
| 28015 | 28728 | */ |
| 28016 | 28729 | static char *cmdline_option_value(int argc, char **argv, int i){ |
| 28017 | 28730 | if( i==argc ){ |
| 28018 | | - utf8_printf(stderr, "%s: Error: missing argument to %s\n", |
| 28019 | | - argv[0], argv[argc-1]); |
| 28731 | + eputf("%s: Error: missing argument to %s\n", argv[0], argv[argc-1]); |
| 28020 | 28732 | exit(1); |
| 28021 | 28733 | } |
| 28022 | 28734 | return argv[i]; |
| 28023 | 28735 | } |
| 28024 | 28736 | |
| 28025 | 28737 | static void sayAbnormalExit(void){ |
| 28026 | | - if( seenInterrupt ) fprintf(stderr, "Program interrupted.\n"); |
| 28738 | + if( seenInterrupt ) eputz("Program interrupted.\n"); |
| 28027 | 28739 | } |
| 28028 | 28740 | |
| 28029 | 28741 | #ifndef SQLITE_SHELL_IS_UTF8 |
| 28030 | 28742 | # if (defined(_WIN32) || defined(WIN32)) \ |
| 28031 | 28743 | && (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__))) |
| | @@ -28051,10 +28763,11 @@ |
| 28051 | 28763 | char *zErrMsg = 0; |
| 28052 | 28764 | #ifdef SQLITE_SHELL_FIDDLE |
| 28053 | 28765 | # define data shellState |
| 28054 | 28766 | #else |
| 28055 | 28767 | ShellState data; |
| 28768 | + StreamsAreConsole consStreams = SAC_NoConsole; |
| 28056 | 28769 | #endif |
| 28057 | 28770 | const char *zInitFile = 0; |
| 28058 | 28771 | int i; |
| 28059 | 28772 | int rc = 0; |
| 28060 | 28773 | int warnInmemoryDb = 0; |
| | @@ -28072,27 +28785,24 @@ |
| 28072 | 28785 | #ifdef SQLITE_SHELL_FIDDLE |
| 28073 | 28786 | stdin_is_interactive = 0; |
| 28074 | 28787 | stdout_is_console = 1; |
| 28075 | 28788 | data.wasm.zDefaultDbName = "/fiddle.sqlite3"; |
| 28076 | 28789 | #else |
| 28077 | | - stdin_is_interactive = isatty(0); |
| 28078 | | - stdout_is_console = isatty(1); |
| 28079 | | -#endif |
| 28080 | | -#if SHELL_WIN_UTF8_OPT |
| 28081 | | - probe_console(); /* Check for console I/O and UTF-8 capability. */ |
| 28082 | | - if( !mbcs_opted ) atexit(console_restore); |
| 28790 | + consStreams = consoleClassifySetup(stdin, stdout, stderr); |
| 28791 | + stdin_is_interactive = (consStreams & SAC_InConsole)!=0; |
| 28792 | + stdout_is_console = (consStreams & SAC_OutConsole)!=0; |
| 28793 | + atexit(consoleRestore); |
| 28083 | 28794 | #endif |
| 28084 | 28795 | atexit(sayAbnormalExit); |
| 28085 | 28796 | #ifdef SQLITE_DEBUG |
| 28086 | 28797 | mem_main_enter = sqlite3_memory_used(); |
| 28087 | 28798 | #endif |
| 28088 | 28799 | #if !defined(_WIN32_WCE) |
| 28089 | 28800 | if( getenv("SQLITE_DEBUG_BREAK") ){ |
| 28090 | 28801 | if( isatty(0) && isatty(2) ){ |
| 28091 | | - fprintf(stderr, |
| 28092 | | - "attach debugger to process %d and press any key to continue.\n", |
| 28093 | | - GETPID()); |
| 28802 | + eputf("attach debugger to process %d and press any key to continue.\n", |
| 28803 | + GETPID()); |
| 28094 | 28804 | fgetc(stdin); |
| 28095 | 28805 | }else{ |
| 28096 | 28806 | #if defined(_WIN32) || defined(WIN32) |
| 28097 | 28807 | #if SQLITE_OS_WINRT |
| 28098 | 28808 | __debugbreak(); |
| | @@ -28108,18 +28818,18 @@ |
| 28108 | 28818 | /* Register a valid signal handler early, before much else is done. */ |
| 28109 | 28819 | #ifdef SIGINT |
| 28110 | 28820 | signal(SIGINT, interrupt_handler); |
| 28111 | 28821 | #elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE) |
| 28112 | 28822 | if( !SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE) ){ |
| 28113 | | - fprintf(stderr, "No ^C handler.\n"); |
| 28823 | + eputz("No ^C handler.\n"); |
| 28114 | 28824 | } |
| 28115 | 28825 | #endif |
| 28116 | 28826 | |
| 28117 | 28827 | #if USE_SYSTEM_SQLITE+0!=1 |
| 28118 | 28828 | if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){ |
| 28119 | | - utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n", |
| 28120 | | - sqlite3_sourceid(), SQLITE_SOURCE_ID); |
| 28829 | + eputf("SQLite header and source version mismatch\n%s\n%s\n", |
| 28830 | + sqlite3_sourceid(), SQLITE_SOURCE_ID); |
| 28121 | 28831 | exit(1); |
| 28122 | 28832 | } |
| 28123 | 28833 | #endif |
| 28124 | 28834 | main_init(&data); |
| 28125 | 28835 | |
| | @@ -28211,18 +28921,11 @@ |
| 28211 | 28921 | ** informational messages (like from process_sqliterc) before |
| 28212 | 28922 | ** we do the actual processing of arguments later in a second pass. |
| 28213 | 28923 | */ |
| 28214 | 28924 | stdin_is_interactive = 0; |
| 28215 | 28925 | }else if( cli_strcmp(z,"-utf8")==0 ){ |
| 28216 | | -#if SHELL_WIN_UTF8_OPT |
| 28217 | | - /* Option accepted, but is ignored except for this diagnostic. */ |
| 28218 | | - if( mbcs_opted ) fprintf(stderr, "Cannot do UTF-8 at this console.\n"); |
| 28219 | | -#endif /* SHELL_WIN_UTF8_OPT */ |
| 28220 | 28926 | }else if( cli_strcmp(z,"-no-utf8")==0 ){ |
| 28221 | | -#if SHELL_WIN_UTF8_OPT |
| 28222 | | - mbcs_opted = 1; |
| 28223 | | -#endif /* SHELL_WIN_UTF8_OPT */ |
| 28224 | 28927 | }else if( cli_strcmp(z,"-heap")==0 ){ |
| 28225 | 28928 | #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) |
| 28226 | 28929 | const char *zSize; |
| 28227 | 28930 | sqlite3_int64 szHeap; |
| 28228 | 28931 | |
| | @@ -28353,30 +29056,21 @@ |
| 28353 | 29056 | if( zVfs ){ |
| 28354 | 29057 | sqlite3_vfs *pVfs = sqlite3_vfs_find(zVfs); |
| 28355 | 29058 | if( pVfs ){ |
| 28356 | 29059 | sqlite3_vfs_register(pVfs, 1); |
| 28357 | 29060 | }else{ |
| 28358 | | - utf8_printf(stderr, "no such VFS: \"%s\"\n", zVfs); |
| 29061 | + eputf("no such VFS: \"%s\"\n", zVfs); |
| 28359 | 29062 | exit(1); |
| 28360 | 29063 | } |
| 28361 | 29064 | } |
| 28362 | | -#if SHELL_WIN_UTF8_OPT |
| 28363 | | - /* Get indicated Windows console setup done before running invocation commands. */ |
| 28364 | | - if( in_console || out_console ){ |
| 28365 | | - console_prepare_utf8(); |
| 28366 | | - } |
| 28367 | | - if( !in_console ){ |
| 28368 | | - setBinaryMode(stdin, 0); |
| 28369 | | - } |
| 28370 | | -#endif |
| 28371 | 29065 | |
| 28372 | 29066 | if( data.pAuxDb->zDbFilename==0 ){ |
| 28373 | 29067 | #ifndef SQLITE_OMIT_MEMORYDB |
| 28374 | 29068 | data.pAuxDb->zDbFilename = ":memory:"; |
| 28375 | 29069 | warnInmemoryDb = argc==1; |
| 28376 | 29070 | #else |
| 28377 | | - utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0); |
| 29071 | + eputf("%s: Error: no database filename specified\n", Argv0); |
| 28378 | 29072 | return 1; |
| 28379 | 29073 | #endif |
| 28380 | 29074 | } |
| 28381 | 29075 | data.out = stdout; |
| 28382 | 29076 | #ifndef SQLITE_SHELL_FIDDLE |
| | @@ -28489,12 +29183,12 @@ |
| 28489 | 29183 | */ |
| 28490 | 29184 | ShellSetFlag(&data, SHFLG_Backslash); |
| 28491 | 29185 | }else if( cli_strcmp(z,"-bail")==0 ){ |
| 28492 | 29186 | /* No-op. The bail_on_error flag should already be set. */ |
| 28493 | 29187 | }else if( cli_strcmp(z,"-version")==0 ){ |
| 28494 | | - printf("%s %s (%d-bit)\n", sqlite3_libversion(), sqlite3_sourceid(), |
| 28495 | | - 8*(int)sizeof(char*)); |
| 29188 | + oputf("%s %s (%d-bit)\n", sqlite3_libversion(), sqlite3_sourceid(), |
| 29189 | + 8*(int)sizeof(char*)); |
| 28496 | 29190 | return 0; |
| 28497 | 29191 | }else if( cli_strcmp(z,"-interactive")==0 ){ |
| 28498 | 29192 | /* already handled */ |
| 28499 | 29193 | }else if( cli_strcmp(z,"-batch")==0 ){ |
| 28500 | 29194 | /* already handled */ |
| | @@ -28546,22 +29240,22 @@ |
| 28546 | 29240 | if( rc && bail_on_error ) return rc==2 ? 0 : rc; |
| 28547 | 29241 | }else{ |
| 28548 | 29242 | open_db(&data, 0); |
| 28549 | 29243 | rc = shell_exec(&data, z, &zErrMsg); |
| 28550 | 29244 | if( zErrMsg!=0 ){ |
| 28551 | | - utf8_printf(stderr,"Error: %s\n", zErrMsg); |
| 29245 | + eputf("Error: %s\n", zErrMsg); |
| 28552 | 29246 | if( bail_on_error ) return rc!=0 ? rc : 1; |
| 28553 | 29247 | }else if( rc!=0 ){ |
| 28554 | | - utf8_printf(stderr,"Error: unable to process SQL \"%s\"\n", z); |
| 29248 | + eputf("Error: unable to process SQL \"%s\"\n", z); |
| 28555 | 29249 | if( bail_on_error ) return rc; |
| 28556 | 29250 | } |
| 28557 | 29251 | } |
| 28558 | 29252 | #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) |
| 28559 | 29253 | }else if( cli_strncmp(z, "-A", 2)==0 ){ |
| 28560 | 29254 | if( nCmd>0 ){ |
| 28561 | | - utf8_printf(stderr, "Error: cannot mix regular SQL or dot-commands" |
| 28562 | | - " with \"%s\"\n", z); |
| 29255 | + eputf("Error: cannot mix regular SQL or dot-commands" |
| 29256 | + " with \"%s\"\n", z); |
| 28563 | 29257 | return 1; |
| 28564 | 29258 | } |
| 28565 | 29259 | open_db(&data, OPEN_DB_ZIPFILE); |
| 28566 | 29260 | if( z[2] ){ |
| 28567 | 29261 | argv[i] = &z[2]; |
| | @@ -28575,12 +29269,12 @@ |
| 28575 | 29269 | }else if( cli_strcmp(z,"-safe")==0 ){ |
| 28576 | 29270 | data.bSafeMode = data.bSafeModePersist = 1; |
| 28577 | 29271 | }else if( cli_strcmp(z,"-unsafe-testing")==0 ){ |
| 28578 | 29272 | /* Acted upon in first pass. */ |
| 28579 | 29273 | }else{ |
| 28580 | | - utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z); |
| 28581 | | - raw_printf(stderr,"Use -help for a list of options.\n"); |
| 29274 | + eputf("%s: Error: unknown option: %s\n", Argv0, z); |
| 29275 | + eputz("Use -help for a list of options.\n"); |
| 28582 | 29276 | return 1; |
| 28583 | 29277 | } |
| 28584 | 29278 | data.cMode = data.mode; |
| 28585 | 29279 | } |
| 28586 | 29280 | |
| | @@ -28600,13 +29294,13 @@ |
| 28600 | 29294 | open_db(&data, 0); |
| 28601 | 29295 | echo_group_input(&data, azCmd[i]); |
| 28602 | 29296 | rc = shell_exec(&data, azCmd[i], &zErrMsg); |
| 28603 | 29297 | if( zErrMsg || rc ){ |
| 28604 | 29298 | if( zErrMsg!=0 ){ |
| 28605 | | - utf8_printf(stderr,"Error: %s\n", zErrMsg); |
| 29299 | + eputf("Error: %s\n", zErrMsg); |
| 28606 | 29300 | }else{ |
| 28607 | | - utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]); |
| 29301 | + eputf("Error: unable to process SQL: %s\n", azCmd[i]); |
| 28608 | 29302 | } |
| 28609 | 29303 | sqlite3_free(zErrMsg); |
| 28610 | 29304 | free(azCmd); |
| 28611 | 29305 | return rc!=0 ? rc : 1; |
| 28612 | 29306 | } |
| | @@ -28616,30 +29310,24 @@ |
| 28616 | 29310 | /* Run commands received from standard input |
| 28617 | 29311 | */ |
| 28618 | 29312 | if( stdin_is_interactive ){ |
| 28619 | 29313 | char *zHome; |
| 28620 | 29314 | char *zHistory; |
| 28621 | | - const char *zCharset = ""; |
| 28622 | 29315 | int nHistory; |
| 28623 | | -#if SHELL_WIN_UTF8_OPT |
| 28624 | | - switch( console_utf8_in+2*console_utf8_out ){ |
| 28625 | | - default: case 0: break; |
| 28626 | | - case 1: zCharset = " (utf8 in)"; break; |
| 28627 | | - case 2: zCharset = " (utf8 out)"; break; |
| 28628 | | - case 3: zCharset = " (utf8 I/O)"; break; |
| 28629 | | - } |
| 29316 | +#if CIO_WIN_WC_XLATE |
| 29317 | +# define SHELL_CIO_CHAR_SET (stdout_is_console? " (UTF-16 console I/O)" : "") |
| 29318 | +#else |
| 29319 | +# define SHELL_CIO_CHAR_SET "" |
| 28630 | 29320 | #endif |
| 28631 | | - printf( |
| 28632 | | - "SQLite version %s %.19s%s\n" /*extra-version-info*/ |
| 28633 | | - "Enter \".help\" for usage hints.\n", |
| 28634 | | - sqlite3_libversion(), sqlite3_sourceid(), zCharset |
| 28635 | | - ); |
| 29321 | + oputf("SQLite version %s %.19s%s\n" /*extra-version-info*/ |
| 29322 | + "Enter \".help\" for usage hints.\n", |
| 29323 | + sqlite3_libversion(), sqlite3_sourceid(), SHELL_CIO_CHAR_SET); |
| 28636 | 29324 | if( warnInmemoryDb ){ |
| 28637 | | - printf("Connected to a "); |
| 29325 | + oputz("Connected to a "); |
| 28638 | 29326 | printBold("transient in-memory database"); |
| 28639 | | - printf(".\nUse \".open FILENAME\" to reopen on a " |
| 28640 | | - "persistent database.\n"); |
| 29327 | + oputz(".\nUse \".open FILENAME\" to reopen on a" |
| 29328 | + " persistent database.\n"); |
| 28641 | 29329 | } |
| 28642 | 29330 | zHistory = getenv("SQLITE_HISTORY"); |
| 28643 | 29331 | if( zHistory ){ |
| 28644 | 29332 | zHistory = strdup(zHistory); |
| 28645 | 29333 | }else if( (zHome = find_home_dir(0))!=0 ){ |
| | @@ -28695,12 +29383,12 @@ |
| 28695 | 29383 | /* Clear the global data structure so that valgrind will detect memory |
| 28696 | 29384 | ** leaks */ |
| 28697 | 29385 | memset(&data, 0, sizeof(data)); |
| 28698 | 29386 | #ifdef SQLITE_DEBUG |
| 28699 | 29387 | if( sqlite3_memory_used()>mem_main_enter ){ |
| 28700 | | - utf8_printf(stderr, "Memory leaked: %u bytes\n", |
| 28701 | | - (unsigned int)(sqlite3_memory_used()-mem_main_enter)); |
| 29388 | + eputf("Memory leaked: %u bytes\n", |
| 29389 | + (unsigned int)(sqlite3_memory_used()-mem_main_enter)); |
| 28702 | 29390 | } |
| 28703 | 29391 | #endif |
| 28704 | 29392 | #endif /* !SQLITE_SHELL_FIDDLE */ |
| 28705 | 29393 | return rc; |
| 28706 | 29394 | } |
| 28707 | 29395 | |