MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / open_db

Function open_db

modules/dasSQLITE/sqlite/shell.c:20413–20571  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

20411** the database fails to open, print an error message and exit.
20412*/
20413static void open_db(ShellState *p, int openFlags){
20414 if( p->db==0 ){
20415 const char *zDbFilename = p->pAuxDb->zDbFilename;
20416 if( p->openMode==SHELL_OPEN_UNSPEC ){
20417 if( zDbFilename==0 || zDbFilename[0]==0 ){
20418 p->openMode = SHELL_OPEN_NORMAL;
20419 }else{
20420 p->openMode = (u8)deduceDatabaseType(zDbFilename,
20421 (openFlags & OPEN_DB_ZIPFILE)!=0);
20422 }
20423 }
20424 switch( p->openMode ){
20425 case SHELL_OPEN_APPENDVFS: {
20426 sqlite3_open_v2(zDbFilename, &p->db,
20427 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
20428 break;
20429 }
20430 case SHELL_OPEN_HEXDB:
20431 case SHELL_OPEN_DESERIALIZE: {
20432 sqlite3_open(0, &p->db);
20433 break;
20434 }
20435 case SHELL_OPEN_ZIPFILE: {
20436 sqlite3_open(":memory:", &p->db);
20437 break;
20438 }
20439 case SHELL_OPEN_READONLY: {
20440 sqlite3_open_v2(zDbFilename, &p->db,
20441 SQLITE_OPEN_READONLY|p->openFlags, 0);
20442 break;
20443 }
20444 case SHELL_OPEN_UNSPEC:
20445 case SHELL_OPEN_NORMAL: {
20446 sqlite3_open_v2(zDbFilename, &p->db,
20447 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
20448 break;
20449 }
20450 }
20451 globalDb = p->db;
20452 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
20453 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
20454 zDbFilename, sqlite3_errmsg(p->db));
20455 if( openFlags & OPEN_DB_KEEPALIVE ){
20456 sqlite3_open(":memory:", &p->db);
20457 return;
20458 }
20459 exit(1);
20460 }
20461
20462#ifndef SQLITE_OMIT_LOAD_EXTENSION
20463 sqlite3_enable_load_extension(p->db, 1);
20464#endif
20465 sqlite3_shathree_init(p->db, 0, 0);
20466 sqlite3_uint_init(p->db, 0, 0);
20467 sqlite3_decimal_init(p->db, 0, 0);
20468 sqlite3_base64_init(p->db, 0, 0);
20469 sqlite3_base85_init(p->db, 0, 0);
20470 sqlite3_regexp_init(p->db, 0, 0);

Callers 4

shell_dbinfo_commandFunction · 0.85
do_meta_commandFunction · 0.85
runOneSqlLineFunction · 0.85
wmainFunction · 0.85

Calls 15

deduceDatabaseTypeFunction · 0.85
utf8_printfFunction · 0.85
sqlite3_shathree_initFunction · 0.85
sqlite3_uint_initFunction · 0.85
sqlite3_decimal_initFunction · 0.85
sqlite3_base64_initFunction · 0.85
sqlite3_base85_initFunction · 0.85
sqlite3_regexp_initFunction · 0.85
sqlite3_ieee_initFunction · 0.85
sqlite3_series_initFunction · 0.85
sqlite3_fileio_initFunction · 0.85
sqlite3_completion_initFunction · 0.85

Tested by

no test coverage detected