/ Check-in [24e88773]
Login

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

Overview
Comment:Allow the database name in a DETACH statement to be quoted. Ticket #1151. (CVS 2386)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:24e887735256499e58dabe90463524d9e6eb08ce
User & Date: drh 2005-03-15 02:04:12
Context
2005-03-15
17:09
When creating a new database, delete any preexisting journal that might be left over from a prior database with the same name. Ticket #1152. (CVS 2387) check-in: 856e2ec9 user: drh tags: trunk
02:04
Allow the database name in a DETACH statement to be quoted. Ticket #1151. (CVS 2386) check-in: 24e88773 user: drh tags: trunk
2005-03-14
02:01
Be more aggressive about using the busy handler. Ticket #1159. (CVS 2385) check-in: 644c6398 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/attach.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the ATTACH and DETACH commands.
    13     13   **
    14         -** $Id: attach.c,v 1.31 2005/01/24 10:25:59 danielk1977 Exp $
           14  +** $Id: attach.c,v 1.32 2005/03/15 02:04:12 drh Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /*
    19     19   ** This routine is called by the parser to process an ATTACH statement:
    20     20   **
    21     21   **     ATTACH DATABASE filename AS dbname
................................................................................
   154    154   ** The pDbname argument is the name of the database in the DETACH statement.
   155    155   */
   156    156   void sqlite3Detach(Parse *pParse, Token *pDbname){
   157    157     int i;
   158    158     sqlite3 *db;
   159    159     Vdbe *v;
   160    160     Db *pDb = 0;
          161  +  char *zName;
   161    162   
   162    163     v = sqlite3GetVdbe(pParse);
   163    164     if( !v ) return;
   164    165     sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
   165    166     sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   166    167     if( pParse->explain ) return;
   167    168     db = pParse->db;
          169  +  zName = sqlite3NameFromToken(pDbname);
          170  +  if( zName==0 ) return;
   168    171     for(i=0; i<db->nDb; i++){
   169    172       pDb = &db->aDb[i];
   170         -    if( pDb->pBt==0 || pDb->zName==0 ) continue;
   171         -    if( strlen(pDb->zName)!=pDbname->n ) continue;
   172         -    if( sqlite3StrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
          173  +    if( pDb->pBt==0 ) continue;
          174  +    if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
   173    175     }
   174    176     if( i>=db->nDb ){
   175         -    sqlite3ErrorMsg(pParse, "no such database: %T", pDbname);
          177  +    sqlite3ErrorMsg(pParse, "no such database: %z", zName);
   176    178       return;
   177    179     }
   178    180     if( i<2 ){
   179         -    sqlite3ErrorMsg(pParse, "cannot detach database %T", pDbname);
          181  +    sqlite3ErrorMsg(pParse, "cannot detach database %z", zName);
   180    182       return;
   181    183     }
          184  +  sqliteFree(zName);
   182    185     if( !db->autoCommit ){
   183    186       sqlite3ErrorMsg(pParse, "cannot DETACH database within transaction");
   184    187       pParse->rc = SQLITE_ERROR;
   185    188       return;
   186    189     }
   187    190   #ifndef SQLITE_OMIT_AUTHORIZATION
   188    191     if( sqlite3AuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){

Changes to test/attach.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ATTACH and DETACH commands
    13     13   # and related functionality.
    14     14   #
    15         -# $Id: attach.test,v 1.38 2005/03/02 05:18:57 drh Exp $
           15  +# $Id: attach.test,v 1.39 2005/03/15 02:04:13 drh Exp $
    16     16   #
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   for {set i 2} {$i<=15} {incr i} {
    22     22     file delete -force test$i.db
................................................................................
    76     76   do_test attach-1.9 {
    77     77     catchsql {
    78     78       SELECT * FROM three.sqlite_master;
    79     79     }
    80     80   } {0 {}}
    81     81   do_test attach-1.10 {
    82     82     catchsql {
    83         -    DETACH DATABASE three;
           83  +    DETACH DATABASE [three];
    84     84     }
    85     85   } {0 {}}
    86     86   do_test attach-1.11 {
    87     87     execsql {
    88     88       ATTACH 'test.db' AS db2;
    89     89       ATTACH 'test.db' AS db3;
    90     90       ATTACH 'test.db' AS db4;
................................................................................
   168    168   do_test attach-1.22 {
   169    169     catchsql {
   170    170       ATTACH 'test.db' as db13;
   171    171     }
   172    172   } {1 {too many attached databases - max 10}}
   173    173   do_test attach-1.23 {
   174    174     catchsql {
   175         -    DETACH db14;
          175  +    DETACH "db14";
   176    176     }
   177    177   } {1 {no such database: db14}}
   178    178   do_test attach-1.24 {
   179    179     catchsql {
   180    180       DETACH db12;
   181    181     }
   182    182   } {0 {}}