** Implementation of ".ar" dot command. */
| 22559 | ** Implementation of ".ar" dot command. |
| 22560 | */ |
| 22561 | static int arDotCommand( |
| 22562 | ShellState *pState, /* Current shell tool state */ |
| 22563 | int fromCmdLine, /* True if -A command-line option, not .ar cmd */ |
| 22564 | char **azArg, /* Array of arguments passed to dot command */ |
| 22565 | int nArg /* Number of entries in azArg[] */ |
| 22566 | ){ |
| 22567 | ArCommand cmd; |
| 22568 | int rc; |
| 22569 | memset(&cmd, 0, sizeof(cmd)); |
| 22570 | cmd.fromCmdLine = fromCmdLine; |
| 22571 | rc = arParseCommand(azArg, nArg, &cmd); |
| 22572 | if( rc==SQLITE_OK ){ |
| 22573 | int eDbType = SHELL_OPEN_UNSPEC; |
| 22574 | cmd.p = pState; |
| 22575 | cmd.db = pState->db; |
| 22576 | if( cmd.zFile ){ |
| 22577 | eDbType = deduceDatabaseType(cmd.zFile, 1); |
| 22578 | }else{ |
| 22579 | eDbType = pState->openMode; |
| 22580 | } |
| 22581 | if( eDbType==SHELL_OPEN_ZIPFILE ){ |
| 22582 | if( cmd.eCmd==AR_CMD_EXTRACT || cmd.eCmd==AR_CMD_LIST ){ |
| 22583 | if( cmd.zFile==0 ){ |
| 22584 | cmd.zSrcTable = sqlite3_mprintf("zip"); |
| 22585 | }else{ |
| 22586 | cmd.zSrcTable = sqlite3_mprintf("zipfile(%Q)", cmd.zFile); |
| 22587 | } |
| 22588 | } |
| 22589 | cmd.bZip = 1; |
| 22590 | }else if( cmd.zFile ){ |
| 22591 | int flags; |
| 22592 | if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS; |
| 22593 | if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT |
| 22594 | || cmd.eCmd==AR_CMD_REMOVE || cmd.eCmd==AR_CMD_UPDATE ){ |
| 22595 | flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; |
| 22596 | }else{ |
| 22597 | flags = SQLITE_OPEN_READONLY; |
| 22598 | } |
| 22599 | cmd.db = 0; |
| 22600 | if( cmd.bDryRun ){ |
| 22601 | utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile, |
| 22602 | eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : ""); |
| 22603 | } |
| 22604 | rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags, |
| 22605 | eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0); |
| 22606 | if( rc!=SQLITE_OK ){ |
| 22607 | utf8_printf(stderr, "cannot open file: %s (%s)\n", |
| 22608 | cmd.zFile, sqlite3_errmsg(cmd.db) |
| 22609 | ); |
| 22610 | goto end_ar_command; |
| 22611 | } |
| 22612 | sqlite3_fileio_init(cmd.db, 0, 0); |
| 22613 | sqlite3_sqlar_init(cmd.db, 0, 0); |
| 22614 | sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p, |
| 22615 | shellPutsFunc, 0, 0); |
| 22616 | |
| 22617 | } |
| 22618 | if( cmd.zSrcTable==0 && cmd.bZip==0 && cmd.eCmd!=AR_CMD_HELP ){ |
no test coverage detected