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

Function deduceDatabaseType

lib-src/sqlite/shell.c:14424–14457  ·  view source on GitHub ↗

** Try to deduce the type of file for zName based on its content. Return ** one of the SHELL_OPEN_* constants. ** ** If the file does not exist or is empty but its name looks like a ZIP ** archive and the dfltZip flag is true, then assume it is a ZIP archive. ** Otherwise, assume an ordinary database regardless of the filename if ** the type cannot be determined from content. */

Source from the content-addressed store, hash-verified

14422** the type cannot be determined from content.
14423*/
14424int deduceDatabaseType(const char *zName, int dfltZip){
14425 FILE *f = fopen(zName, "rb");
14426 size_t n;
14427 int rc = SHELL_OPEN_UNSPEC;
14428 char zBuf[100];
14429 if( f==0 ){
14430 if( dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
14431 return SHELL_OPEN_ZIPFILE;
14432 }else{
14433 return SHELL_OPEN_NORMAL;
14434 }
14435 }
14436 n = fread(zBuf, 16, 1, f);
14437 if( n==1 && memcmp(zBuf, "SQLite format 3", 16)==0 ){
14438 fclose(f);
14439 return SHELL_OPEN_NORMAL;
14440 }
14441 fseek(f, -25, SEEK_END);
14442 n = fread(zBuf, 25, 1, f);
14443 if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){
14444 rc = SHELL_OPEN_APPENDVFS;
14445 }else{
14446 fseek(f, -22, SEEK_END);
14447 n = fread(zBuf, 22, 1, f);
14448 if( n==1 && zBuf[0]==0x50 && zBuf[1]==0x4b && zBuf[2]==0x05
14449 && zBuf[3]==0x06 ){
14450 rc = SHELL_OPEN_ZIPFILE;
14451 }else if( n==0 && dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
14452 rc = SHELL_OPEN_ZIPFILE;
14453 }
14454 }
14455 fclose(f);
14456 return rc;
14457}
14458
14459#ifdef SQLITE_ENABLE_DESERIALIZE
14460/*

Callers 2

open_dbFunction · 0.85
arDotCommandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected