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

Function deduceDatabaseType

modules/dasSQLITE/sqlite/shell.c:20120–20153  ·  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

20118** the type cannot be determined from content.
20119*/
20120int deduceDatabaseType(const char *zName, int dfltZip){
20121 FILE *f = fopen(zName, "rb");
20122 size_t n;
20123 int rc = SHELL_OPEN_UNSPEC;
20124 char zBuf[100];
20125 if( f==0 ){
20126 if( dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
20127 return SHELL_OPEN_ZIPFILE;
20128 }else{
20129 return SHELL_OPEN_NORMAL;
20130 }
20131 }
20132 n = fread(zBuf, 16, 1, f);
20133 if( n==1 && memcmp(zBuf, "SQLite format 3", 16)==0 ){
20134 fclose(f);
20135 return SHELL_OPEN_NORMAL;
20136 }
20137 fseek(f, -25, SEEK_END);
20138 n = fread(zBuf, 25, 1, f);
20139 if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){
20140 rc = SHELL_OPEN_APPENDVFS;
20141 }else{
20142 fseek(f, -22, SEEK_END);
20143 n = fread(zBuf, 22, 1, f);
20144 if( n==1 && zBuf[0]==0x50 && zBuf[1]==0x4b && zBuf[2]==0x05
20145 && zBuf[3]==0x06 ){
20146 rc = SHELL_OPEN_ZIPFILE;
20147 }else if( n==0 && dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
20148 rc = SHELL_OPEN_ZIPFILE;
20149 }
20150 }
20151 fclose(f);
20152 return rc;
20153}
20154
20155#ifndef SQLITE_OMIT_DESERIALIZE
20156/*

Callers 2

open_dbFunction · 0.85
arDotCommandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected