/ Check-in [90d6573c]
Login

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

Overview
Comment:Split the logic for the ALTER TABLE command off into a separate source code file. (CVS 2342)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 90d6573c2631fac92b9e572e9e21698ae2480c9d
User & Date: drh 2005-02-15 20:47:57
Context
2005-02-15
21:36
Move the special built-in SQL functions used by ALTER TABLE out of func.c and into alter.c. (CVS 2343) check-in: dbd11a0c user: drh tags: trunk
20:47
Split the logic for the ALTER TABLE command off into a separate source code file. (CVS 2342) check-in: 90d6573c user: drh tags: trunk
16:23
Btree checks the autovacuum flag after locking the database file. (CVS 2341) check-in: 6610188f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to Makefile.in.

   108    108   ###############################################################################
   109    109   
   110    110   OPTS += -DSQLITE_OMIT_CURSOR          # Cursors do not work at this time
   111    111   TCC += -DSQLITE_OMIT_CURSOR
   112    112   
   113    113   # Object files for the SQLite library.
   114    114   #
   115         -LIBOBJ = attach.lo auth.lo btree.lo build.lo date.lo \
          115  +LIBOBJ = alter.lo attach.lo auth.lo btree.lo build.lo date.lo \
   116    116            delete.lo expr.lo func.lo hash.lo insert.lo \
   117    117            main.lo opcodes.lo os_unix.lo os_win.lo \
   118    118            pager.lo parse.lo pragma.lo printf.lo random.lo \
   119    119            select.lo table.lo tokenize.lo trigger.lo update.lo \
   120    120            util.lo vacuum.lo vdbe.lo vdbeapi.lo vdbeaux.lo vdbemem.lo \
   121    121            where.lo utf.lo legacy.lo
   122    122   
   123    123   # All of the source code files.
   124    124   #
   125    125   SRC = \
          126  +  $(TOP)/src/alter.c \
   126    127     $(TOP)/src/attach.c \
   127    128     $(TOP)/src/auth.c \
   128    129     $(TOP)/src/btree.c \
   129    130     $(TOP)/src/btree.h \
   130    131     $(TOP)/src/build.c \
   131    132     $(TOP)/src/date.c \
   132    133     $(TOP)/src/delete.c \
