aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/attach.c3
-rw-r--r--src/btree.c5
-rw-r--r--src/btree.h3
-rw-r--r--src/shell.c11
-rw-r--r--src/sqlite.h.in26
-rw-r--r--src/tclsqlite.c9
6 files changed, 40 insertions, 17 deletions
diff --git a/src/attach.c b/src/attach.c
index 1679abf59..cd36936da 100644
--- a/src/attach.c
+++ b/src/attach.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
-** $Id: attach.c,v 1.23 2004/07/22 01:19:35 drh Exp $
+** $Id: attach.c,v 1.24 2004/07/22 02:40:38 drh Exp $
*/
#include "sqliteInt.h"
@@ -96,7 +96,6 @@ void sqlite3Attach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey)
extern int sqlite3CodecAttach(sqlite*, int, void*, int);
char *zKey = 0;
int nKey;
- sqlite3BtreeSetPageSize(aNew->pBt, -1, 4);
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
zKey = sqlite3NameFromToken(pKey);
nKey = strlen(zKey);
diff --git a/src/btree.c b/src/btree.c
index fcee69176..5790ddf78 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.178 2004/07/22 01:19:35 drh Exp $
+** $Id: btree.c,v 1.179 2004/07/22 02:40:38 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -1124,6 +1124,9 @@ int sqlite3BtreeSetPageSize(Btree *pBt, int pageSize, int nReserve){
int sqlite3BtreeGetPageSize(Btree *pBt){
return pBt->pageSize;
}
+int sqlite3BtreeGetReserve(Btree *pBt){
+ return pBt->pageSize - pBt->usableSize;
+}
/*
** Get a reference to pPage1 of the database file. This will
diff --git a/src/btree.h b/src/btree.h
index 19261b232..6b08c953c 100644
--- a/src/btree.h
+++ b/src/btree.h
@@ -13,7 +13,7 @@
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
**
-** @(#) $Id: btree.h,v 1.56 2004/07/22 01:19:35 drh Exp $
+** @(#) $Id: btree.h,v 1.57 2004/07/22 02:40:38 drh Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_
@@ -48,6 +48,7 @@ int sqlite3BtreeSetCacheSize(Btree*,int);
int sqlite3BtreeSetSafetyLevel(Btree*,int);
int sqlite3BtreeSetPageSize(Btree*,int,int);
int sqlite3BtreeGetPageSize(Btree*);
+int sqlite3BtreeGetReserve(Btree*);
int sqlite3BtreeBeginTrans(Btree*,int);
int sqlite3BtreeCommit(Btree*);
int sqlite3BtreeRollback(Btree*);
diff --git a/src/shell.c b/src/shell.c
index 953a994ba..164cb3650 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.106 2004/06/30 08:20:16 danielk1977 Exp $
+** $Id: shell.c,v 1.107 2004/07/22 02:40:38 drh Exp $
*/
#include <stdlib.h>
#include <string.h>
@@ -633,13 +633,10 @@ static void process_input(struct callback_data *p, FILE *in);
*/
static void open_db(struct callback_data *p){
if( p->db==0 ){
-#ifdef SQLITE_HAS_CODEC
- int n = p->zKey ? strlen(p->zKey) : 0;
- db = p->db = sqlite3_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg);
- assert(0); /* Encrypted databases are broken in SQLite 3 */
-#else
sqlite3_open(p->zDbFilename, &p->db);
db = p->db;
+#ifdef SQLITE_HAS_CODEC
+ sqlite3_key(p->db, p->zKey, p->zKey ? strlen(p->zKey) : 0);
#endif
sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
shellstaticFunc, 0, 0);
@@ -925,7 +922,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}else{
sqlite3_free(p->zKey);
p->zKey = sqlite3_mprintf("%s", azArg[2]);
- sqlite_rekey(p->db, p->zKey, strlen(p->zKey));
+ sqlite3_rekey(p->db, p->zKey, strlen(p->zKey));
}
}else
#endif
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 20c828904..632b5b7b2 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -12,7 +12,7 @@
** This header file defines the interface that the SQLite library
** presents to client programs.
**
-** @(#) $Id: sqlite.h.in,v 1.109 2004/07/21 15:21:36 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.110 2004/07/22 02:40:38 drh Exp $
*/
#ifndef _SQLITE_H_
#define _SQLITE_H_
@@ -1085,6 +1085,30 @@ int sqlite3_collation_needed16(
void(*)(void*,sqlite3*,int eTextRep,const void*)
);
+/*
+** Specify the key for an encrypted database. This routine should be
+** called right after sqlite3_open().
+**
+** The code to implement this API is not available in the public release
+** of SQLite.
+*/
+int sqlite3_key(
+ sqlite3 *db, /* Database to be rekeyed */
+ const void *pKey, int nKey /* The key */
+);
+
+/*
+** Change the key on an open database. If the current database is not
+** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
+** database is decrypted.
+**
+** The code to implement this API is not available in the public release
+** of SQLite.
+*/
+int sqlite3_rekey(
+ sqlite3 *db, /* Database to be rekeyed */
+ const void *pKey, int nKey /* The new key */
+);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index 7e9b463a0..b2953f9c3 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -11,7 +11,7 @@
*************************************************************************
** A TCL Interface to SQLite
**
-** $Id: tclsqlite.c,v 1.95 2004/06/30 12:42:59 danielk1977 Exp $
+** $Id: tclsqlite.c,v 1.96 2004/07/22 02:40:39 drh Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
@@ -878,7 +878,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
}
pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey);
#ifdef SQLITE_HAS_CODEC
- rc = sqlite_rekey(pDb->db, pKey, nKey);
+ rc = sqlite3_rekey(pDb->db, pKey, nKey);
if( rc ){
Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0);
rc = TCL_ERROR;
@@ -1048,15 +1048,14 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
}
memset(p, 0, sizeof(*p));
zFile = Tcl_GetStringFromObj(objv[2], 0);
-#ifdef SQLITE_HAS_CODEC
- p->db = sqlite3_open_encrypted(zFile, pKey, nKey, 0, &zErrMsg);
-#else
sqlite3_open(zFile, &p->db);
if( SQLITE_OK!=sqlite3_errcode(p->db) ){
zErrMsg = strdup(sqlite3_errmsg(p->db));
sqlite3_close(p->db);
p->db = 0;
}
+#ifdef SQLITE_HAS_CODEC
+ sqlite3_key(p->db, pKey, nKey);
#endif
if( p->db==0 ){
Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);