/ Check-in [262a3e63]
Login

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

Overview
Comment:Relax the restriction on using bytes 0x80 through 0xbf as the first character of an identifier. Enhancements to ALTER TABLE tests for tables with strange names or stange column names. (CVS 4008)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 262a3e6339b31f269f8f07e43d295b90827e2779
User & Date: drh 2007-05-15 14:34:32
Context
2007-05-15
14:40
Remove the alternative UTF-16 implementation of SUBSTR(). It does not work anymore and the UTF-8 version can do everything that the UTF-16 version does. (CVS 4009) check-in: 9b91502e user: drh tags: trunk
14:34
Relax the restriction on using bytes 0x80 through 0xbf as the first character of an identifier. Enhancements to ALTER TABLE tests for tables with strange names or stange column names. (CVS 4008) check-in: 262a3e63 user: drh tags: trunk
14:17
Change the documentation to clearly state that the result of sqlite3_column_type() is undefined following a type conversion. (CVS 4007) check-in: 960be575 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/alter.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
** $Id: alter.c,v 1.24 2007/05/15 03:56:49 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** The code in this file only exists if we are not omitting the
** ALTER TABLE logic from the build.
................................................................................
  Token *pName              /* The new table name. */
){
  int iDb;                  /* Database that contains the table */
  char *zDb;                /* Name of database iDb */
  Table *pTab;              /* Table being renamed */
  char *zName = 0;          /* NULL-terminated version of pName */ 
  sqlite3 *db = pParse->db; /* Database connection */
  int i;                    /* Loop counter */
  int nTabName;             /* Number of UTF-8 characters in zTabName */
  const char *zTabName;     /* Original name of the table */
  Vdbe *v;
#ifndef SQLITE_OMIT_TRIGGER
  char *zWhere = 0;         /* Where clause to locate temp triggers */
#endif
  
................................................................................
    goto exit_rename_table;
  }
  sqlite3BeginWriteOperation(pParse, 0, iDb);
  sqlite3ChangeCookie(db, v, iDb);

  /* figure out how many UTF-8 characters are in zName */
  zTabName = pTab->zName;
  for(i=nTabName=0; zTabName[i]; i++){
    if( (zTabName[i]&0xc0)!=0x80 ) nTabName++;
  }

  /* Modify the sqlite_master table to use the new table name. */
  sqlite3NestedParse(pParse,
      "UPDATE %Q.%s SET "
#ifdef SQLITE_OMIT_TRIGGER
          "sql = sqlite_rename_table(sql, %Q), "
#else







|







 







<







 







|
<
<







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
269
270
271
272
273
274
275

276
277
278
279
280
281
282
...
334
335
336
337
338
339
340
341


342
343
344
345
346
347
348
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
** $Id: alter.c,v 1.25 2007/05/15 14:34:32 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** The code in this file only exists if we are not omitting the
** ALTER TABLE logic from the build.
................................................................................
  Token *pName              /* The new table name. */
){
  int iDb;                  /* Database that contains the table */
  char *zDb;                /* Name of database iDb */
  Table *pTab;              /* Table being renamed */
  char *zName = 0;          /* NULL-terminated version of pName */ 
  sqlite3 *db = pParse->db; /* Database connection */

  int nTabName;             /* Number of UTF-8 characters in zTabName */
  const char *zTabName;     /* Original name of the table */
  Vdbe *v;
#ifndef SQLITE_OMIT_TRIGGER
  char *zWhere = 0;         /* Where clause to locate temp triggers */
#endif
  
................................................................................
    goto exit_rename_table;
  }
  sqlite3BeginWriteOperation(pParse, 0, iDb);
  sqlite3ChangeCookie(db, v, iDb);

  /* figure out how many UTF-8 characters are in zName */
  zTabName = pTab->zName;
  nTabName = sqlite3Utf8CharLen(zTabName, -1);



  /* Modify the sqlite_master table to use the new table name. */
  sqlite3NestedParse(pParse,
      "UPDATE %Q.%s SET "
#ifdef SQLITE_OMIT_TRIGGER
          "sql = sqlite_rename_table(sql, %Q), "
#else

Changes to src/build.c.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
....
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.431 2007/05/15 03:56:49 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Initialize the pParse structure as needed.
................................................................................
    pParse->pNewTable = 0;
    db->nTable++;
    db->flags |= SQLITE_InternChanges;

#ifndef SQLITE_OMIT_ALTERTABLE
    if( !p->pSelect ){
      const char *zName = (const char *)pParse->sNameToken.z;
      int nName, i, nUtfChar;
      assert( !pSelect && pCons && pEnd );
      if( pCons->z==0 ){
        pCons = pEnd;
      }
      nName = (const char *)pCons->z - zName;
      for(i=nUtfChar=0; i<nName; i++){
        if( (zName[i]&0xc0)!=0x80 ) nUtfChar++;
      }
      p->addColOffset = 13 + nUtfChar;
    }
#endif
  }
}