................................................................................
   256    257   lemon$(BEXE):	$(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
   257    258   	$(BCC) -o lemon $(TOP)/tool/lemon.c
   258    259   	cp $(TOP)/tool/lempar.c .
   259    260   
   260    261   
   261    262   # Rules to build individual files
   262    263   #
          264  +alter.lo:	$(TOP)/src/alter.c $(HDR)
          265  +	$(LTCOMPILE) -c $(TOP)/src/alter.c
          266  +
   263    267   attach.lo:	$(TOP)/src/attach.c $(HDR)
   264    268   	$(LTCOMPILE) -c $(TOP)/src/attach.c
   265    269   
   266    270   auth.lo:	$(TOP)/src/auth.c $(HDR)
   267    271   	$(LTCOMPILE) -c $(TOP)/src/auth.c
   268    272   
   269    273   btree.lo:	$(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h

Changes to main.mk.

    50     50   
    51     51   # This is how we compile
    52     52   #
    53     53   TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
    54     54   
    55     55   # Object files for the SQLite library.
    56     56   #
    57         -LIBOBJ+= attach.o auth.o btree.o build.o date.o delete.o \
           57  +LIBOBJ+= alter.o attach.o auth.o btree.o build.o date.o delete.o \
    58     58            expr.o func.o hash.o insert.o \
    59     59            main.o opcodes.o os_unix.o os_win.o \
    60     60            pager.o parse.o pragma.o printf.o random.o \
    61     61            select.o table.o tclsqlite.o tokenize.o trigger.o \
    62     62            update.o util.o vacuum.o \
    63     63            vdbe.o vdbeapi.o vdbeaux.o vdbemem.o \
    64     64            where.o utf.o legacy.o
    65     65   
    66     66   # All of the source code files.
    67     67   #
    68     68   SRC = \
           69  +  $(TOP)/src/alter.c \
    69     70     $(TOP)/src/attach.c \
    70     71     $(TOP)/src/auth.c \
    71     72     $(TOP)/src/btree.c \
    72     73     $(TOP)/src/btree.h \
    73     74     $(TOP)/src/build.c \
    74     75     $(TOP)/src/date.c \
    75     76     $(TOP)/src/delete.c \
................................................................................
   191    192   #
   192    193   lemon:	$(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
   193    194   	$(BCC) -o lemon $(TOP)/tool/lemon.c
   194    195   	cp $(TOP)/tool/lempar.c .
   195    196   
   196    197   # Rules to build individual files
   197    198   #
          199  +alter.o:	$(TOP)/src/alter.c $(HDR)
          200  +	$(TCCX) -c $(TOP)/src/alter.c
          201  +
   198    202   attach.o:	$(TOP)/src/attach.c $(HDR)
   199    203   	$(TCCX) -c $(TOP)/src/attach.c
   200    204   
   201    205   auth.o:	$(TOP)/src/auth.c $(HDR)
   202    206   	$(TCCX) -c $(TOP)/src/auth.c
   203    207   
   204    208   btree.o:	$(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h

Added src/alter.c.

            1  +/*
            2  +** 2005 February 15
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +*************************************************************************
           12  +** This file contains C code routines that used to generate VDBE code
           13  +** that implements the ALTER TABLE command.
           14  +**
           15  +** $Id: alter.c,v 1.1 2005/02/15 20:47:57 drh Exp $
           16  +*/
           17  +#include "sqliteInt.h"
           18  +
           19  +
           20  +#ifndef SQLITE_OMIT_ALTERTABLE
           21  +/*
           22  +** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" 
           23  +** command. 
           24  +*/
           25  +void sqlite3AlterRenameTable(
           26  +  Parse *pParse,            /* Parser context. */
           27  +  SrcList *pSrc,            /* The table to rename. */
           28  +  Token *pName              /* The new table name. */
           29  +){
           30  +  int iDb;                  /* Database that contains the table */
           31  +  char *zDb;                /* Name of database iDb */
           32  +  Table *pTab;              /* Table being renamed */
           33  +  char *zName = 0;          /* NULL-terminated version of pName */ 
           34  +  char *zWhere = 0;         /* Where clause of schema elements to reparse */
           35  +  sqlite3 *db = pParse->db; /* Database connection */
           36  +  Vdbe *v;
           37  +#ifndef SQLITE_OMIT_TRIGGER
           38  +  char *zTempTrig = 0;      /* Where clause to locate temp triggers */
           39  +#endif
           40  +  
           41  +  assert( pSrc->nSrc==1 );
           42  +
           43  +  pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
           44  +  if( !pTab ) goto exit_rename_table;
           45  +  iDb = pTab->iDb;
           46  +  zDb = db->aDb[iDb].zName;
           47  +
           48  +  /* Get a NULL terminated version of the new table name. */
           49  +  zName = sqlite3NameFromToken(pName);
           50  +  if( !zName ) goto exit_rename_table;
           51  +
           52  +  /* Check that a table or index named 'zName' does not already exist
           53  +  ** in database iDb. If so, this is an error.
           54  +  */
           55  +  if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
           56  +    sqlite3ErrorMsg(pParse, 
           57  +        "there is already another table or index with this name: %s", zName);
           58  +    goto exit_rename_table;
           59  +  }
           60  +
           61  +  /* Make sure it is not a system table being altered, or a reserved name
           62  +  ** that the table is being renamed to.
           63  +  */
           64  +  if( strlen(pTab->zName)>6 && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ){
           65  +    sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
           66  +    goto exit_rename_table;
           67  +  }
           68  +  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
           69  +    goto exit_rename_table;
           70  +  }
           71  +
           72  +#ifndef SQLITE_OMIT_AUTHORIZATION
           73  +  /* Invoke the authorization callback. */
           74  +  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
           75  +    goto exit_rename_table;
           76  +  }
           77  +#endif
           78  +
           79  +  /* Begin a transaction and code the VerifyCookie for database iDb. 
           80  +  ** Then modify the schema cookie (since the ALTER TABLE modifies the
           81  +  ** schema).
           82  +  */
           83  +  v = sqlite3GetVdbe(pParse);
           84  +  if( v==0 ){
           85  +    goto exit_rename_table;
           86  +  }
           87  +  sqlite3BeginWriteOperation(pParse, 0, iDb);
           88  +  sqlite3ChangeCookie(db, v, iDb);
           89  +
           90  +  /* Modify the sqlite_master table to use the new table name. */
           91  +  sqlite3NestedParse(pParse,
           92  +      "UPDATE %Q.%s SET "
           93  +#ifdef SQLITE_OMIT_TRIGGER
           94  +          "sql = sqlite_rename_table(sql, %Q), "
           95  +#else
           96  +          "sql = CASE "
           97  +            "WHEN type = 'trigger' THEN sqlite_rename_trigger(sql, %Q)"
           98  +            "ELSE sqlite_rename_table(sql, %Q) END, "
           99  +#endif
          100  +          "tbl_name = %Q, "
          101  +          "name = CASE "
          102  +            "WHEN type='table' THEN %Q "
          103  +            "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
          104  +              "'sqlite_autoindex_' || %Q || substr(name, %d+18,10) "
          105  +            "ELSE name END "
          106  +      "WHERE tbl_name=%Q AND "
          107  +          "(type='table' OR type='index' OR type='trigger');", 
          108  +      zDb, SCHEMA_TABLE(iDb), zName, zName, zName, 
          109  +#ifndef SQLITE_OMIT_TRIGGER
          110  +zName,
          111  +#endif
          112  +      zName, strlen(pTab->zName), pTab->zName
          113  +  );
          114  +
          115  +#ifndef SQLITE_OMIT_AUTOINCREMENT
          116  +  /* If the sqlite_sequence table exists in this database, then update 
          117  +  ** it with the new table name.
          118  +  */
          119  +  if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
          120  +    sqlite3NestedParse(pParse,
          121  +        "UPDATE %Q.sqlite_sequence set name = %Q WHERE name = %Q",
          122  +        zDb, zName, pTab->zName);
          123  +  }
          124  +#endif
          125  +
          126  +#ifndef SQLITE_OMIT_TRIGGER
          127  +  /* If there are TEMP triggers on this table, modify the sqlite_temp_master
          128  +  ** table. Don't do this if the table being ALTERed is itself located in
          129  +  ** the temp database.
          130  +  */
          131  +  if( iDb!=1 ){
          132  +    Trigger *pTrig;
          133  +    char *tmp = 0;
          134  +    for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
          135  +      if( pTrig->iDb==1 ){
          136  +        if( !zTempTrig ){
          137  +          zTempTrig = 
          138  +              sqlite3MPrintf("type = 'trigger' AND (name=%Q", pTrig->name);
          139  +        }else{
          140  +          tmp = zTempTrig;
          141  +          zTempTrig = sqlite3MPrintf("%s OR name=%Q", zTempTrig, pTrig->name);
          142  +          sqliteFree(tmp);
          143  +        }
          144  +      }
          145  +    }
          146  +    if( zTempTrig ){
          147  +      tmp = zTempTrig;
          148  +      zTempTrig = sqlite3MPrintf("%s)", zTempTrig);
          149  +      sqliteFree(tmp);
          150  +      sqlite3NestedParse(pParse, 
          151  +          "UPDATE sqlite_temp_master SET "
          152  +              "sql = sqlite_rename_trigger(sql, %Q), "
          153  +              "tbl_name = %Q "
          154  +              "WHERE %s;", zName, zName, zTempTrig);
          155  +    }
          156  +  }
          157  +#endif
          158  +
          159  +  /* Drop the elements of the in-memory schema that refered to the table
          160  +  ** renamed and load the new versions from the database.
          161  +  */
          162  +  if( pParse->nErr==0 ){
          163  +#ifndef SQLITE_OMIT_TRIGGER
          164  +    Trigger *pTrig;
          165  +    for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
          166  +      assert( pTrig->iDb==iDb || pTrig->iDb==1 );
          167  +      sqlite3VdbeOp3(v, OP_DropTrigger, pTrig->iDb, 0, pTrig->name, 0);
          168  +    }
          169  +#endif
          170  +    sqlite3VdbeOp3(v, OP_DropTable, iDb, 0, pTab->zName, 0);
          171  +    zWhere = sqlite3MPrintf("tbl_name=%Q", zName);
          172  +    sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, zWhere, P3_DYNAMIC);
          173  +#ifndef SQLITE_OMIT_TRIGGER
          174  +    if( zTempTrig ){
          175  +      sqlite3VdbeOp3(v, OP_ParseSchema, 1, 0, zTempTrig, P3_DYNAMIC);
          176  +    }
          177  +  }else{
          178  +    sqliteFree(zTempTrig);
          179  +#endif
          180  +  }
          181  +
          182  +exit_rename_table:
          183  +  sqlite3SrcListDelete(pSrc);
          184  +  sqliteFree(zName);
          185  +}
          186  +#endif  /* SQLITE_ALTER_TABLE */

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.310 2005/02/14 20:48:20 drh Exp $
           25  +** $Id: build.c,v 1.311 2005/02/15 20:47:57 drh Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
  2998   2998     if( pIndex ){
  2999   2999       sqlite3BeginWriteOperation(pParse, 0, iDb);
  3000   3000       sqlite3RefillIndex(pParse, pIndex, -1);
  3001   3001       return;
  3002   3002     }
  3003   3003     sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
  3004   3004   }
  3005         -#endif
  3006         -
  3007         -#ifndef SQLITE_OMIT_ALTERTABLE
  3008         -/*
  3009         -** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" 
  3010         -** command. 
  3011         -*/
  3012         -void sqlite3AlterRenameTable(
  3013         -  Parse *pParse,            /* Parser context. */
  3014         -  SrcList *pSrc,            /* The table to rename. */
  3015         -  Token *pName              /* The new table name. */
  3016         -){
  3017         -  int iDb;                  /* Database that contains the table */
  3018         -  char *zDb;                /* Name of database iDb */
  3019         -  Table *pTab;              /* Table being renamed */
  3020         -  char *zName = 0;          /* NULL-terminated version of pName */ 
  3021         -  char *zWhere = 0;         /* Where clause of schema elements to reparse */
  3022         -  sqlite3 *db = pParse->db; /* Database connection */
  3023         -  Vdbe *v;
  3024         -#ifndef SQLITE_OMIT_TRIGGER
  3025         -  char *zTempTrig = 0;      /* Where clause to locate temp triggers */
  3026         -#endif
  3027         -  
  3028         -  assert( pSrc->nSrc==1 );
  3029         -
  3030         -  pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
  3031         -  if( !pTab ) goto exit_alter_table;
  3032         -  iDb = pTab->iDb;
  3033         -  zDb = db->aDb[iDb].zName;
  3034         -
  3035         -  /* Get a NULL terminated version of the new table name. */
  3036         -  zName = sqlite3NameFromToken(pName);
  3037         -  if( !zName ) goto exit_alter_table;
  3038         -
  3039         -  /* Check that a table or index named 'zName' does not already exist
  3040         -  ** in database iDb. If so, this is an error.
  3041         -  */
  3042         -  if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
  3043         -    sqlite3ErrorMsg(pParse, 
  3044         -        "there is already another table or index with this name: %s", zName);
  3045         -    goto exit_alter_table;
  3046         -  }
  3047         -
  3048         -  /* Make sure it is not a system table being altered, or a reserved name
  3049         -  ** that the table is being renamed to.
  3050         -  */
  3051         -  if( strlen(pTab->zName)>6 && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ){
  3052         -    sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
  3053         -    goto exit_alter_table;
  3054         -  }
  3055         -  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
  3056         -    goto exit_alter_table;
  3057         -  }
  3058         -
  3059         -#ifndef SQLITE_OMIT_AUTHORIZATION
  3060         -  /* Invoke the authorization callback. */
  3061         -  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
  3062         -    goto exit_alter_table;
  3063         -  }
  3064         -#endif
  3065         -
  3066         -  /* Begin a transaction and code the VerifyCookie for database iDb. 
  3067         -  ** Then modify the schema cookie (since the ALTER TABLE modifies the
  3068         -  ** schema).
  3069         -  */
  3070         -  v = sqlite3GetVdbe(pParse);
  3071         -  if( v==0 ){
  3072         -    goto exit_alter_table;
  3073         -  }
  3074         -  sqlite3BeginWriteOperation(pParse, 0, iDb);
  3075         -  sqlite3ChangeCookie(db, v, iDb);
  3076         -
  3077         -  /* Modify the sqlite_master table to use the new table name. */
  3078         -  sqlite3NestedParse(pParse,
  3079         -      "UPDATE %Q.%s SET "
  3080         -#ifdef SQLITE_OMIT_TRIGGER
  3081         -          "sql = sqlite_alter_table(sql, %Q), "
  3082         -#else
  3083         -          "sql = CASE "
  3084         -            "WHEN type = 'trigger' THEN sqlite_alter_trigger(sql, %Q)"
  3085         -            "ELSE sqlite_alter_table(sql, %Q) END, "
  3086         -#endif
  3087         -          "tbl_name = %Q, "
  3088         -          "name = CASE "
  3089         -            "WHEN type='table' THEN %Q "
  3090         -            "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
  3091         -              "'sqlite_autoindex_' || %Q || substr(name, %d+18,10) "
  3092         -            "ELSE name END "
  3093         -      "WHERE tbl_name=%Q AND "
  3094         -          "(type='table' OR type='index' OR type='trigger');", 
  3095         -      zDb, SCHEMA_TABLE(iDb), zName, zName, zName, 
  3096         -#ifndef SQLITE_OMIT_TRIGGER
  3097         -zName,
  3098         -#endif
  3099         -      zName, strlen(pTab->zName), pTab->zName
  3100         -  );
  3101         -
  3102         -#ifndef SQLITE_OMIT_AUTOINCREMENT
  3103         -  /* If the sqlite_sequence table exists in this database, then update 
  3104         -  ** it with the new table name.
  3105         -  */
  3106         -  if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
  3107         -    sqlite3NestedParse(pParse,
  3108         -        "UPDATE %Q.sqlite_sequence set name = %Q WHERE name = %Q",
  3109         -        zDb, zName, pTab->zName);
  3110         -  }
  3111         -#endif
  3112         -
  3113         -#ifndef SQLITE_OMIT_TRIGGER
  3114         -  /* If there are TEMP triggers on this table, modify the sqlite_temp_master
  3115         -  ** table. Don't do this if the table being ALTERed is itself located in
  3116         -  ** the temp database.
  3117         -  */
  3118         -  if( iDb!=1 ){
  3119         -    Trigger *pTrig;
  3120         -    char *tmp = 0;
  3121         -    for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
  3122         -      if( pTrig->iDb==1 ){
  3123         -        if( !zTempTrig ){
  3124         -          zTempTrig = 
  3125         -              sqlite3MPrintf("type = 'trigger' AND (name=%Q", pTrig->name);
  3126         -        }else{
  3127         -          tmp = zTempTrig;
  3128         -          zTempTrig = sqlite3MPrintf("%s OR name=%Q", zTempTrig, pTrig->name);
  3129         -          sqliteFree(tmp);
  3130         -        }
  3131         -      }
  3132         -    }
  3133         -    if( zTempTrig ){
  3134         -      tmp = zTempTrig;
  3135         -      zTempTrig = sqlite3MPrintf("%s)", zTempTrig);
  3136         -      sqliteFree(tmp);
  3137         -      sqlite3NestedParse(pParse, 
  3138         -          "UPDATE sqlite_temp_master SET "
  3139         -              "sql = sqlite_alter_trigger(sql, %Q), "
  3140         -              "tbl_name = %Q "
  3141         -              "WHERE %s;", zName, zName, zTempTrig);
  3142         -    }
  3143         -  }
  3144         -#endif
  3145         -
  3146         -  /* Drop the elements of the in-memory schema that refered to the table
  3147         -  ** renamed and load the new versions from the database.
  3148         -  */
  3149         -  if( pParse->nErr==0 ){
  3150         -#ifndef SQLITE_OMIT_TRIGGER
  3151         -    Trigger *pTrig;
  3152         -    for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
  3153         -      assert( pTrig->iDb==iDb || pTrig->iDb==1 );
  3154         -      sqlite3VdbeOp3(v, OP_DropTrigger, pTrig->iDb, 0, pTrig->name, 0);
  3155         -    }
  3156         -#endif
  3157         -    sqlite3VdbeOp3(v, OP_DropTable, iDb, 0, pTab->zName, 0);
  3158         -    zWhere = sqlite3MPrintf("tbl_name=%Q", zName);
  3159         -    sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, zWhere, P3_DYNAMIC);
  3160         -#ifndef SQLITE_OMIT_TRIGGER
  3161         -    if( zTempTrig ){
  3162         -      sqlite3VdbeOp3(v, OP_ParseSchema, 1, 0, zTempTrig, P3_DYNAMIC);
  3163         -    }
  3164         -  }else{
  3165         -    sqliteFree(zTempTrig);
  3166         -#endif
  3167         -  }
  3168         -
  3169         -exit_alter_table:
  3170         -  sqlite3SrcListDelete(pSrc);
  3171         -  sqliteFree(zName);
  3172         -}
  3173   3005   #endif

