#pragma ident "%Z%%M% %I% %E% SMI"
/*
** 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.
**
*************************************************************************
** Code for testing the btree.c module in SQLite. This code
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test3.c,v 1.23 2003/04/13 18:26:52 paul Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
#include "btree.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
/*
** Interpret an SQLite error number
*/
char *zName;
switch( rc ){
default: zName = "SQLITE_Unknown"; break;
}
return zName;
}
/*
** Usage: btree_open FILENAME
**
** Open a new database
*/
static int btree_open(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
if( argc!=2 ){
" FILENAME\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
}
return TCL_OK;
}
/*
** Usage: btree_close ID
**
** Close the given database.
*/
static int btree_close(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_begin_transaction ID
**
** Start a new transaction
*/
static int btree_begin_transaction(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_rollback ID
**
** Rollback changes
*/
static int btree_rollback(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_commit ID
**
** Commit all changes
*/
static int btree_commit(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_create_table ID
**
** Create a new table in the database
*/
static int btree_create_table(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_drop_table ID TABLENUM
**
** Delete an entire table from the database
*/
static int btree_drop_table(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int iTable;
int rc;
if( argc!=3 ){
" ID TABLENUM\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_clear_table ID TABLENUM
**
** Remove all entries from the given table but keep the table around.
*/
static int btree_clear_table(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int iTable;
int rc;
if( argc!=3 ){
" ID TABLENUM\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_get_meta ID
**
** Return meta data
*/
static int btree_get_meta(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int i;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
for(i=0; i<SQLITE_N_BTREE_META; i++){
}
return TCL_OK;
}
/*
** Usage: btree_update_meta ID METADATA...
**
** Return meta data
*/
static int btree_update_meta(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int i;
return TCL_ERROR;
}
for(i=0; i<SQLITE_N_BTREE_META; i++){
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_page_dump ID PAGENUM
**
** Print a disassembly of a page on standard output
*/
static int btree_page_dump(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int iPage;
int rc;
if( argc!=3 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_tree_dump ID PAGENUM
**
** Print a disassembly of a page and all its child pages on standard output
*/
static int btree_tree_dump(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int iPage;
int rc;
if( argc!=3 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_pager_stats ID
**
** Returns pager statistics
*/
static int btree_pager_stats(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
int *a;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
for(i=0; i<9; i++){
static char *zName[] = {
"ref", "page", "max", "size", "state", "err",
"hit", "miss", "ovfl",
};
}
return TCL_OK;
}
/*
** Usage: btree_pager_ref_dump ID
**
** Print out all outstanding pages.
*/
static int btree_pager_ref_dump(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: btree_integrity_check ID ROOT ...
**
** Look through every page of the given BTree file to verify correct
** formatting and linkage. Return a line of text for each problem found.
** Return an empty string if everything worked.
*/
static int btree_integrity_check(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
char *zResult;
int nRoot;
int *aRoot;
int i;
if( argc<3 ){
" ID ROOT ...\"", 0);
return TCL_ERROR;
}
for(i=0; i<argc-2; i++){
}
if( zResult ){
}
return TCL_OK;
}
/*
** Usage: btree_cursor ID TABLENUM WRITEABLE
**
** Create a new cursor. Return the ID for the cursor.
*/
static int btree_cursor(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int iTable;
int rc;
int wrFlag;
if( argc!=4 ){
" ID TABLENUM WRITEABLE\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_close_cursor ID
**
** Close a cursor opened using btree_cursor.
*/
static int btree_close_cursor(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_move_to ID KEY
**
** Move the cursor to the entry with the given key.
*/
static int btree_move_to(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int res;
if( argc!=3 ){
" ID KEY\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_delete ID
**
** Delete the entry that the cursor is pointing to
*/
static int btree_delete(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_insert ID KEY DATA
**
** Create a new entry with the given key and data. If an entry already
** exists with the same key the old entry is overwritten.
*/
static int btree_insert(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
if( argc!=4 ){
" ID KEY DATA\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_next ID
**
** Move the cursor to the next entry in the table. Return 0 on success
** or 1 if the cursor was already on the last entry in the table or if
** the table is empty.
*/
static int btree_next(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int res = 0;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_prev ID
**
** Move the cursor to the previous entry in the table. Return 0 on
** success and 1 if the cursor was already on the first entry in
** the table or if the table was empty.
*/
static int btree_prev(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int res = 0;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_first ID
**
** Move the cursor to the first entry in the table. Return 0 if the
** cursor was left point to something and 1 if the table is empty.
*/
static int btree_first(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int res = 0;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_last ID
**
** Move the cursor to the last entry in the table. Return 0 if the
** cursor was left point to something and 1 if the table is empty.
*/
static int btree_last(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int res = 0;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_key ID
**
** Return the key for the entry at which the cursor is pointing.
*/
static int btree_key(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int n;
char *zBuf;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
sqliteBtreeKeySize(pCur, &n);
if( rc!=n ){
return TCL_ERROR;
}
zBuf[n] = 0;
return SQLITE_OK;
}
/*
** Usage: btree_data ID
**
** Return the data for the entry at which the cursor is pointing.
*/
static int btree_data(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int n;
char *zBuf;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
sqliteBtreeDataSize(pCur, &n);
if( rc!=n ){
return TCL_ERROR;
}
zBuf[n] = 0;
return SQLITE_OK;
}
/*
** Usage: btree_payload_size ID
**
** Return the number of bytes of payload
*/
static int btree_payload_size(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
return SQLITE_OK;
}
/*
** Usage: btree_cursor_dump ID
**
** Return eight integers containing information about the entry the
** cursor is pointing to:
**
** aResult[0] = The page number
** aResult[1] = The entry number
** aResult[2] = Total number of entries on this page
** aResult[3] = Size of this entry
** aResult[4] = Number of free bytes on this page
** aResult[5] = Number of free blocks on the page
** aResult[6] = Page number of the left child of this entry
** aResult[7] = Page number of the right child for the whole page
*/
static int btree_cursor_dump(
void *NotUsed,
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int i, j;
if( argc!=2 ){
" ID\"", 0);
return TCL_ERROR;
}
if( rc ){
return TCL_ERROR;
}
j = 0;
}
return SQLITE_OK;
}
/*
** Register commands with the TCL interpreter.
*/
static struct {
char *zName;
} aCmd[] = {
};
int i;
}
return TCL_OK;
}