SQLite

Check-in [7a716229]
Login

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

Overview
Comment:Fix another problem with ".expert" and virtual tables. Forum post 49d6a19ec.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7a7162293c8fdb0078fe56948d697703539dd23273b2072990d4391c761e6ae2
User & Date: dan 2024-10-20 07:19:38
Context
2024-10-21
10:47
Avoid using LIKE in sqlite3expert.c, in case "PRAGMA case_sensitive_like" has been used or the "like" UDF replaced by something unexpected. (check-in: 9f642b3d user: dan tags: trunk)
2024-10-20
07:19
Fix another problem with ".expert" and virtual tables. Forum post 49d6a19ec. (check-in: 7a716229 user: dan tags: trunk)
2024-10-19
22:45
Add sqlite3_rsync to the docs at the top of mktoolzip.tcl. No code changes. (check-in: 10f5c4a2 user: stephan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/expert/expert1.test.

575
576
577
578
579
580
581

























582
583
584
  }
  
  do_test 7.5 {
    set expert [sqlite3_expert_new db]
    list [catch { $expert sql "SELECT * FROM ft, t2 WHERE b=1" } msg] $msg
  } {1 {no such table: t2}}
  $expert destroy

























}

finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
  }
  
  do_test 7.5 {
    set expert [sqlite3_expert_new db]
    list [catch { $expert sql "SELECT * FROM ft, t2 WHERE b=1" } msg] $msg
  } {1 {no such table: t2}}
  $expert destroy

  reset_db
  do_execsql_test 7.6 {
    BEGIN TRANSACTION;
      CREATE TABLE IF NOT EXISTS 'bfts_idx_data'(id INTEGER PRIMARY KEY, block BLOB);
      CREATE TABLE IF NOT EXISTS 'fts_idx_data'(id INTEGER PRIMARY KEY, block BLOB);
      INSERT INTO fts_idx_data VALUES(1,X'');
      INSERT INTO fts_idx_data VALUES(10,X'00000000ff000001000000');
      CREATE TABLE IF NOT EXISTS 'fts_idx_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID;
      CREATE TABLE IF NOT EXISTS 'fts_idx_docsize'(id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER);
      CREATE TABLE IF NOT EXISTS 'fts_idx_config'(k PRIMARY KEY, v) WITHOUT ROWID;
      INSERT INTO fts_idx_config VALUES('version',4);
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)VALUES('table','fts_idx','fts_idx',0,'CREATE VIRTUAL TABLE fts_idx USING fts5(Title, Description, Channel, Tags, content='''', contentless_delete=1)');
      
      CREATE TABLE f(x BLOB, y);
    COMMIT;
    PRAGMA writable_schema = RESET;
  }

  do_candidates_test 7.4 {
    SELECT * FROM fts_idx, f WHERE x = fts_idx.Channel
  } {
    CREATE INDEX f_idx_00000078 ON f(x);
  }
}

finish_test

Changes to ext/expert/sqlite3expert.c.

1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473

  /* For each table in the main db schema:
  **
  **   1) Add an entry to the p->pTable list, and
  **   2) Create the equivalent virtual table in dbv.
  */
  rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
      "SELECT type, name, sql, 1, sql LIKE 'create virtual%' "
      "FROM sqlite_schema "
      "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' "
      " UNION ALL "
      "SELECT type, name, sql, 2, 0 FROM sqlite_schema "
      "WHERE type = 'trigger'"
      "  AND tbl_name IN(SELECT name FROM sqlite_schema WHERE type = 'view') "
      "ORDER BY 4, 5 DESC, 1"







|







1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473

  /* For each table in the main db schema:
  **
  **   1) Add an entry to the p->pTable list, and
  **   2) Create the equivalent virtual table in dbv.
  */
  rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
      "SELECT type, name, sql, 1, sql LIKE 'create virtual%%' "
      "FROM sqlite_schema "
      "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' "
      " UNION ALL "
      "SELECT type, name, sql, 2, 0 FROM sqlite_schema "
      "WHERE type = 'trigger'"
      "  AND tbl_name IN(SELECT name FROM sqlite_schema WHERE type = 'view') "
      "ORDER BY 4, 5 DESC, 1"
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
  }
#endif

  /* Copy the entire schema of database [db] into [dbm]. */
  if( rc==SQLITE_OK ){
    sqlite3_stmt *pSql = 0;
    rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg, 
        "SELECT sql, name "
        " FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
        " ORDER BY rowid"
    );
    while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
      const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
      const char *zName = (const char*)sqlite3_column_text(pSql, 1);
      int bExists = 0;
      rc = expertDbContainsObject(pNew->dbm, zName, &bExists);
      if( rc==SQLITE_OK && zSql && bExists==0 ){







|

|







2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
  }
#endif

  /* Copy the entire schema of database [db] into [dbm]. */
  if( rc==SQLITE_OK ){
    sqlite3_stmt *pSql = 0;
    rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg, 
        "SELECT sql, name, sql LIKE 'create virtual%%' AS virt "
        " FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
        " ORDER BY virt DESC, rowid"
    );
    while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
      const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
      const char *zName = (const char*)sqlite3_column_text(pSql, 1);
      int bExists = 0;
      rc = expertDbContainsObject(pNew->dbm, zName, &bExists);
      if( rc==SQLITE_OK && zSql && bExists==0 ){