#ifndef SQLITE_OMIT_VIEW
/*







|







 







|





<
<
<
|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
....
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570



1571
1572
1573
1574
1575
1576
1577
1578
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.432 2007/05/15 14:34:32 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Initialize the pParse structure as needed.
................................................................................
    pParse->pNewTable = 0;
    db->nTable++;
    db->flags |= SQLITE_InternChanges;

#ifndef SQLITE_OMIT_ALTERTABLE
    if( !p->pSelect ){
      const char *zName = (const char *)pParse->sNameToken.z;
      int nName;
      assert( !pSelect && pCons && pEnd );
      if( pCons->z==0 ){
        pCons = pEnd;
      }
      nName = (const char *)pCons->z - zName;



      p->addColOffset = 13 + sqlite3Utf8CharLen(zName, nName);
    }
#endif
  }
}

#ifndef SQLITE_OMIT_VIEW
/*

Changes to src/tokenize.c.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that splits an SQL input string up into
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.128 2007/05/15 09:00:15 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include <stdlib.h>

/*
................................................................................
        if( c ) i++;
        return i;
      }
      /* Otherwise fall through to the next case */
    }
#endif
    default: {
      if( !IdChar(*z) || (*z & 0xc0)==0x80 ){
        break;
      }
      for(i=1; IdChar(z[i]); i++){}
      *tokenType = keywordCode((char*)z, i);
      return i;
    }
  }







|







 







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that splits an SQL input string up into
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.129 2007/05/15 14:34:32 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include <stdlib.h>

/*
................................................................................
        if( c ) i++;
        return i;
      }
      /* Otherwise fall through to the next case */
    }
#endif
    default: {
      if( !IdChar(*z) ){
        break;
      }
      for(i=1; IdChar(z[i]); i++){}
      *tokenType = keywordCode((char*)z, i);
      return i;
    }
  }

Changes to test/alter.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
699
700
701
702
703
704
705




706
707
708
709
710
711
712
713
714










715
716
717


718
















719
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the ALTER TABLE statement.
#
# $Id: alter.test,v 1.23 2007/05/15 09:00:16 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
................................................................................
    ALTER TABLE t11 ADD COLUMN abc;
  }
  catchsql {
    ALTER TABLE t11 ADD COLUMN abc;
  }
} {1 {duplicate column name: abc}}
do_test alter-11.2 {




  sqlite3_exec db {CREATE TABLE t11b("%81%82%83" text)}
  execsql {
    ALTER TABLE t11b ADD COLUMN abc;
  }
  catchsql {
    ALTER TABLE t11b ADD COLUMN abc;
  }
} {1 {duplicate column name: abc}}
do_test alter-11.3 {










  set v [sqlite3_exec db {CREATE TABLE t11c(%81%82%83 text)}]
  set v [string range $v 0 20]\175
} {1 {unrecognized token}}



















finish_test







|







 







>
>
>
>








|
>
>
>
>
>
>
>
>
>
>
|
<
<
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729


730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the ALTER TABLE statement.
#
# $Id: alter.test,v 1.24 2007/05/15 14:34:32 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
................................................................................
    ALTER TABLE t11 ADD COLUMN abc;
  }
  catchsql {
    ALTER TABLE t11 ADD COLUMN abc;
  }
} {1 {duplicate column name: abc}}
do_test alter-11.2 {
  execsql {INSERT INTO t11 VALUES(1,2)}
  sqlite3_exec db {SELECT %c6%c6 AS xyz, abc FROM t11}
} {0 {xyz abc 1 2}}
do_test alter-11.3 {
  sqlite3_exec db {CREATE TABLE t11b("%81%82%83" text)}
  execsql {
    ALTER TABLE t11b ADD COLUMN abc;
  }
  catchsql {
    ALTER TABLE t11b ADD COLUMN abc;
  }
} {1 {duplicate column name: abc}}
do_test alter-11.4 {
  execsql {INSERT INTO t11b VALUES(3,4)}
  sqlite3_exec db {SELECT %81%82%83 AS xyz, abc FROM t11b}
} {0 {xyz abc 3 4}}
do_test alter-11.5 {
  sqlite3_exec db {SELECT [%81%82%83] AS xyz, abc FROM t11b}
} {0 {xyz abc 3 4}}
do_test alter-11.6 {
  sqlite3_exec db {SELECT "%81%82%83" AS xyz, abc FROM t11b}
} {0 {xyz abc 3 4}}
do_test alter-11.7 {
  sqlite3_exec db {CREATE TABLE t11c(%81%82%83 text)}


  execsql {
    ALTER TABLE t11c ADD COLUMN abc;
  }
  catchsql {
    ALTER TABLE t11c ADD COLUMN abc;
  }
} {1 {duplicate column name: abc}}
do_test alter-11.8 {
  execsql {INSERT INTO t11c VALUES(5,6)}
  sqlite3_exec db {SELECT %81%82%83 AS xyz, abc FROM t11c}
} {0 {xyz abc 5 6}}
do_test alter-11.9 {
  sqlite3_exec db {SELECT [%81%82%83] AS xyz, abc FROM t11c}
} {0 {xyz abc 5 6}}
do_test alter-11.10 {
  sqlite3_exec db {SELECT "%81%82%83" AS xyz, abc FROM t11c}
} {0 {xyz abc 5 6}}


finish_test