/ Check-in [0857c48e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the -file option on the sqlite3_expert program.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | schemalint
Files: files | file ages | folders
SHA3-256: 0857c48e02a76490fc623364f77363165dea94ec254f93d8f0fd0bac2968c572
User & Date: dan 2017-04-09 08:38:37
Context
2017-04-10
16:13
Changes to allow the code in sqlite3expert.c to be tested directly (via the API in sqlite3expert.h) instead of by invoking the sqlite3_expert application. Fix memory leaks and other problems. check-in: 5dd98317 user: dan tags: schemalint
2017-04-09
08:38
Fix the -file option on the sqlite3_expert program. check-in: 0857c48e user: dan tags: schemalint
2017-04-08
19:00
Merge latest trunk with this branch. check-in: e051e8f2 user: dan tags: schemalint
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/expert/expert.c.

    36     36     fprintf(stderr, "  -sql SQL   (analyze SQL statements passed as argument)\n");
    37     37     fprintf(stderr, "  -file FILE (read SQL statements from file FILE)\n");
    38     38     fprintf(stderr, "  -verbose LEVEL (integer verbosity level. default 1)\n");
    39     39     exit(-1);
    40     40   }
    41     41   
    42     42   static int readSqlFromFile(sqlite3expert *p, const char *zFile, char **pzErr){
    43         -  return SQLITE_OK;
           43  +  FILE *in = fopen(zFile, "rb");
           44  +  long nIn;
           45  +  size_t nRead;
           46  +  char *pBuf;
           47  +  int rc;
           48  +  if( in==0 ){
           49  +    *pzErr = sqlite3_mprintf("failed to open file %s\n", zFile);
           50  +    return SQLITE_ERROR;
           51  +  }
           52  +  fseek(in, 0, SEEK_END);
           53  +  nIn = ftell(in);
           54  +  rewind(in);
           55  +  pBuf = sqlite3_malloc64( nIn+1 );
           56  +  nRead = fread(pBuf, nIn, 1, in);
           57  +  fclose(in);
           58  +  if( nRead!=1 ){
           59  +    sqlite3_free(pBuf);
           60  +    *pzErr = sqlite3_mprintf("failed to read file %s\n", zFile);
           61  +    return SQLITE_ERROR;
           62  +  }
           63  +  pBuf[nIn] = 0;
           64  +  rc = sqlite3_expert_sql(p, pBuf, pzErr);
           65  +  sqlite3_free(pBuf);
           66  +  return rc;
    44     67   }
    45     68   
    46     69   int main(int argc, char **argv){
    47     70     const char *zDb;
    48     71     int rc = 0;
    49     72     char *zErr = 0;
    50     73     int i;