From: Stephen D. <sd...@us...> - 2005-10-20 23:38:28
|
Update of /cvsroot/naviserver/naviserver/nsdbtest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28406/nsdbtest Added Files: Makefile nsdbtest.c Log Message: * Makefile: * nsdbtest/Makefile: * nsdbtest/nsdbtest.c: * tests/test.nscfg: * tests/nsdb.test: Implement a simple nsdb driver for testing and add the beginnings of some tests. --- NEW FILE: nsdbtest.c --- /* * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://mozilla.org/. * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * Copyright (C) 2005 Stephen Deasey. * * Alternatively, the contents of this file may be used under the terms * of the GNU General Public License (the "GPL"), in which case the * provisions of GPL are applicable instead of those above. If you wish * to allow use of your version of this file only under the terms of the * GPL and not to allow others to use your version of this file under the * License, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the GPL. * If you do not delete the provisions above, a recipient may use your * version of this file under either the License or the GPL. * */ /* * nsdbtest.c -- * * Implements a stub nsdb driver for testing. */ #include "../nsdb/nsdb.h" NS_RCSID("$Header: /cvsroot/naviserver/naviserver/nsdbtest/nsdbtest.c,v 1.1 2005/10/20 23:38:15 sdeasey Exp $"); NS_EXPORT int Ns_ModuleVersion = 1; /* * Local functions defined in this file. */ static char *DbType(Ns_DbHandle *handle); static int OpenDb(Ns_DbHandle *handle); static int CloseDb(Ns_DbHandle *handle); static Ns_Set *BindRow(Ns_DbHandle *handle); static int Exec(Ns_DbHandle *handle, char *sql); static int GetRow(Ns_DbHandle *handle, Ns_Set *row); static int Flush(Ns_DbHandle *handle); static int ResetHandle(Ns_DbHandle *handle); static void SetTransactionState(Ns_DbHandle *handle, char *sql); /* * Local variables defined in this file. */ static Ns_DbProc procs[] = { {DbFn_DbType, DbType}, {DbFn_Name, DbType}, {DbFn_OpenDb, OpenDb}, {DbFn_CloseDb, CloseDb}, {DbFn_BindRow, BindRow}, {DbFn_Exec, Exec}, {DbFn_GetRow, GetRow}, {DbFn_Flush, Flush}, {DbFn_Cancel, Flush}, {DbFn_ResetHandle, ResetHandle}, {0, NULL} }; static char *dbName = "nsdbtest"; /* *---------------------------------------------------------------------- * * Ns_DbDriverInit -- * * Register driver functions. * * Results: * NS_OK or NS_ERROR. * * Side effects: * None. * *---------------------------------------------------------------------- */ NS_EXPORT int Ns_DbDriverInit(char *driver, char *configPath) { return Ns_DbRegisterDriver(driver, &procs[0]); } /* *---------------------------------------------------------------------- * * DbType -- * * Return a string which identifies the driver type and name. * * Results: * Database type/name. * * Side effects: * None. * *---------------------------------------------------------------------- */ static char * DbType(Ns_DbHandle *handle) { return dbName; } /* *---------------------------------------------------------------------- * * OpenDb -- * * Open a connection. * * Results: * NS_OK or NS_ERROR. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int OpenDb(Ns_DbHandle *handle) { return NS_OK; } /* *---------------------------------------------------------------------- * * CloseDb -- * * Close an open connection. * * Results: * NS_OK or NS_ERROR. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int CloseDb(Ns_DbHandle *handle) { return NS_OK; } /* *---------------------------------------------------------------------- * * BindRow -- * * Retrieve the column names of the current result. * * Results: * An Ns_Set whos keys are the names of columns, or NULL on error. * * Side effects: * None. * *---------------------------------------------------------------------- */ static Ns_Set * BindRow(Ns_DbHandle *handle) { Ns_SetPut(handle->row, "column1", NULL); handle->fetchingRows = NS_FALSE; return handle->row; } /* *---------------------------------------------------------------------- * * Exec -- * * Execute an SQL statement. * * Results: * NS_ROWS, NS_DML or NS_ERROR. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int Exec(Ns_DbHandle *handle, char *sql) { if (handle->verbose) { Ns_Log(Notice, "nsdbtest(%s): Querying '%s'", handle->driver, sql); } if (STRIEQ(sql, "rows")) { return NS_ROWS; } else if (STRIEQ(sql, "dml")) { return NS_DML; } return NS_ERROR; } /* *---------------------------------------------------------------------- * * GetRow -- * * Fill in the given Ns_Set with values for each column of the * current row. * * Results: * NS_OK, NS_END_DATA or NS_ERROR. * * Side effects: * Current tupple updated. * *---------------------------------------------------------------------- */ static int GetRow(Ns_DbHandle *handle, Ns_Set *row) { Ns_SetPutValue(row, 0, "ok"); return NS_END_DATA; } /* *---------------------------------------------------------------------- * * Flush -- * * Flush unfetched rows. * * Results: * NS_OK or NS_ERROR. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int Flush(Ns_DbHandle *handle) { return NS_OK; } /* *---------------------------------------------------------------------- * * ResetHandle -- * * Reset connection ready for next command. * * Results: * NS_OK or NS_ERROR. * * Side effects: * Any active transaction will be rolled back. * *---------------------------------------------------------------------- */ static int ResetHandle(Ns_DbHandle *handle) { return NS_OK; } --- NEW FILE: Makefile --- # # # $Header: /cvsroot/naviserver/naviserver/nsdbtest/Makefile,v 1.1 2005/10/20 23:38:15 sdeasey Exp $ # MOD = nsdbtest.so OBJS = nsdbtest.o include ../include/Makefile.build |