/ Check-in [99dcba1f]
Login

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

Overview
Comment:In the TCL interface, user-defined functions preserve the datatype returned by the Tcl procedure. (CVS 2453)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:99dcba1fb1fdaa2b8bc85046b00c14f6af596e8f
User & Date: drh 2005-05-05 10:30:30
Context
2005-05-05
11:04
Fix a datatype in trigger6.test that changed due to the previous check-in. (CVS 2454) check-in: c2af7d2c user: drh tags: trunk
10:30
In the TCL interface, user-defined functions preserve the datatype returned by the Tcl procedure. (CVS 2453) check-in: 99dcba1f user: drh tags: trunk
2005-05-03
12:30
Make sure all data structures have 8-byte alignment - necessary for the sparc architecture and helpful on other 64-bit platforms. Ticket #1232. Also update some comments in build.c. (CVS 2452) check-in: d9418851 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/tclsqlite.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** A TCL Interface to SQLite
    13     13   **
    14         -** $Id: tclsqlite.c,v 1.123 2005/04/28 19:03:37 drh Exp $
           14  +** $Id: tclsqlite.c,v 1.124 2005/05/05 10:30:30 drh Exp $
    15     15   */
    16     16   #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
    17     17   
    18     18   #include "sqliteInt.h"
    19     19   #include "hash.h"
    20     20   #include "tcl.h"
    21     21   #include <stdlib.h>
................................................................................
   267    267     for(i=0; i<argc; i++){
   268    268       if( SQLITE_NULL==sqlite3_value_type(argv[i]) ){
   269    269         Tcl_DStringAppendElement(&cmd, "");
   270    270       }else{
   271    271         Tcl_DStringAppendElement(&cmd, sqlite3_value_text(argv[i]));
   272    272       }
   273    273     }
   274         -  rc = Tcl_Eval(p->interp, Tcl_DStringValue(&cmd));
   275         -  if( rc ){
          274  +  rc = Tcl_EvalEx(p->interp, Tcl_DStringValue(&cmd), Tcl_DStringLength(&cmd),
          275  +                  TCL_EVAL_DIRECT);
          276  +  if( rc && rc!=TCL_RETURN ){
   276    277       sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); 
   277    278     }else{
   278         -    sqlite3_result_text(context, Tcl_GetStringResult(p->interp), -1, 
   279         -        SQLITE_TRANSIENT);
          279  +    Tcl_Obj *pVar = Tcl_GetObjResult(p->interp);
          280  +    int n;
          281  +    u8 *data;
          282  +    char *zType = pVar->typePtr ? pVar->typePtr->name : "";
          283  +    char c = zType[0];
          284  +    if( c=='b' && strcmp(zType,"bytearray")==0 ){
          285  +      data = Tcl_GetByteArrayFromObj(pVar, &n);
          286  +      sqlite3_result_blob(context, data, n, SQLITE_TRANSIENT);
          287  +      Tcl_IncrRefCount(pVar);
          288  +    }else if( (c=='b' && strcmp(zType,"boolean")==0) ||
          289  +          (c=='i' && strcmp(zType,"int")==0) ){
          290  +      Tcl_GetIntFromObj(0, pVar, &n);
          291  +      sqlite3_result_int(context, n);
          292  +    }else if( c=='d' && strcmp(zType,"double")==0 ){
          293  +      double r;
          294  +      Tcl_GetDoubleFromObj(0, pVar, &r);
          295  +      sqlite3_result_double(context, r);
          296  +    }else{
          297  +      data = Tcl_GetStringFromObj(pVar, &n);
          298  +      sqlite3_result_text(context, data, n, SQLITE_TRANSIENT);
          299  +      Tcl_IncrRefCount(pVar);
          300  +    }
   280    301     }
   281    302   }
   282    303   
   283    304   #ifndef SQLITE_OMIT_AUTHORIZATION
   284    305   /*
   285    306   ** This is the authentication function.  It appends the authentication
   286    307   ** type code and the two arguments to zCmd[] then invokes the result

Changes to test/tclsqlite.test.

    11     11   # This file implements regression tests for TCL interface to the
    12     12   # SQLite library. 
    13     13   #
    14     14   # Actually, all tests are based on the TCL interface, so the main
    15     15   # interface is pretty well tested.  This file contains some addition
    16     16   # tests for fringe issues that the main test suite does not cover.
    17     17   #
    18         -# $Id: tclsqlite.test,v 1.39 2005/04/03 23:54:45 danielk1977 Exp $
           18  +# $Id: tclsqlite.test,v 1.40 2005/05/05 10:30:30 drh Exp $
    19     19   
    20     20   set testdir [file dirname $argv0]
    21     21   source $testdir/tester.tcl
    22     22   
    23     23   # Check the error messages generated by tclsqlite
    24     24   #
    25     25   if {[sqlite3 -has-codec]} {
................................................................................
   313    313     db nullvalue NULL
   314    314     db nullvalue
   315    315   } {NULL}
   316    316   do_test tcl-8.3 {
   317    317     db nullvalue {}
   318    318     db eval {SELECT * FROM t1 WHERE b IS NULL}
   319    319   } {30 {}}
          320  +
          321  +# Test the return type of user-defined functions
          322  +#
          323  +do_test tcl-9.1 {
          324  +  db function ret_str {return "hi"}
          325  +  execsql {SELECT typeof(ret_str())}
          326  +} {text}
          327  +do_test tcl-9.2 {
          328  +  db function ret_dbl {return [expr {[clock seconds]*0.5}]}
          329  +  execsql {SELECT typeof(ret_dbl())}
          330  +} {real}
          331  +do_test tcl-9.3 {
          332  +  db function ret_int {clock seconds}
          333  +  execsql {SELECT typeof(ret_int())}
          334  +} {integer}
          335  +
   320    336   
   321    337   finish_test