MCPcopy Create free account
hub / github.com/audacity/audacity / open_db

Function open_db

lib-src/sqlite/shell.c:14719–14835  ·  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

14717** the database fails to open, print an error message and exit.
14718*/
14719static void open_db(ShellState *p, int openFlags){
14720 if( p->db==0 ){
14721 if( p->openMode==SHELL_OPEN_UNSPEC ){
14722 if( p->zDbFilename==0 || p->zDbFilename[0]==0 ){
14723 p->openMode = SHELL_OPEN_NORMAL;
14724 }else{
14725 p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
14726 (openFlags & OPEN_DB_ZIPFILE)!=0);
14727 }
14728 }
14729 switch( p->openMode ){
14730 case SHELL_OPEN_APPENDVFS: {
14731 sqlite3_open_v2(p->zDbFilename, &p->db,
14732 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
14733 break;
14734 }
14735 case SHELL_OPEN_HEXDB:
14736 case SHELL_OPEN_DESERIALIZE: {
14737 sqlite3_open(0, &p->db);
14738 break;
14739 }
14740 case SHELL_OPEN_ZIPFILE: {
14741 sqlite3_open(":memory:", &p->db);
14742 break;
14743 }
14744 case SHELL_OPEN_READONLY: {
14745 sqlite3_open_v2(p->zDbFilename, &p->db,
14746 SQLITE_OPEN_READONLY|p->openFlags, 0);
14747 break;
14748 }
14749 case SHELL_OPEN_UNSPEC:
14750 case SHELL_OPEN_NORMAL: {
14751 sqlite3_open_v2(p->zDbFilename, &p->db,
14752 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
14753 break;
14754 }
14755 }
14756 globalDb = p->db;
14757 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
14758 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
14759 p->zDbFilename, sqlite3_errmsg(p->db));
14760 if( openFlags & OPEN_DB_KEEPALIVE ){
14761 sqlite3_open(":memory:", &p->db);
14762 return;
14763 }
14764 exit(1);
14765 }
14766#ifndef SQLITE_OMIT_LOAD_EXTENSION
14767 sqlite3_enable_load_extension(p->db, 1);
14768#endif
14769 sqlite3_fileio_init(p->db, 0, 0);
14770 sqlite3_shathree_init(p->db, 0, 0);
14771 sqlite3_completion_init(p->db, 0, 0);
14772 sqlite3_uint_init(p->db, 0, 0);
14773 sqlite3_decimal_init(p->db, 0, 0);
14774 sqlite3_ieee_init(p->db, 0, 0);
14775 sqlite3_series_init(p->db, 0, 0);
14776#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)

Callers 4

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

Calls 12

deduceDatabaseTypeFunction · 0.85
utf8_printfFunction · 0.85
sqlite3_fileio_initFunction · 0.85
sqlite3_shathree_initFunction · 0.85
sqlite3_completion_initFunction · 0.85
sqlite3_uint_initFunction · 0.85
sqlite3_decimal_initFunction · 0.85
sqlite3_ieee_initFunction · 0.85
sqlite3_series_initFunction · 0.85
sqlite3_dbdata_initFunction · 0.85
sqlite3_zipfile_initFunction · 0.85
sqlite3_sqlar_initFunction · 0.85

Tested by

no test coverage detected