Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix the onecolumn method in the TCL interface so that it works the same as the eval method in all ways except for returning just the first value in the result set. (CVS 1944) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
f323e4f86a08fe6448cbd4ff7cab459e |
User & Date: | drh 2004-09-07 13:20:35.000 |
Context
2004-09-07
| ||
16:19 | Wildcards with the same name map into the same variable number. New api sqlite3_bind_parameter_index() added to map wildcard names into wildcard index numbers. Support for "?nnn" wildcards. (CVS 1945) (check-in: 435b3f301f user: drh tags: trunk) | |
13:20 | Fix the onecolumn method in the TCL interface so that it works the same as the eval method in all ways except for returning just the first value in the result set. (CVS 1944) (check-in: f323e4f86a user: drh tags: trunk) | |
11:28 | Lemon escapes backslashes in filenames in #line directives it generates. Ticket #892. (CVS 1943) (check-in: d53047cbbc user: drh tags: trunk) | |
Changes
Changes to src/tclsqlite.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** A TCL Interface to SQLite ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** A TCL Interface to SQLite ** ** $Id: tclsqlite.c,v 1.105 2004/09/07 13:20:35 drh Exp $ */ #ifndef NO_TCL /* Omit this whole file if TCL is unavailable */ #include "sqliteInt.h" #include "hash.h" #include "tcl.h" #include <stdlib.h> |
︙ | ︙ | |||
69 70 71 72 73 74 75 | char *zAuth; /* The authorization callback routine */ SqlFunc *pFunc; /* List of SQL functions */ SqlCollate *pCollate; /* List of SQL collation functions */ int rc; /* Return code of most recent sqlite3_exec() */ Tcl_Obj *pCollateNeeded; /* Collation needed script */ }; | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | char *zAuth; /* The authorization callback routine */ SqlFunc *pFunc; /* List of SQL functions */ SqlCollate *pCollate; /* List of SQL collation functions */ int rc; /* Return code of most recent sqlite3_exec() */ Tcl_Obj *pCollateNeeded; /* Collation needed script */ }; /* ** TCL calls this procedure when an sqlite3 database command is ** deleted. */ static void DbDeleteCmd(void *db){ SqliteDb *pDb = (SqliteDb*)db; sqlite3_close(pDb->db); |
︙ | ︙ | |||
492 493 494 495 496 497 498 | }else{ sqlite3_busy_handler(pDb->db, 0, 0); } } break; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | }else{ sqlite3_busy_handler(pDb->db, 0, 0); } } break; } /* $db changes ** ** Return the number of rows that were modified, inserted, or deleted by ** the most recent INSERT, UPDATE or DELETE statement, not including ** any changes made by trigger programs. */ case DB_CHANGES: { |
︙ | ︙ | |||
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | case DB_ERRORCODE: { Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_errcode(pDb->db))); break; } /* ** $db eval $sql ?array? ?{ ...code... }? ** ** The SQL statement in $sql is evaluated. For each row, the values are ** placed in elements of the array named "array" and ...code... is executed. ** If "array" and "code" are omitted, then no callback is every invoked. ** If "array" is an empty string, then the values are placed in variables ** that have the same name as the fields extracted by the query. */ case DB_EVAL: { char const *zSql; /* Next SQL statement to execute */ char const *zLeft; /* What is left after first stmt in zSql */ sqlite3_stmt *pStmt; /* Compiled SQL statment */ Tcl_Obj *pArray; /* Name of array into which results are written */ Tcl_Obj *pScript; /* Script to run for each result set */ Tcl_Obj **apParm; /* Parameters that need a Tcl_DecrRefCount() */ int nParm; /* Number of entries used in apParm[] */ Tcl_Obj *aParm[10]; /* Static space for apParm[] in the common case */ | > > > > > > > | | > | > > | | | > > > | 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | case DB_ERRORCODE: { Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_errcode(pDb->db))); break; } /* ** $db eval $sql ?array? ?{ ...code... }? ** $db onecolumn $sql ** ** The SQL statement in $sql is evaluated. For each row, the values are ** placed in elements of the array named "array" and ...code... is executed. ** If "array" and "code" are omitted, then no callback is every invoked. ** If "array" is an empty string, then the values are placed in variables ** that have the same name as the fields extracted by the query. ** ** The onecolumn method is the equivalent of: ** lindex [$db eval $sql] 0 */ case DB_ONECOLUMN: case DB_EVAL: { char const *zSql; /* Next SQL statement to execute */ char const *zLeft; /* What is left after first stmt in zSql */ sqlite3_stmt *pStmt; /* Compiled SQL statment */ Tcl_Obj *pArray; /* Name of array into which results are written */ Tcl_Obj *pScript; /* Script to run for each result set */ Tcl_Obj **apParm; /* Parameters that need a Tcl_DecrRefCount() */ int nParm; /* Number of entries used in apParm[] */ Tcl_Obj *aParm[10]; /* Static space for apParm[] in the common case */ Tcl_Obj *pRet; /* Value to be returned */ if( choice==DB_ONECOLUMN ){ if( objc!=3 ){ Tcl_WrongNumArgs(interp, 2, objv, "SQL"); return TCL_ERROR; } pRet = 0; }else{ if( objc<3 || objc>5 ){ Tcl_WrongNumArgs(interp, 2, objv, "SQL ?ARRAY-NAME? ?SCRIPT?"); return TCL_ERROR; } pRet = Tcl_NewObj(); Tcl_IncrRefCount(pRet); } if( objc==3 ){ pArray = pScript = 0; }else if( objc==4 ){ pArray = 0; pScript = objv[3]; }else{ |
︙ | ︙ | |||
780 781 782 783 784 785 786 | sqlite3_bind_text(pStmt, i, data, n, SQLITE_STATIC); Tcl_IncrRefCount(pVar); apParm[nParm++] = pVar; } } } } | < | 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | sqlite3_bind_text(pStmt, i, data, n, SQLITE_STATIC); Tcl_IncrRefCount(pVar); apParm[nParm++] = pVar; } } } } /* Compute column names */ nCol = sqlite3_column_count(pStmt); if( pScript ){ apColName = (Tcl_Obj**)Tcl_Alloc( sizeof(Tcl_Obj*)*nCol ); if( apColName==0 ) break; for(i=0; i<nCol; i++){ |
︙ | ︙ | |||
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 | if( pScript ){ if( pArray==0 ){ Tcl_ObjSetVar2(interp, apColName[i], 0, pVal, 0); }else{ Tcl_ObjSetVar2(interp, pArray, apColName[i], pVal, 0); } }else{ Tcl_ListObjAppendElement(interp, pRet, pVal); } } if( pScript ){ rc = Tcl_EvalObjEx(interp, pScript, 0); if( rc!=TCL_ERROR ) rc = TCL_OK; } } /* Free the column name objects */ if( pScript ){ for(i=0; i<nCol; i++){ Tcl_DecrRefCount(apColName[i]); } Tcl_Free((char*)apColName); | > > > > > > > | 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 | if( pScript ){ if( pArray==0 ){ Tcl_ObjSetVar2(interp, apColName[i], 0, pVal, 0); }else{ Tcl_ObjSetVar2(interp, pArray, apColName[i], pVal, 0); } }else if( choice==DB_ONECOLUMN ){ if( pRet==0 ){ pRet = pVal; Tcl_IncrRefCount(pRet); } goto end_step; }else{ Tcl_ListObjAppendElement(interp, pRet, pVal); } } if( pScript ){ rc = Tcl_EvalObjEx(interp, pScript, 0); if( rc!=TCL_ERROR ) rc = TCL_OK; } } end_step: /* Free the column name objects */ if( pScript ){ for(i=0; i<nCol; i++){ Tcl_DecrRefCount(apColName[i]); } Tcl_Free((char*)apColName); |
︙ | ︙ | |||
888 889 890 891 892 893 894 | break; } zSql = zLeft; } Tcl_DecrRefCount(objv[2]); | > | | | | > | 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 | break; } zSql = zLeft; } Tcl_DecrRefCount(objv[2]); if( pRet ){ if( rc==TCL_OK ){ Tcl_SetObjResult(interp, pRet); } Tcl_DecrRefCount(pRet); } break; } /* ** $db function NAME SCRIPT ** |
︙ | ︙ | |||
945 946 947 948 949 950 951 | rowid = sqlite3_last_insert_rowid(pDb->db); pResult = Tcl_GetObjResult(interp); Tcl_SetIntObj(pResult, rowid); break; } /* | > > | > | | > | < < | > | > > > > > > | > > > | | > > | > > > | > | > | < > > | < | | | | 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | rowid = sqlite3_last_insert_rowid(pDb->db); pResult = Tcl_GetObjResult(interp); Tcl_SetIntObj(pResult, rowid); break; } /* ** The DB_ONECOLUMN method is implemented together with DB_EVAL. */ /* $db progress ?N CALLBACK? ** ** Invoke the given callback every N virtual machine opcodes while executing ** queries. */ case DB_PROGRESS: { if( objc==2 ){ if( pDb->zProgress ){ Tcl_AppendResult(interp, pDb->zProgress, 0); } }else if( objc==4 ){ char *zProgress; int len; int N; if( TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &N) ){ return TCL_ERROR; }; if( pDb->zProgress ){ Tcl_Free(pDb->zProgress); } zProgress = Tcl_GetStringFromObj(objv[3], &len); if( zProgress && len>0 ){ pDb->zProgress = Tcl_Alloc( len + 1 ); strcpy(pDb->zProgress, zProgress); }else{ pDb->zProgress = 0; } #ifndef SQLITE_OMIT_PROGRESS_CALLBACK if( pDb->zProgress ){ pDb->interp = interp; sqlite3_progress_handler(pDb->db, N, DbProgressHandler, pDb); }else{ sqlite3_progress_handler(pDb->db, 0, 0, 0); } #endif }else{ Tcl_WrongNumArgs(interp, 2, objv, "N CALLBACK"); return TCL_ERROR; } break; } /* ** $db rekey KEY ** ** Change the encryption key on the currently open database. |
︙ | ︙ |
Changes to test/tclsqlite.test.
︙ | ︙ | |||
11 12 13 14 15 16 17 | # This file implements regression tests for TCL interface to the # SQLite library. # # Actually, all tests are based on the TCL interface, so the main # interface is pretty well tested. This file contains some addition # tests for fringe issues that the main test suite does not cover. # | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # This file implements regression tests for TCL interface to the # SQLite library. # # Actually, all tests are based on the TCL interface, so the main # interface is pretty well tested. This file contains some addition # tests for fringe issues that the main test suite does not cover. # # $Id: tclsqlite.test,v 1.31 2004/09/07 13:20:35 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Check the error messages generated by tclsqlite # if {[sqlite3 -has-codec]} { |
︙ | ︙ | |||
166 167 168 169 170 171 172 173 174 175 176 177 178 179 | set rc [catch {db onecolumn} errmsg] lappend rc $errmsg } {1 {wrong # args: should be "db onecolumn SQL"}} do_test tcl-3.4 { set rc [catch {db onecolumn {SELECT bogus}} errmsg] lappend rc $errmsg } {1 {no such column: bogus}} # Turn the busy handler on and off # do_test tcl-4.1 { proc busy_callback {cnt} { break } | > > > > > > > > > > > > > > > > > > | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | set rc [catch {db onecolumn} errmsg] lappend rc $errmsg } {1 {wrong # args: should be "db onecolumn SQL"}} do_test tcl-3.4 { set rc [catch {db onecolumn {SELECT bogus}} errmsg] lappend rc $errmsg } {1 {no such column: bogus}} do_test tcl-3.5 { set b 50 set rc [catch {db one {SELECT * FROM t1 WHERE b>$b}} msg] lappend rc $msg } {0 41} do_test tcl-3.6 { set b 500 set rc [catch {db one {SELECT * FROM t1 WHERE b>$b}} msg] lappend rc $msg } {0 {}} do_test tcl-3.7 { set b 500 set rc [catch {db one { INSERT INTO t1 VALUES(99,510); SELECT * FROM t1 WHERE b>$b }} msg] lappend rc $msg } {0 99} # Turn the busy handler on and off # do_test tcl-4.1 { proc busy_callback {cnt} { break } |
︙ | ︙ |