/*- * Copyright 2005-2007 Guram Dukashvili * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ //--------------------------------------------------------------------------- #include //--------------------------------------------------------------------------- namespace adicpp { //--------------------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////// //--------------------------------------------------------------------------- FirebirdDatabase::~FirebirdDatabase() { } //--------------------------------------------------------------------------- FirebirdDatabase::FirebirdDatabase() { static_cast(this)->attach(*this); } //--------------------------------------------------------------------------- void FirebirdDatabase::exceptionHandler(ksys::Exception * e) { static_cast(this)->staticExceptionHandler(e); } //--------------------------------------------------------------------------- Statement * FirebirdDatabase::newStatement() { return newObject(); } //--------------------------------------------------------------------------- Statement * FirebirdDatabase::newAttachedStatement() { ksys::AutoPtr p(newObject()); p->attach(*this); return p.ptr(NULL); } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::create() { static_cast(this)->create(); return this; } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::drop() { static_cast(this)->drop(); return this; } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::attach() { static_cast(this)->attach(); return this; } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::detach() { static_cast(this)->detach(); return this; } //--------------------------------------------------------------------------- bool FirebirdDatabase::attached() { return static_cast(this)->attached(); } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::isolation(const utf8::String & isolation) { static_cast(this)->isolation(isolation); return this; } //--------------------------------------------------------------------------- utf8::String FirebirdDatabase::isolation() { return static_cast(this)->isolation(); } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::start() { static_cast(this)->start(); return this; } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::rollback() { static_cast(this)->rollback(); return this; } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::commit() { static_cast(this)->commit(); return this; } //--------------------------------------------------------------------------- bool FirebirdDatabase::active() { return static_cast(this)->active(); } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::clearParams() { static_cast(this)->params().clear(); return this; } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::addParam(const utf8::String & name, const ksys::Mutant & value) { static_cast(this)->params().add(name, value); return this; } //--------------------------------------------------------------------------- FirebirdDatabase * FirebirdDatabase::name(const utf8::String & name) { static_cast(this)->name(name); return this; } //--------------------------------------------------------------------------- bool FirebirdDatabase::separateDBName(const utf8::String & name, utf8::String & hostName, utf8::String & dbName, uintptr_t & port) { return static_cast(this)->separateDBName(name, hostName, dbName, port); } //--------------------------------------------------------------------------- utf8::String FirebirdDatabase::name() { return static_cast(this)->name(); } //--------------------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////// //--------------------------------------------------------------------------- FirebirdStatement::~FirebirdStatement() { } //--------------------------------------------------------------------------- FirebirdStatement::FirebirdStatement() { } //--------------------------------------------------------------------------- Database * FirebirdStatement::database() { return dynamic_cast(static_cast(this)->database()); } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::attach(Database & database) { FirebirdDatabase * p = dynamic_cast(&database); if( p == NULL ) newObjectV1C2(EINVAL,__PRETTY_FUNCTION__)->throwSP(); static_cast(this)->attach(*p,*p); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::detach() { static_cast(this)->detach(); return this; } //--------------------------------------------------------------------------- bool FirebirdStatement::attached() { return static_cast(this)->attached(); } //--------------------------------------------------------------------------- bool FirebirdStatement::prepared() { return static_cast(this)->prepared(); } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::prepare() { static_cast(this)->prepare(); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::unprepare() { static_cast(this)->unprepare(); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::execute() { static_cast(this)->execute(); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::execute(const utf8::String & sqlTextImm) { static_cast(this)->execute(sqlTextImm); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::text(const utf8::String & sqlText) { static_cast(this)->sqlText(sqlText); return this; } //--------------------------------------------------------------------------- utf8::String FirebirdStatement::text() { return static_cast(this)->sqlText(); } //--------------------------------------------------------------------------- uintptr_t FirebirdStatement::paramCount() { return static_cast(this)->params().count(); } //--------------------------------------------------------------------------- intptr_t FirebirdStatement::paramIndex(const utf8::String & name,bool noThrow) { intptr_t i = static_cast(this)->params().paramIndex(name); if( i < 0 && !noThrow ) newObjectV1C2(EINVAL,"invalid param name: " + name + ", " + __PRETTY_FUNCTION__)->throwSP(); return i; } //--------------------------------------------------------------------------- utf8::String FirebirdStatement::paramName(uintptr_t i) { return static_cast(this)->params().paramName(i); } //--------------------------------------------------------------------------- ksys::Mutant FirebirdStatement::paramAsMutant(uintptr_t i) { return static_cast(this)->paramAsMutant(i); } //--------------------------------------------------------------------------- ksys::Mutant FirebirdStatement::paramAsMutant(const utf8::String & name) { return static_cast(this)->paramAsMutant(name); } //--------------------------------------------------------------------------- utf8::String FirebirdStatement::paramAsString(uintptr_t i) { return static_cast(this)->paramAsString(i); } //--------------------------------------------------------------------------- utf8::String FirebirdStatement::paramAsString(const utf8::String & name) { return static_cast(this)->paramAsString(name); } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::paramAsMutant(uintptr_t i, const ksys::Mutant & value) { static_cast(this)->paramAsMutant(i, value); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::paramAsMutant(const utf8::String & name, const ksys::Mutant & value) { static_cast(this)->paramAsMutant(name, value); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::paramAsString(uintptr_t i, const utf8::String & value) { static_cast(this)->paramAsString(i, value); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::paramAsString(const utf8::String & name, const utf8::String & value) { static_cast(this)->paramAsString(name, value); return this; } //--------------------------------------------------------------------------- bool FirebirdStatement::fetch() { return static_cast(this)->values().fetch(); } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::fetchAll() { static_cast(this)->values().fetchAll(); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::selectRow(uintptr_t i) { static_cast(this)->values().selectRow(i); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::selectFirstRow() { static_cast(this)->values().selectFirst(); return this; } //--------------------------------------------------------------------------- FirebirdStatement * FirebirdStatement::selectLastRow() { static_cast(this)->values().selectLast(); return this; } //--------------------------------------------------------------------------- uintptr_t FirebirdStatement::rowCount() { return static_cast(this)->values().rowCount(); } //--------------------------------------------------------------------------- intptr_t FirebirdStatement::rowIndex() { return static_cast(this)->values().rowIndex(); } //--------------------------------------------------------------------------- ksys::Mutant FirebirdStatement::valueAsMutant(uintptr_t i) { return static_cast(this)->valueAsMutant(i); } //--------------------------------------------------------------------------- ksys::Mutant FirebirdStatement::valueAsMutant(const utf8::String & name) { return static_cast(this)->valueAsMutant(name); } //--------------------------------------------------------------------------- utf8::String FirebirdStatement::valueAsString(uintptr_t i) { return static_cast(this)->valueAsString(i); } //--------------------------------------------------------------------------- utf8::String FirebirdStatement::valueAsString(const utf8::String & name) { return static_cast(this)->valueAsString(name); } //--------------------------------------------------------------------------- bool FirebirdStatement::valueIsNull(uintptr_t i) { return static_cast(this)->values().isNull(i); } //--------------------------------------------------------------------------- bool FirebirdStatement::valueIsNull(const utf8::String & name) { return static_cast(this)->values().isNull(name); } //--------------------------------------------------------------------------- FieldType FirebirdStatement::fieldType(uintptr_t i) { i = static_cast(this)->values().checkValueIndex(i); i = static_cast(this)->values().sqlda().sqlda()->sqlvar[i].sqltype & ~1; switch( i ){ case SQL_VARYING : case SQL_TEXT : return ftString; case SQL_SHORT : return ftShort; case SQL_LONG : return ftInt; case SQL_FB_FLOAT : return ftFloat; case SQL_FB_DOUBLE : case SQL_D_FLOAT : return ftDouble; case SQL_FB_TYPE_TIME : case SQL_FB_TYPE_DATE : case SQL_FB_TIMESTAMP : return ftTime; case SQL_QUAD : case SQL_INT64 : return ftLong; case SQL_BLOB : return ftBlob; case SQL_ARRAY : break; } return ftUnknown; } //--------------------------------------------------------------------------- uintptr_t FirebirdStatement::fieldCount() { return static_cast(this)->values().count(); } //--------------------------------------------------------------------------- FieldType FirebirdStatement::fieldType(const utf8::String & name) { return fieldType(static_cast(this)->values().indexOfName(name)); } //--------------------------------------------------------------------------- utf8::String FirebirdStatement::fieldName(uintptr_t i) { return static_cast(this)->values().nameOfIndex(i); } //--------------------------------------------------------------------------- intptr_t FirebirdStatement::fieldIndex(const utf8::String & name,bool noThrow) { intptr_t i = static_cast(this)->values().indexOfName(name); if( i < 0 && !noThrow ) newObjectV1C2(EINVAL,"invalid field name: " + name + ", " + __PRETTY_FUNCTION__)->throwSP(); return i; } //--------------------------------------------------------------------------- } // namespace adicpp //---------------------------------------------------------------------------