aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/printf.c32
-rw-r--r--src/select.c18
-rw-r--r--src/shell.c38
-rw-r--r--src/tclsqlite.c18
-rw-r--r--src/test1.c8
-rw-r--r--src/threadtest.c10
6 files changed, 49 insertions, 75 deletions
diff --git a/src/printf.c b/src/printf.c
index 827b7bbcb..e1ae39df7 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -699,14 +699,10 @@ char *sqlite_mprintf(const char *zFormat, ...){
vxprintf(mout,&sMprintf,zFormat,ap);
va_end(ap);
sMprintf.zText[sMprintf.nChar] = 0;
- if( sMprintf.zText==sMprintf.zBase ){
- zNew = sqliteMalloc( sMprintf.nChar+1 );
- if( zNew ) strcpy(zNew,zBuf);
- }else{
- zNew = sqliteRealloc(sMprintf.zText,sMprintf.nChar+1);
- if( zNew==0 ){
- sqliteFree(sMprintf.zText);
- }
+ zNew = malloc( sMprintf.nChar+1 );
+ if( zNew ) strcpy(zNew,sMprintf.zText);
+ if( sMprintf.zText!=sMprintf.zBase ){
+ sqliteFree(sMprintf.zText);
}
return zNew;
}
@@ -715,6 +711,7 @@ char *sqlite_mprintf(const char *zFormat, ...){
*/
char *sqlite_vmprintf(const char *zFormat, va_list ap){
struct sgMprintf sMprintf;
+ char *zNew;
char zBuf[200];
sMprintf.nChar = 0;
sMprintf.zText = zBuf;
@@ -722,17 +719,12 @@ char *sqlite_vmprintf(const char *zFormat, va_list ap){
sMprintf.zBase = zBuf;
vxprintf(mout,&sMprintf,zFormat,ap);
sMprintf.zText[sMprintf.nChar] = 0;
- if( sMprintf.zText==sMprintf.zBase ){
- sMprintf.zText = sqliteMalloc( strlen(zBuf)+1 );
- if( sMprintf.zText ) strcpy(sMprintf.zText,zBuf);
- }else{
- char *z = sqliteRealloc(sMprintf.zText,sMprintf.nChar+1);
- if( z==0 ){
- sqliteFree(sMprintf.zText);
- }
- sMprintf.zText = z;
+ zNew = malloc( sMprintf.nChar+1 );
+ if( zNew ) strcpy(zNew,sMprintf.zText);
+ if( sMprintf.zText!=sMprintf.zBase ){
+ sqliteFree(sMprintf.zText);
}
- return sMprintf.zText;
+ return zNew;
}
/*
@@ -772,7 +764,7 @@ int sqlite_exec_vprintf(
zSql = sqlite_vmprintf(sqlFormat, ap);
rc = sqlite_exec(db, zSql, xCallback, pArg, errmsg);
- sqliteFree(zSql);
+ free(zSql);
return rc;
}
int sqlite_get_table_printf(
@@ -806,6 +798,6 @@ int sqlite_get_table_vprintf(
zSql = sqlite_vmprintf(sqlFormat, ap);
rc = sqlite_get_table(db, zSql, resultp, nrow, ncolumn, errmsg);
- sqliteFree(zSql);
+ free(zSql);
return rc;
}
diff --git a/src/select.c b/src/select.c
index 882e8885c..73c1f6a3d 100644
--- a/src/select.c
+++ b/src/select.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.103 2002/07/05 21:42:37 drh Exp $
+** $Id: select.c,v 1.104 2002/07/10 21:26:01 drh Exp $
*/
#include "sqliteInt.h"
@@ -626,11 +626,7 @@ static void generateColumnNames(
p = pEList->a[i].pExpr;
if( p==0 ) continue;
showFullNames = (pParse->db->flags & SQLITE_FullColNames)!=0;
- if( p->span.z && p->span.z[0] && !showFullNames ){
- int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, 0);
- sqliteVdbeChangeP3(v, -1, p->span.z, p->span.n);
- sqliteVdbeCompressSpace(v, addr);
- }else if( p->op==TK_COLUMN && pTabList ){
+ if( p->op==TK_COLUMN && pTabList ){
Table *pTab = pTabList->a[p->iTable - base].pTab;
char *zCol;
int iCol = p->iColumn;
@@ -643,7 +639,11 @@ static void generateColumnNames(
zCol = pTab->aCol[iCol].zName;
zType = pTab->aCol[iCol].zType;
}
- if( pTabList->nSrc>1 || showFullNames ){
+ if( p->span.z && p->span.z[0] && !showFullNames ){
+ int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, 0);
+ sqliteVdbeChangeP3(v, -1, p->span.z, p->span.n);
+ sqliteVdbeCompressSpace(v, addr);
+ }else if( pTabList->nSrc>1 || showFullNames ){
char *zName = 0;
char *zTab;
@@ -657,6 +657,10 @@ static void generateColumnNames(
sqliteVdbeAddOp(v, OP_ColumnName, i, 0);
sqliteVdbeChangeP3(v, -1, zCol, 0);
}
+ }else if( p->span.z && p->span.z[0] && !showFullNames ){
+ int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, 0);
+ sqliteVdbeChangeP3(v, -1, p->span.z, p->span.n);
+ sqliteVdbeCompressSpace(v, addr);
}else if( p->span.z && p->span.z[0] ){
int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, 0);
sqliteVdbeChangeP3(v, -1, p->span.z, p->span.n);
diff --git a/src/shell.c b/src/shell.c
index a3c94bf67..ef31ceeaa 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -12,7 +12,7 @@
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
-** $Id: shell.c,v 1.59 2002/06/25 19:31:18 drh Exp $
+** $Id: shell.c,v 1.60 2002/07/10 21:26:01 drh Exp $
*/
#include <stdlib.h>
#include <string.h>
@@ -492,8 +492,6 @@ static char zHelp[] =
".prompt MAIN CONTINUE Replace the standard prompts\n"
".quit Exit this program\n"
".read FILENAME Execute SQL in FILENAME\n"
- ".reindex ?TABLE? Rebuild indices\n"
-/* ".rename OLD NEW Change the name of a table or index\n" */
".schema ?TABLE? Show the CREATE statements\n"
".separator STRING Change separator string for \"list\" mode\n"
".show Show the current values for various settings\n"
@@ -754,40 +752,6 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
}
}else
- if( c=='r' && strncmp(azArg[0], "reindex", n)==0 ){
- char **azResult;
- int nRow, rc;
- char *zErrMsg;
- int i;
- char *zSql;
- if( nArg==1 ){
- rc = sqlite_get_table(db,
- "SELECT name, sql FROM sqlite_master "
- "WHERE type='index'",
- &azResult, &nRow, 0, &zErrMsg
- );
- }else{
- rc = sqlite_get_table_printf(db,
- "SELECT name, sql FROM sqlite_master "
- "WHERE type='index' AND tbl_name LIKE '%q'",
- &azResult, &nRow, 0, &zErrMsg, azArg[1]
- );
- }
- for(i=1; rc==SQLITE_OK && i<=nRow; i++){
- extern char *sqlite_mprintf(const char *, ...);
- zSql = sqlite_mprintf(
- "DROP INDEX '%q';\n%s;\nVACUUM '%q';",
- azResult[i*2], azResult[i*2+1], azResult[i*2]);
- if( p->echoOn ) printf("%s\n", zSql);
- rc = sqlite_exec(db, zSql, 0, 0, &zErrMsg);
- }
- sqlite_free_table(azResult);
- if( zErrMsg ){
- fprintf(stderr,"Error: %s\n", zErrMsg);
- free(zErrMsg);
- }
- }else
-
if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
struct callback_data data;
char *zErrMsg = 0;
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index fecc6ab58..b8e2a5ee3 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -11,7 +11,7 @@
*************************************************************************
** A TCL Interface to SQLite
**
-** $Id: tclsqlite.c,v 1.36 2002/07/07 17:12:36 drh Exp $
+** $Id: tclsqlite.c,v 1.37 2002/07/10 21:26:01 drh Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
@@ -93,9 +93,20 @@ static int DbEvalCallback(
return 1;
}
if( cbData->zArray[0] ){
+ Tcl_DString dType;
+ Tcl_DStringInit(&dType);
Tcl_SetVar2(cbData->interp, cbData->zArray, "*",
Tcl_DStringValue(&dCol), TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
+ Tcl_DStringAppend(&dType, "typeof:", -1);
+ Tcl_DStringAppend(&dType, Tcl_DStringValue(&dCol), -1);
+ Tcl_DStringFree(&dCol);
+ Tcl_ExternalToUtfDString(NULL, azN[i+argc+1], -1, &dCol);
+ Tcl_SetVar2(cbData->interp, cbData->zArray,
+ Tcl_DStringValue(&dType), Tcl_DStringValue(&dCol),
+ TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
+ Tcl_DStringFree(&dType);
}
+
Tcl_DStringFree(&dCol);
}
}
@@ -152,8 +163,13 @@ static int DbEvalCallback(
if( azCol==0 || (cbData->once && cbData->zArray[0]) ){
Tcl_SetVar2(cbData->interp, cbData->zArray, "*", "", 0);
for(i=0; i<nCol; i++){
+ char *z;
Tcl_SetVar2(cbData->interp, cbData->zArray, "*", azN[i],
TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
+ z = sqlite_mprintf("typeof:%s", azN[i]);
+ Tcl_SetVar2(cbData->interp, cbData->zArray, z, azN[i+nCol+1],
+ TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
+ sqlite_freemem(z);
}
cbData->once = 0;
}
diff --git a/src/test1.c b/src/test1.c
index 771b26d61..6bb76a7ee 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test1.c,v 1.11 2002/07/01 00:31:36 drh Exp $
+** $Id: test1.c,v 1.12 2002/07/10 21:26:01 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -331,7 +331,7 @@ static int sqlite_mprintf_int(
}
z = sqlite_mprintf(argv[1], a[0], a[1], a[2]);
Tcl_AppendResult(interp, z, 0);
- sqliteFree(z);
+ sqlite_freemem(z);
return TCL_OK;
}
@@ -358,7 +358,7 @@ static int sqlite_mprintf_str(
}
z = sqlite_mprintf(argv[1], a[0], a[1], argc>4 ? argv[4] : NULL);
Tcl_AppendResult(interp, z, 0);
- sqliteFree(z);
+ sqlite_freemem(z);
return TCL_OK;
}
@@ -387,7 +387,7 @@ static int sqlite_mprintf_double(
if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR;
z = sqlite_mprintf(argv[1], a[0], a[1], r);
Tcl_AppendResult(interp, z, 0);
- sqliteFree(z);
+ sqlite_freemem(z);
return TCL_OK;
}
diff --git a/src/threadtest.c b/src/threadtest.c
index 7255ba919..b85f7d6ab 100644
--- a/src/threadtest.c
+++ b/src/threadtest.c
@@ -25,8 +25,6 @@
#include <string.h>
#include <unistd.h>
-#define sqliteFree(X) sqliteFree_(X,__FILE__,__LINE__)
-
/*
** Come here to die.
*/
@@ -100,7 +98,7 @@ char **db_query(sqlite *db, const char *zFile, const char *zFormat, ...){
free(zSql);
Exit(1);
}
- sqliteFree(zSql);
+ sqlite_freemem(zSql);
if( sResult.azElem==0 ){
db_query_callback(&sResult, 0, 0, 0);
}
@@ -123,10 +121,10 @@ void db_execute(sqlite *db, const char *zFile, const char *zFormat, ...){
if( zErrMsg ){
fprintf(stderr,"%s: command failed: %s - %s\n", zFile, zSql, zErrMsg);
free(zErrMsg);
- sqliteFree(zSql);
+ sqlite_freemem(zSql);
Exit(1);
}
- sqliteFree(zSql);
+ sqlite_freemem(zSql);
}
/*
@@ -135,7 +133,7 @@ void db_execute(sqlite *db, const char *zFile, const char *zFormat, ...){
void db_query_free(char **az){
int i;
for(i=0; az[i]; i++){
- sqliteFree(az[i]);
+ sqlite_freemem(az[i]);
}
free(az);
}