/ Check-in [7f89a860]
Login

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

Overview
Comment:Make sure the default value on a column added using ALTER TABLE has the correct encoding. Ticket #3838. (CVS 6603)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7f89a860b7cd0993c36a8b0482c2bac950a875d6
User & Date: drh 2009-05-05 12:54:50
Context
2009-05-05
15:46
Changes to update.c to facilitate full coverage testing. (CVS 6604) check-in: 25a11b9e user: drh tags: trunk
12:54
Make sure the default value on a column added using ALTER TABLE has the correct encoding. Ticket #3838. (CVS 6603) check-in: 7f89a860 user: drh tags: trunk
2009-05-04
20:20
Make sure va_arg() does not occur on the same line as any "if" statement or "?" operator. (CVS 6602) check-in: 3543be6e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbemem.c.

    11     11   *************************************************************************
    12     12   **
    13     13   ** This file contains code use to manipulate "Mem" structure.  A "Mem"
    14     14   ** stores a single value in the VDBE.  Mem is an opaque structure visible
    15     15   ** only within the VDBE.  Interface routines refer to a Mem using the
    16     16   ** name sqlite_value
    17     17   **
    18         -** $Id: vdbemem.c,v 1.143 2009/05/01 21:13:37 drh Exp $
           18  +** $Id: vdbemem.c,v 1.144 2009/05/05 12:54:50 drh Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   #include "vdbeInt.h"
    22     22   
    23     23   /*
    24     24   ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
    25     25   ** P if required.
................................................................................
   975    975   
   976    976     if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
   977    977       zVal = sqlite3DbStrNDup(db, (char*)pExpr->token.z, pExpr->token.n);
   978    978       pVal = sqlite3ValueNew(db);
   979    979       if( !zVal || !pVal ) goto no_mem;
   980    980       sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
   981    981       if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
   982         -      sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc);
          982  +      sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
   983    983       }else{
   984         -      sqlite3ValueApplyAffinity(pVal, affinity, enc);
          984  +      sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
          985  +    }
          986  +    if( enc!=SQLITE_UTF8 ){
          987  +      sqlite3VdbeChangeEncoding(pVal, enc);
   985    988       }
   986    989     }else if( op==TK_UMINUS ) {
   987    990       if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
   988    991         pVal->u.i = -1 * pVal->u.i;
   989    992         /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
   990    993         pVal->r = (double)-1 * pVal->r;
   991    994       }

Added test/tkt3838.test.

            1  +# 2009 May 5
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# Ticket #3838
           13  +#
           14  +# The ticket reports that the encoding is UTF8 on the DEFAULT VALUE of
           15  +# a column added using ALTER TABLE even when the database is UTF16.
           16  +# Verify that this has been fixed.
           17  +#
           18  +# $Id: tkt3838.test,v 1.1 2009/05/05 12:54:50 drh Exp $
           19  +
           20  +set testdir [file dirname $argv0]
           21  +source $testdir/tester.tcl
           22  +
           23  +
           24  +do_test tkt3838-1.1 {
           25  +  db eval {
           26  +    PRAGMA encoding=UTF16;
           27  +    CREATE TABLE t1(x);
           28  +    INSERT INTO t1 VALUES(1);
           29  +    ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT '999';
           30  +    ALTER TABLE t1 ADD COLUMN c REAL DEFAULT '9e99';
           31  +    ALTER TABLE t1 ADD COLUMN d TEXT DEFAULT 'xyzzy';
           32  +    UPDATE t1 SET x=x+1;
           33  +    SELECT * FROM t1;
           34  +  }
           35  +} {2 999 9e+99 xyzzy}
           36  +
           37  +finish_test