Skip to content

Commit

Permalink
:-) (CVS 37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Jun 2, 2000
1 parent 4962107 commit 1702ada
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 102 deletions.
32 changes: 31 additions & 1 deletion Makefile.in
Expand Up @@ -51,11 +51,41 @@ LIBOBJ = build.o dbbe.o delete.o expr.o insert.o \
main.o parse.o select.o tokenize.o update.o \
util.o vdbe.o where.o

# All of the source code files.
#
SRC = \
$(TOP)/src/build.c \
$(TOP)/src/dbbe.c \
$(TOP)/src/dbbe.h \
$(TOP)/src/delete.c \
$(TOP)/src/expr.c \
$(TOP)/src/insert.c \
$(TOP)/src/main.c \
$(TOP)/src/parse.y \
$(TOP)/src/select.c \
$(TOP)/src/shell.c \
$(TOP)/src/sqlite.h \
$(TOP)/src/sqliteInt.h \
$(TOP)/src/tclsqlite.c \
$(TOP)/src/tokenize.c \
$(TOP)/src/update.c \
$(TOP)/src/util.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/vdbe.h \
$(TOP)/src/where.c

# This is the default Makefile target. The objects listed here
# are what get build when you type just "make" with no arguments.
#
all: libsqlite.a sqlite.h sqlite

# Generate the file "last_change" which contains the date of change
# of the most recently modified source code file
#
last_change: $(SRC)
cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
| awk '{print $$5,$$6}' >last_change

libsqlite.a: $(LIBOBJ)
$(AR) libsqlite.a $(LIBOBJ)
$(RANLIB) libsqlite.a
Expand Down Expand Up @@ -153,7 +183,7 @@ sqlite.tar.gz:
all.tar.gz:
pwd=`pwd`; cd $(TOP)/..; tar czf $$pwd/all.tar.gz sqlite

index.html: $(TOP)/www/index.tcl sqlite.tar.gz all.tar.gz
index.html: $(TOP)/www/index.tcl sqlite.tar.gz all.tar.gz last_change
tclsh $(TOP)/www/index.tcl >index.html

sqlite.html: $(TOP)/www/sqlite.tcl
Expand Down
2 changes: 1 addition & 1 deletion README
@@ -1,6 +1,6 @@
This directory contains source code to

SQLite: An SQL Frontend To GDBM
SQLite: An SQL Database Built Upon GDBM

To compile the project, first create a directory in which to place
the build products. The build directory must be separate from the
Expand Down
27 changes: 18 additions & 9 deletions src/build.c
Expand Up @@ -22,9 +22,18 @@
**
*************************************************************************
** This file contains C code routines that are called by the parser
** when syntax rules are reduced.
** when syntax rules are reduced. The routines in this file handle
** the following kinds of rules:
**
** $Id: build.c,v 1.12 2000/06/02 01:17:37 drh Exp $
** CREATE TABLE
** DROP TABLE
** CREATE INDEX
** DROP INDEX
** creating expressions and ID lists
** COPY
** VACUUM
**
** $Id: build.c,v 1.13 2000/06/02 13:27:59 drh Exp $
*/
#include "sqliteInt.h"

Expand Down Expand Up @@ -529,15 +538,15 @@ void sqliteCreateIndex(
*/
if( pParse->initFlag==0 ){
static VdbeOp addTable[] = {
{ OP_Open, 0, 1, MASTER_NAME},
{ OP_New, 0, 0, 0},
{ OP_Open, 2, 1, MASTER_NAME},
{ OP_New, 2, 0, 0},
{ OP_String, 0, 0, "index"},
{ OP_String, 0, 0, 0}, /* 3 */
{ OP_String, 0, 0, 0}, /* 4 */
{ OP_String, 0, 0, 0}, /* 5 */
{ OP_MakeRecord, 4, 0, 0},
{ OP_Put, 0, 0, 0},
{ OP_Close, 0, 0, 0},
{ OP_Put, 2, 0, 0},
{ OP_Close, 2, 0, 0},
};
int n;
Vdbe *v = pParse->pVdbe;
Expand All @@ -548,6 +557,8 @@ void sqliteCreateIndex(
v = pParse->pVdbe = sqliteVdbeCreate(pParse->db->pBe);
}
if( v==0 ) goto exit_create_index;
sqliteVdbeAddOp(v, OP_Open, 0, 0, pTab->zName, 0);
sqliteVdbeAddOp(v, OP_Open, 1, 1, pIndex->zName, 0);
if( pStart && pEnd ){
int base;
n = (int)pEnd->z - (int)pStart->z + 1;
Expand All @@ -556,8 +567,6 @@ void sqliteCreateIndex(
sqliteVdbeChangeP3(v, base+4, pTab->zName, 0);
sqliteVdbeChangeP3(v, base+5, pStart->z, n);
}
sqliteVdbeAddOp(v, OP_Open, 0, 0, pTab->zName, 0);
sqliteVdbeAddOp(v, OP_Open, 1, 1, pIndex->zName, 0);
lbl1 = sqliteVdbeMakeLabel(v);
lbl2 = sqliteVdbeMakeLabel(v);
sqliteVdbeAddOp(v, OP_Next, 0, lbl2, 0, lbl1);
Expand All @@ -569,8 +578,8 @@ void sqliteCreateIndex(
sqliteVdbeAddOp(v, OP_PutIdx, 1, 0, 0, 0);
sqliteVdbeAddOp(v, OP_Goto, 0, lbl1, 0, 0);
sqliteVdbeAddOp(v, OP_Noop, 0, 0, 0, lbl2);
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
sqliteVdbeAddOp(v, OP_Close, 1, 0, 0, 0);
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
}

/* Reclaim memory on an EXPLAIN call.
Expand Down
59 changes: 45 additions & 14 deletions src/dbbe.c
Expand Up @@ -30,7 +30,7 @@
** relatively simple to convert to a different database such
** as NDBM, SDBM, or BerkeleyDB.
**
** $Id: dbbe.c,v 1.10 2000/06/02 02:09:23 drh Exp $
** $Id: dbbe.c,v 1.11 2000/06/02 13:27:59 drh Exp $
*/
#include "sqliteInt.h"
#include <gdbm.h>
Expand Down Expand Up @@ -124,9 +124,13 @@ static int rc4byte(struct rc4 *p){
}

/*
** This routine opens a new database. For the current driver scheme,
** the database name is the name of the directory
** This routine opens a new database. For the GDBM driver
** implemented here, the database name is the name of the directory
** containing all the files of the database.
**
** If successful, a pointer to the Dbbe structure is returned.
** If there are errors, an appropriate error message is left
** in *pzErrMsg and NULL is returned.
*/
Dbbe *sqliteDbbeOpen(
const char *zName, /* The name of the database */
Expand All @@ -142,7 +146,8 @@ Dbbe *sqliteDbbeOpen(
if( stat(zName, &statbuf)!=0 ){
if( createFlag ) mkdir(zName, 0750);
if( stat(zName, &statbuf)!=0 ){
sqliteSetString(pzErrMsg, "can't find or make directory \"",
sqliteSetString(pzErrMsg, createFlag ?
"can't find or create directory \"" : "can't find directory \"",
zName, "\"", 0);
return 0;
}
Expand Down Expand Up @@ -229,6 +234,9 @@ static char *sqliteFileOfTable(Dbbe *pBe, const char *zTable){

/*
** Generate a random filename with the given prefix.
**
** Very random names are chosen so that the chance of a
** collision with an existing filename is very very small.
*/
static void randomName(struct rc4 *pRc4, char *zBuf, char *zPrefix){
int i, j;
Expand All @@ -242,9 +250,28 @@ static void randomName(struct rc4 *pRc4, char *zBuf, char *zPrefix){
zBuf[j] = 0;
}


/*
** Open a new table cursor
** Open a new table cursor. Write a pointer to the corresponding
** DbbeTable structure into *ppTable. Return an integer success
** code:
**
** SQLITE_OK It worked!
**
** SQLITE_NOMEM sqliteMalloc() failed
**
** SQLITE_PERM Attempt to access a file for which file
** access permission is denied
**
** SQLITE_BUSY Another thread or process is already using
** the corresponding file and has that file locked.
**
** SQLITE_READONLY The current thread already has this file open
** readonly but you are trying to open for writing.
** (This can happen if a SELECT callback tries to
** do an UPDATE or DELETE.)
**
** If zTable is 0 or "", then a temporary table is created and opened.
** This table will be deleted from the disk when it is closed.
*/
int sqliteDbbeOpenTable(
Dbbe *pBe, /* The database the table belongs to */
Expand Down Expand Up @@ -335,7 +362,8 @@ int sqliteDbbeOpenTable(
}

/*
** Drop a table from the database.
** Drop a table from the database. The file on the disk that corresponds
** to this table is deleted.
*/
void sqliteDbbeDropTable(Dbbe *pBe, const char *zTable){
char *zFile; /* Name of the table file */
Expand All @@ -349,7 +377,6 @@ void sqliteDbbeDropTable(Dbbe *pBe, const char *zTable){
** Reorganize a table to reduce search times and disk usage.
*/
void sqliteDbbeReorganizeTable(Dbbe *pBe, const char *zTable){
char *zFile; /* Name of the table file */
DbbeTable *pTab;

if( sqliteDbbeOpenTable(pBe, zTable, 1, &pTab)!=SQLITE_OK ){
Expand Down Expand Up @@ -603,14 +630,18 @@ int sqliteDbbeDelete(DbbeTable *pTable, int nKey, char *pKey){
}

/*
** Open a temporary file.
** Open a temporary file. The file should be deleted when closed.
**
** Note that we can't use the old Unix trick of opening the file
** and then immediately unlinking the file. That works great
** under Unix, but fails when we try to port to Windows.
*/
int sqliteDbbeOpenTempFile(Dbbe *pBe, FILE **ppFile){
char *zFile;
char zBuf[50];
int i, j;
int limit;
int rc = SQLITE_OK;
char *zFile; /* Full name of the temporary file */
char zBuf[50]; /* Base name of the temporary file */
int i; /* Loop counter */
int limit; /* Prevent an infinite loop */
int rc = SQLITE_OK; /* Value returned by this function */

for(i=0; i<pBe->nTemp; i++){
if( pBe->apTemp[i]==0 ) break;
Expand Down
7 changes: 3 additions & 4 deletions src/expr.c
Expand Up @@ -23,7 +23,7 @@
*************************************************************************
** This file contains C code routines used for processing expressions
**
** $Id: expr.c,v 1.1 2000/05/31 15:34:53 drh Exp $
** $Id: expr.c,v 1.2 2000/06/02 13:27:59 drh Exp $
*/
#include "sqliteInt.h"

Expand Down Expand Up @@ -77,10 +77,9 @@ int sqliteExprResolveIds(Parse *pParse, IdList *pTabList, Expr *pExpr){

/* A table name and field name: ID.ID */
case TK_DOT: {
int cnt = 0; /* Number of matches */
int i; /* Loop counter */
int cnt = 0; /* Number of matches */
int i; /* Loop counter */
Expr *pLeft, *pRight; /* Left and right subbranches of the expr */
int n; /* Length of an identifier */
char *zLeft, *zRight; /* Text of an identifier */

pLeft = pExpr->pLeft;
Expand Down
14 changes: 8 additions & 6 deletions src/insert.c
Expand Up @@ -24,7 +24,7 @@
** This file contains C code routines that are called by the parser
** to handle INSERT statements.
**
** $Id: insert.c,v 1.2 2000/06/02 01:17:37 drh Exp $
** $Id: insert.c,v 1.3 2000/06/02 13:27:59 drh Exp $
*/
#include "sqliteInt.h"

Expand All @@ -43,7 +43,7 @@ void sqliteInsert(
){
Table *pTab;
char *zTab;
int i, j;
int i, j, idx;
Vdbe *v;

zTab = sqliteTableNameFromToken(pTableName);
Expand Down Expand Up @@ -105,6 +105,9 @@ void sqliteInsert(
if( v ){
Index *pIdx;
sqliteVdbeAddOp(v, OP_Open, 0, 1, pTab->zName, 0);
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
sqliteVdbeAddOp(v, OP_Open, idx, 1, pIdx->zName, 0);
}
sqliteVdbeAddOp(v, OP_New, 0, 0, 0, 0);
if( pTab->pIndex ){
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
Expand All @@ -126,11 +129,10 @@ void sqliteInsert(
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0, 0, 0);
sqliteVdbeAddOp(v, OP_Put, 0, 0, 0, 0);
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
if( pIdx->pNext ){
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
}
sqliteVdbeAddOp(v, OP_Open, 0, 1, pIdx->zName, 0);
for(i=0; i<pIdx->nField; i++){
int idx = pIdx->aiField[i];
if( pField==0 ){
Expand All @@ -147,8 +149,8 @@ void sqliteInsert(
}
}
sqliteVdbeAddOp(v, OP_MakeKey, pIdx->nField, 0, 0, 0);
sqliteVdbeAddOp(v, OP_PutIdx, 0, 0, 0, 0);
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
sqliteVdbeAddOp(v, OP_PutIdx, idx, 0, 0, 0);
sqliteVdbeAddOp(v, OP_Close, idx, 0, 0, 0);
}
}

Expand Down
21 changes: 19 additions & 2 deletions src/main.c
Expand Up @@ -26,7 +26,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.5 2000/06/02 01:51:20 drh Exp $
** $Id: main.c,v 1.6 2000/06/02 13:27:59 drh Exp $
*/
#include "sqliteInt.h"

Expand Down Expand Up @@ -54,6 +54,13 @@ static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
** Attempt to read the database schema and initialize internal
** data structures. Return one of the SQLITE_ error codes to
** indicate success or failure.
**
** After the database is initialized, the SQLITE_Initialized
** bit is set in the flags field of the sqlite structure. An
** attempt is made to initialize the database as soon as it
** is opened. If that fails (perhaps because another process
** has the sqlite_master table locked) than another attempt
** is made the first time the database is accessed.
*/
static int sqliteInit(sqlite *db, char **pzErrMsg){
Vdbe *vdbe;
Expand Down Expand Up @@ -177,6 +184,9 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
sqlite_close(db);
return 0;
}else{
sqliteFree(pzErrMsg);
*pzErrMsg = 0;
}
return db;
}
Expand Down Expand Up @@ -230,7 +240,14 @@ int sqlite_complete(const char *zSql){
}

/*
** Execute SQL code
** Execute SQL code. Return one of the SQLITE_ success/failure
** codes. Also write an error message into memory obtained from
** malloc() and make *pzErrMsg point to that message.
**
** If the SQL is a query, then for each row in the query result
** the xCallback() function is called. pArg becomes the first
** argument to xCallback(). If xCallback=NULL then no callback
** is invoked, even for queries.
*/
int sqlite_exec(
sqlite *db, /* The database on which the SQL executes */
Expand Down
5 changes: 2 additions & 3 deletions src/shell.c
Expand Up @@ -24,7 +24,7 @@
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
** $Id: shell.c,v 1.5 2000/05/31 23:33:17 drh Exp $
** $Id: shell.c,v 1.6 2000/06/02 13:27:59 drh Exp $
*/
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -53,7 +53,6 @@
static char *getline(char *zPrompt){
char *zLine;
int nLine;
char *z;
int n;
int eol;

Expand Down Expand Up @@ -433,7 +432,7 @@ int main(int argc, char **argv){
argc--;
argv++;
}else if( argc>=3 && strcmp(argv[0],"-separator")==0 ){
sprintf(data.separator,"%.*s",sizeof(data.separator)-1,argv[2]);
sprintf(data.separator,"%.*s",(int)sizeof(data.separator)-1,argv[2]);
argc -= 2;
argv += 2;
}else if( strcmp(argv[1],"-header")==0 ){
Expand Down

0 comments on commit 1702ada

Please sign in to comment.