** Implementation of ".ar" dot command. */
| 16752 | ** Implementation of ".ar" dot command. |
| 16753 | */ |
| 16754 | static int arDotCommand( |
| 16755 | ShellState *pState, /* Current shell tool state */ |
| 16756 | int fromCmdLine, /* True if -A command-line option, not .ar cmd */ |
| 16757 | char **azArg, /* Array of arguments passed to dot command */ |
| 16758 | int nArg /* Number of entries in azArg[] */ |
| 16759 | ){ |
| 16760 | ArCommand cmd; |
| 16761 | int rc; |
| 16762 | memset(&cmd, 0, sizeof(cmd)); |
| 16763 | cmd.fromCmdLine = fromCmdLine; |
| 16764 | rc = arParseCommand(azArg, nArg, &cmd); |
| 16765 | if( rc==SQLITE_OK ){ |
| 16766 | int eDbType = SHELL_OPEN_UNSPEC; |
| 16767 | cmd.p = pState; |
| 16768 | cmd.db = pState->db; |
| 16769 | if( cmd.zFile ){ |
| 16770 | eDbType = deduceDatabaseType(cmd.zFile, 1); |
| 16771 | }else{ |
| 16772 | eDbType = pState->openMode; |
| 16773 | } |
| 16774 | if( eDbType==SHELL_OPEN_ZIPFILE ){ |
| 16775 | if( cmd.eCmd==AR_CMD_EXTRACT || cmd.eCmd==AR_CMD_LIST ){ |
| 16776 | if( cmd.zFile==0 ){ |
| 16777 | cmd.zSrcTable = sqlite3_mprintf("zip"); |
| 16778 | }else{ |
| 16779 | cmd.zSrcTable = sqlite3_mprintf("zipfile(%Q)", cmd.zFile); |
| 16780 | } |
| 16781 | } |
| 16782 | cmd.bZip = 1; |
| 16783 | }else if( cmd.zFile ){ |
| 16784 | int flags; |
| 16785 | if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS; |
| 16786 | if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT |
| 16787 | || cmd.eCmd==AR_CMD_UPDATE ){ |
| 16788 | flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; |
| 16789 | }else{ |
| 16790 | flags = SQLITE_OPEN_READONLY; |
| 16791 | } |
| 16792 | cmd.db = 0; |
| 16793 | if( cmd.bDryRun ){ |
| 16794 | utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile, |
| 16795 | eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : ""); |
| 16796 | } |
| 16797 | rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags, |
| 16798 | eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0); |
| 16799 | if( rc!=SQLITE_OK ){ |
| 16800 | utf8_printf(stderr, "cannot open file: %s (%s)\n", |
| 16801 | cmd.zFile, sqlite3_errmsg(cmd.db) |
| 16802 | ); |
| 16803 | goto end_ar_command; |
| 16804 | } |
| 16805 | sqlite3_fileio_init(cmd.db, 0, 0); |
| 16806 | sqlite3_sqlar_init(cmd.db, 0, 0); |
| 16807 | sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p, |
| 16808 | shellPutsFunc, 0, 0); |
| 16809 | |
| 16810 | } |
| 16811 | if( cmd.zSrcTable==0 && cmd.bZip==0 && cmd.eCmd!=AR_CMD_HELP ){ |
no test coverage detected