Changes to src/func.c.

    12     12   ** This file contains the C functions that implement various SQL
    13     13   ** functions of SQLite.  
    14     14   **
    15     15   ** There is only one exported symbol in this file - the function
    16     16   ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
    17     17   ** All other code has file scope.
    18     18   **
    19         -** $Id: func.c,v 1.94 2005/02/09 01:40:25 danielk1977 Exp $
           19  +** $Id: func.c,v 1.95 2005/02/15 20:47:57 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   #include <ctype.h>
    23     23   #include <math.h>
    24     24   #include <stdlib.h>
    25     25   #include <assert.h>
    26     26   #include "vdbeInt.h"
................................................................................
   537    537   /*
   538    538   ** This function is used by SQL generated to implement the 
   539    539   ** ALTER TABLE command. The first argument is the text of a CREATE TABLE or
   540    540   ** CREATE INDEX command. The second is a table name. The table name in 
   541    541   ** the CREATE TABLE or CREATE INDEX statement is replaced with the second
   542    542   ** argument and the result returned. Examples:
   543    543   **
   544         -** sqlite_alter_table('CREATE TABLE abc(a, b, c)', 'def')
          544  +** sqlite_rename_table('CREATE TABLE abc(a, b, c)', 'def')
   545    545   **     -> 'CREATE TABLE def(a, b, c)'
   546    546   **
   547         -** sqlite_alter_table('CREATE INDEX i ON abc(a)', 'def')
          547  +** sqlite_rename_table('CREATE INDEX i ON abc(a)', 'def')
   548    548   **     -> 'CREATE INDEX i ON def(a, b, c)'
   549    549   */
   550         -static void altertableFunc(
          550  +static void renameTableFunc(
   551    551     sqlite3_context *context,
   552    552     int argc,
   553    553     sqlite3_value **argv
   554    554   ){
   555    555     unsigned char const *zSql = sqlite3_value_text(argv[0]);
   556    556     unsigned char const *zTableName = sqlite3_value_text(argv[1]);
   557    557   
................................................................................
   590    590   
   591    591   #ifndef SQLITE_OMIT_ALTERTABLE
   592    592   #ifndef SQLITE_OMIT_TRIGGER
   593    593   /* This function is used by SQL generated to implement the ALTER TABLE
   594    594   ** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER 
   595    595   ** statement. The second is a table name. The table name in the CREATE 
   596    596   ** TRIGGER statement is replaced with the second argument and the result 
   597         -** returned. This is analagous to altertableFunc() above, except for CREATE
          597  +** returned. This is analagous to renameTableFunc() above, except for CREATE
   598    598   ** TRIGGER, not CREATE INDEX and CREATE TABLE.
   599    599   */
   600         -static void altertriggerFunc(
          600  +static void renameTriggerFunc(
   601    601     sqlite3_context *context,
   602    602     int argc,
   603    603     sqlite3_value **argv
   604    604   ){
   605    605     unsigned char const *zSql = sqlite3_value_text(argv[0]);
   606    606     unsigned char const *zTableName = sqlite3_value_text(argv[1]);
   607    607   
................................................................................
  1119   1119       { "nullif",             2, 0, SQLITE_UTF8,    1, nullifFunc },
  1120   1120       { "sqlite_version",     0, 0, SQLITE_UTF8,    0, versionFunc},
  1121   1121       { "quote",              1, 0, SQLITE_UTF8,    0, quoteFunc  },
  1122   1122       { "last_insert_rowid",  0, 1, SQLITE_UTF8,    0, last_insert_rowid },
  1123   1123       { "changes",            0, 1, SQLITE_UTF8,    0, changes    },
  1124   1124       { "total_changes",      0, 1, SQLITE_UTF8,    0, total_changes },
  1125   1125   #ifndef SQLITE_OMIT_ALTERTABLE
  1126         -    { "sqlite_alter_table", 2, 0, SQLITE_UTF8,    0, altertableFunc},
         1126  +    { "sqlite_rename_table",  2, 0, SQLITE_UTF8,  0, renameTableFunc},
  1127   1127   #ifndef SQLITE_OMIT_TRIGGER
  1128         -    { "sqlite_alter_trigger", 2, 0, SQLITE_UTF8,  0, altertriggerFunc},
         1128  +    { "sqlite_rename_trigger",2, 0, SQLITE_UTF8,  0, renameTriggerFunc},
  1129   1129   #endif
  1130   1130   #endif
  1131   1131   #ifdef SQLITE_SOUNDEX
  1132   1132       { "soundex",            1, 0, SQLITE_UTF8, 0, soundexFunc},
  1133   1133   #endif
  1134   1134   #ifdef SQLITE_TEST
  1135   1135       { "randstr",               2, 0, SQLITE_UTF8, 0, randStr    },