/* * Copyright (C) 2007 Tildeslash Ltd. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation. * * There are special exceptions to the terms and conditions of the GPL * as it is applied to this software. View the full text of the exception * in the file EXCEPTIONS accompanying this software distribution. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Config.h" #include #include "Util.h" #include "Vector.h" #include "ResultSet.h" #include "PreparedStatement.h" /** * Implementation of the PreparedStatement interface * * @version \$Id: PreparedStatement.c,v 1.11 2007/02/11 11:18:55 hauk Exp $ * @file */ /* ----------------------------------------------------------- Definitions */ #define T PreparedStatement_T struct T { Pop_T op; ResultSet_T resultSet; IPreparedStatement_T I; }; /* ------------------------------------------------------------ Prototypes */ static void clearResultSet(T P); /* ----------------------------------------------------- Protected methods */ #ifdef PACKAGE_PROTECTED #pragma GCC visibility push(hidden) #endif T PreparedStatement_new(IPreparedStatement_T I, Pop_T op) { T P; assert(I); assert(op); NEW(P); P->I= I; P->op= op; return P; } void PreparedStatement_free(T *P) { assert(P && *P); clearResultSet((*P)); (*P)->op->free(&(*P)->I); FREE(*P); } #ifdef PACKAGE_PROTECTED #pragma GCC visibility pop #endif /* -------------------------------------------------------- Public methods */ int PreparedStatement_setString(T P, int parameterIndex, const char *x) { assert(P); if(P->op->setString(P->I, parameterIndex, x)) return TRUE; THROW(SQLException); return FALSE; } int PreparedStatement_setInt(T P, int parameterIndex, int x) { assert(P); if(P->op->setInt(P->I, parameterIndex, x)) return TRUE; THROW(SQLException); return FALSE; } int PreparedStatement_setLLong(T P, int parameterIndex, long long int x) { assert(P); if(P->op->setLLong(P->I, parameterIndex, x)) return TRUE; THROW(SQLException); return FALSE; } int PreparedStatement_setDouble(T P, int parameterIndex, double x) { assert(P); if(P->op->setDouble(P->I, parameterIndex, x)) return TRUE; THROW(SQLException); return FALSE; } int PreparedStatement_setBlob(T P, int parameterIndex, const void *x, int size) { assert(P); if(P->op->setBlob(P->I, parameterIndex, x, size)) return TRUE; THROW(SQLException); return FALSE; } int PreparedStatement_execute(T P) { assert(P); clearResultSet(P); if(P->op->execute(P->I)) return TRUE; THROW(SQLException); return FALSE; } ResultSet_T PreparedStatement_executeQuery(T P) { assert(P); clearResultSet(P); P->resultSet= P->op->executeQuery(P->I); if(! P->resultSet) THROW(SQLException); return P->resultSet; } /* ------------------------------------------------------- Private methods */ static void clearResultSet(T P) { if(P->resultSet) ResultSet_free(&P->resultSet); }