aboutsummaryrefslogtreecommitdiff
path: root/src/func.c
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2004-11-19 05:14:54 +0000
committerdanielk1977 <danielk1977@noemail.net>2004-11-19 05:14:54 +0000
commit343e92610ecf58d20f0990b9721aa6073bdc4b9c (patch)
treea3161bd2bd4179e8abce46be775f7275f667d175 /src/func.c
parentd641d646ff6e428980130f64487f72c3c0b8f3ed (diff)
downloadsqlite-343e92610ecf58d20f0990b9721aa6073bdc4b9c.tar.gz
sqlite-343e92610ecf58d20f0990b9721aa6073bdc4b9c.zip
Fix bugs in ALTER TABLE related to (a) whitespace in table defn, (b) temp triggers. (CVS 2112)
FossilOrigin-Name: 1fd8e835a3656799c23f4ef6ea1311fecf5a15cb
Diffstat (limited to 'src/func.c')
-rw-r--r--src/func.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/func.c b/src/func.c
index c6ec755ba..e0b85cad6 100644
--- a/src/func.c
+++ b/src/func.c
@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: func.c,v 1.90 2004/11/18 15:44:29 danielk1977 Exp $
+** $Id: func.c,v 1.91 2004/11/19 05:14:55 danielk1977 Exp $
*/
#include <ctype.h>
#include <math.h>
@@ -552,26 +552,38 @@ static void altertableFunc(
int argc,
sqlite3_value **argv
){
- char const *zSql = sqlite3_value_text(argv[0]);
- char const *zTableName = sqlite3_value_text(argv[1]);
+ unsigned char const *zSql = sqlite3_value_text(argv[0]);
+ unsigned char const *zTableName = sqlite3_value_text(argv[1]);
+ int token;
+ Token tname;
char const *zCsr = zSql;
- char const *zPrev;
- char *zRet = 0;
- int tokenType = 0;
- int len;
+ int len = 0;
+ char *zRet;
- assert( argc==2 );
+ /* The principle used to locate the table name in the CREATE TABLE
+ ** statement is that the table name is the first token that is immediatedly
+ ** followed by a left parenthesis - TK_LP.
+ */
if( zSql ){
- while( tokenType!=TK_LP ){
- zPrev = zCsr-len;
- len = sqlite3GetToken(zCsr, &tokenType);
- zCsr += len;
- }
+ do {
+ /* Store the token that zCsr points to in tname. */
+ tname.z = zCsr;
+ tname.n = len;
+
+ /* Advance zCsr to the next token. Store that token type in 'token',
+ ** and it's length in 'len' (to be used next iteration of this loop).
+ */
+ do {
+ zCsr += len;
+ len = sqlite3GetToken(zCsr, &token);
+ } while( token==TK_SPACE );
+ assert( len>0 );
+ } while( token!=TK_LP );
- zRet = sqlite3MPrintf("%.*s%Q(%s", zPrev-zSql, zSql, zTableName, zCsr);
- sqlite3_result_text(context, zRet, -1, SQLITE_TRANSIENT);
- sqliteFree(zRet);
+ zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql,
+ zTableName, tname.z+tname.n);
+ sqlite3_result_text(context, zRet, -1, sqlite3FreeX);
}
}
#endif
@@ -605,7 +617,6 @@ static void altertriggerFunc(
** preceded by either TK_ON or TK_DOT and immediatedly followed by one
** of TK_WHEN, TK_BEGIN or TK_FOR.
*/
- assert( argc==2 );
if( zSql ){
do {
/* Store the token that zCsr points to in tname. */
@@ -641,8 +652,7 @@ static void altertriggerFunc(
*/
zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql,
zTableName, tname.z+tname.n);
- sqlite3_result_text(context, zRet, -1, SQLITE_TRANSIENT);
- sqliteFree(zRet);
+ sqlite3_result_text(context, zRet, -1, sqlite3FreeX);
}
}
#endif /* !SQLITE_OMIT_TRIGGER */