** Make sure the database is open. If it is not, then open it. If ** the database fails to open, print an error message and exit. */
| 4231 | ** the database fails to open, print an error message and exit. |
| 4232 | */ |
| 4233 | static void open_db(ShellState *p, int keepAlive){ |
| 4234 | if( p->db==0 ){ |
| 4235 | sqlite3_initialize(); |
| 4236 | sqlite3_open(p->zDbFilename, &p->db); |
| 4237 | globalDb = p->db; |
| 4238 | if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ |
| 4239 | utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n", |
| 4240 | p->zDbFilename, sqlite3_errmsg(p->db)); |
| 4241 | if( keepAlive ) return; |
| 4242 | exit(1); |
| 4243 | } |
| 4244 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 4245 | sqlite3_enable_load_extension(p->db, 1); |
| 4246 | #endif |
| 4247 | sqlite3_fileio_init(p->db, 0, 0); |
| 4248 | sqlite3_shathree_init(p->db, 0, 0); |
| 4249 | sqlite3_completion_init(p->db, 0, 0); |
| 4250 | sqlite3_create_function(p->db, "shell_add_schema", 2, SQLITE_UTF8, 0, |
| 4251 | shellAddSchemaName, 0, 0); |
| 4252 | } |
| 4253 | } |
| 4254 | |
| 4255 | #if HAVE_READLINE || HAVE_EDITLINE |
| 4256 | /* |
no test coverage detected