/ Check-in [19d56d99]
Login

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

Overview
Comment:Return an error if the user attempts to rename a view. Related to (but not a fix for) #2831. (CVS 4623)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 19d56d997f50be81ac2baace16b7e7a1b674301a
User & Date: danielk1977 2007-12-13 08:15:31
Context
2007-12-13
17:50
Additional test cases for tkt2822. Fix a related bug in printf(). (CVS 4624) check-in: 8f184e40 user: drh tags: trunk
08:15
Return an error if the user attempts to rename a view. Related to (but not a fix for) #2831. (CVS 4623) check-in: 19d56d99 user: danielk1977 tags: trunk
07:58
Adjust the test suite to account for recent changes related to #2822. Most changes are related to English language error messages only. (CVS 4622) check-in: 2f88b9b3 user: danielk1977 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
...
315
316
317
318
319
320
321







322
323
324
325
326
327
328
**    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.33 2007/10/20 20:58:57 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.
................................................................................
  if( strlen(pTab->zName)>6 && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ){
    sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
    goto exit_rename_table;
  }
  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
    goto exit_rename_table;
  }








#ifndef SQLITE_OMIT_AUTHORIZATION
  /* Invoke the authorization callback. */
  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
    goto exit_rename_table;
  }
#endif







|







 







>
>
>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
**    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.34 2007/12/13 08:15:31 danielk1977 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.
................................................................................
  if( strlen(pTab->zName)>6 && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ){
    sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
    goto exit_rename_table;
  }
  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
    goto exit_rename_table;
  }

#ifndef SQLITE_OMIT_VIEW
  if( pTab->pSelect ){
    sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);
    goto exit_rename_table;
  }
#endif

#ifndef SQLITE_OMIT_AUTHORIZATION
  /* Invoke the authorization callback. */
  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
    goto exit_rename_table;
  }
#endif

Changes to test/alter.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
33
34
35
36
37
38
39


40
41
42
43
44
45
46
...
754
755
756
757
758
759
760




761





















762
#    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.27 2007/10/23 15:39:46 drh Exp $
#

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

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
................................................................................
#     attached database.
# alter-1.9.*: Tests for ALTER TABLE when their is whitespace between the
#     table name and left parenthesis token. i.e: 
#     "CREATE TABLE abc       (a, b, c);"
# alter-2.*: Test error conditions and messages.
# alter-3.*: Test ALTER TABLE on tables that have TRIGGERs attached to them.
# alter-4.*: Test ALTER TABLE on tables that have AUTOINCREMENT fields.


#

# Create some tables to rename.  Be sure to include some TEMP tables
# and some tables with odd names.
#
do_test alter-1.1 {
  ifcapable tempdb {
................................................................................
    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







|







 







>
>







 







>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#    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.28 2007/12/13 08:15:31 danielk1977 Exp $
#

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

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
................................................................................
#     attached database.
# alter-1.9.*: Tests for ALTER TABLE when their is whitespace between the
#     table name and left parenthesis token. i.e: 
#     "CREATE TABLE abc       (a, b, c);"
# alter-2.*: Test error conditions and messages.
# alter-3.*: Test ALTER TABLE on tables that have TRIGGERs attached to them.
# alter-4.*: Test ALTER TABLE on tables that have AUTOINCREMENT fields.
# ...
# alter-12.*: Test ALTER TABLE on views.
#

# Create some tables to rename.  Be sure to include some TEMP tables
# and some tables with odd names.
#
do_test alter-1.1 {
  ifcapable tempdb {
................................................................................
    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}}
}

do_test alter-12.1 {
  execsql {
    CREATE TABLE t12(a, b, c);
    CREATE VIEW v1 AS SELECT * FROM t12;
  }
} {}
do_test alter-12.2 {
  catchsql {
    ALTER TABLE v1 RENAME TO v2;
  }
} {1 {view v1 may not be altered}}
do_test alter-12.3 {
  execsql { SELECT * FROM v1; }
} {}
do_test alter-12.4 {
  db close
  sqlite3 db test.db
  execsql { SELECT * FROM v1; }
} {}
do_test alter-12.5 {
  catchsql { 
    ALTER TABLE v1 ADD COLUMN new_column;
  }
} {1 {Cannot add a column to a view}}


finish_test