/* * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI) * * Website: http://www.ocilib.net * * Copyright (c) 2007-2023 Vincent ROGIER * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include "ocilibcpp/types.hpp" namespace ocilib { inline Resultset::Resultset(OCI_Resultset *resultset, core::Handle *parent) { AcquireTransient(resultset, parent); } inline bool Resultset::Next() { return (core::Check(OCI_FetchNext(*this)) == TRUE); } inline bool Resultset::Prev() { return (core::Check(OCI_FetchPrev(*this)) == TRUE); } inline bool Resultset::First() { return (core::Check(OCI_FetchFirst(*this)) == TRUE); } inline bool Resultset::Last() { return (core::Check(OCI_FetchLast(*this)) == TRUE); } inline bool Resultset::Seek(SeekMode mode, int offset) { return (core::Check(OCI_FetchSeek(*this, mode, offset)) == TRUE); } inline unsigned int Resultset::GetCount() const { return core::Check(OCI_GetRowCount(*this)); } inline unsigned int Resultset::GetCurrentRow() const { return core::Check(OCI_GetCurrentRow(*this)); } inline unsigned int Resultset::GetColumnIndex(const ostring& name) const { return core::Check(OCI_GetColumnIndex(*this, name.c_str())); } inline unsigned int Resultset::GetColumnCount() const { return core::Check(OCI_GetColumnCount(*this)); } inline Column Resultset::GetColumn(unsigned int index) const { return Column(core::Check(OCI_GetColumn(*this, index)), GetHandle()); } inline Column Resultset::GetColumn(const ostring& name) const { return Column(core::Check(OCI_GetColumn2(*this, name.c_str())), GetHandle()); } inline bool Resultset::IsColumnNull(unsigned int index) const { return (core::Check(OCI_IsNull(*this, index)) == TRUE); } inline bool Resultset::IsColumnNull(const ostring& name) const { return (core::Check(OCI_IsNull2(*this, name.c_str())) == TRUE); } inline Statement Resultset::GetStatement() const { return Statement( core::Check(OCI_ResultsetGetStatement(*this)), nullptr); } inline bool Resultset::operator ++ (int) { return Next(); } inline bool Resultset::operator -- (int) { return Prev(); } inline bool Resultset::operator += (int offset) { return Seek(SeekRelative, offset); } inline bool Resultset::operator -= (int offset) { return Seek(SeekRelative, -offset); } template void Resultset::Get(unsigned int index, T& value) const { value = Get(index); } template void Resultset::Get(const ostring &name, T& value) const { value = Get(name); } template bool Resultset::Get(T& value, TAdapter adapter) const { return adapter(static_cast(*this), value); } template unsigned int Resultset::ForEach(TCallback callback) { while (Next()) { if (!callback(static_cast(*this))) { break; } } return GetCurrentRow(); } template unsigned int Resultset::ForEach(T callback, U adapter) { while (Next()) { if (!callback(adapter(static_cast(*this)))) { break; } } return GetCurrentRow(); } template<> inline short Resultset::Get(unsigned int index) const { return core::Check(OCI_GetShort(*this, index)); } template<> inline short Resultset::Get(const ostring& name) const { return core::Check(OCI_GetShort2(*this, name.c_str())); } template<> inline unsigned short Resultset::Get(unsigned int index) const { return core::Check(OCI_GetUnsignedShort(*this, index)); } template<> inline unsigned short Resultset::Get(const ostring& name) const { return core::Check(OCI_GetUnsignedShort2(*this, name.c_str())); } template<> inline int Resultset::Get(unsigned int index) const { return core::Check(OCI_GetInt(*this, index)); } template<> inline int Resultset::Get(const ostring& name) const { return core::Check(OCI_GetInt2(*this, name.c_str())); } template<> inline unsigned int Resultset::Get(unsigned int index) const { return core::Check(OCI_GetUnsignedInt(*this, index)); } template<> inline unsigned int Resultset::Get(const ostring& name) const { return core::Check(OCI_GetUnsignedInt2(*this, name.c_str())); } template<> inline big_int Resultset::Get(unsigned int index) const { return core::Check(OCI_GetBigInt(*this, index)); } template<> inline big_int Resultset::Get(const ostring& name) const { return core::Check(OCI_GetBigInt2(*this, name.c_str())); } template<> inline big_uint Resultset::Get(unsigned int index) const { return core::Check(OCI_GetUnsignedBigInt(*this, index)); } template<> inline big_uint Resultset::Get(const ostring& name) const { return core::Check(OCI_GetUnsignedBigInt2(*this, name.c_str())); } template<> inline float Resultset::Get(unsigned int index) const { return core::Check(OCI_GetFloat(*this, index)); } template<> inline float Resultset::Get(const ostring& name) const { return core::Check(OCI_GetFloat2(*this, name.c_str())); } template<> inline double Resultset::Get(unsigned int index) const { return core::Check(OCI_GetDouble(*this, index)); } template<> inline double Resultset::Get(const ostring& name) const { return core::Check(OCI_GetDouble2(*this, name.c_str())); } template<> inline Number Resultset::Get(unsigned int index) const { return Number(core::Check(OCI_GetNumber(*this, index)), GetHandle()); } template<> inline Number Resultset::Get(const ostring& name) const { return Number(core::Check(OCI_GetNumber2(*this, name.c_str())), GetHandle()); } template<> inline ostring Resultset::Get(unsigned int index) const { return core::MakeString(core::Check(OCI_GetString(*this, index))); } template<> inline ostring Resultset::Get(const ostring& name) const { return core::MakeString(core::Check(OCI_GetString2(*this,name.c_str()))); } template<> inline Raw Resultset::Get(unsigned int index) const { unsigned int size = core::Check(OCI_GetDataLength(*this,index)); core::ManagedBuffer buffer(static_cast(size + 1)); size = core::Check(OCI_GetRaw(*this, index, static_cast(buffer), size)); return core::MakeRaw(buffer, size); } template<> inline Raw Resultset::Get(const ostring& name) const { unsigned int size = core::Check(OCI_GetDataLength(*this, core::Check(OCI_GetColumnIndex(*this, name.c_str())))); core::ManagedBuffer buffer(static_cast(size + 1)); size = core::Check(OCI_GetRaw2(*this, name.c_str(), static_cast(buffer), size)); return core::MakeRaw(buffer, size); } template<> inline Date Resultset::Get(unsigned int index) const { return Date(core::Check(OCI_GetDate(*this, index)), GetHandle()); } template<> inline Date Resultset::Get(const ostring& name) const { return Date(core::Check(OCI_GetDate2(*this,name.c_str())), GetHandle()); } template<> inline Timestamp Resultset::Get(unsigned int index) const { return Timestamp(core::Check(OCI_GetTimestamp(*this, index)), GetHandle()); } template<> inline Timestamp Resultset::Get(const ostring& name) const { return Timestamp(core::Check(OCI_GetTimestamp2(*this,name.c_str())), GetHandle()); } template<> inline Interval Resultset::Get(unsigned int index) const { return Interval(core::Check(OCI_GetInterval(*this, index)), GetHandle()); } template<> inline Interval Resultset::Get(const ostring& name) const { return Interval(core::Check(OCI_GetInterval2(*this,name.c_str())), GetHandle()); } template<> inline Object Resultset::Get(unsigned int index) const { return Object(core::Check(OCI_GetObject(*this, index)), GetHandle()); } template<> inline Object Resultset::Get(const ostring& name) const { return Object(core::Check(OCI_GetObject2(*this,name.c_str())), GetHandle()); } template<> inline Reference Resultset::Get(unsigned int index) const { return Reference(core::Check(OCI_GetRef(*this, index)), GetHandle()); } template<> inline Reference Resultset::Get(const ostring& name) const { return Reference(core::Check(OCI_GetRef2(*this,name.c_str())), GetHandle()); } template<> inline Statement Resultset::Get(unsigned int index) const { return Statement(core::Check(OCI_GetStatement(*this, index)), GetHandle()); } template<> inline Statement Resultset::Get(const ostring& name) const { return Statement(core::Check(OCI_GetStatement2(*this,name.c_str())), GetHandle()); } template<> inline Clob Resultset::Get(unsigned int index) const { return Clob(core::Check(OCI_GetLob(*this, index)), GetHandle()); } template<> inline Clob Resultset::Get(const ostring& name) const { return Clob(core::Check(OCI_GetLob2(*this,name.c_str())), GetHandle()); } template<> inline NClob Resultset::Get(unsigned int index) const { return NClob(core::Check(OCI_GetLob(*this, index)), GetHandle()); } template<> inline NClob Resultset::Get(const ostring& name) const { return NClob(core::Check(OCI_GetLob2(*this, name.c_str())), GetHandle()); } template<> inline Blob Resultset::Get(unsigned int index) const { return Blob(core::Check(OCI_GetLob(*this, index)), GetHandle()); } template<> inline Blob Resultset::Get(const ostring& name) const { return Blob(core::Check(OCI_GetLob2(*this,name.c_str())), GetHandle()); } template<> inline File Resultset::Get(unsigned int index) const { return File(core::Check(OCI_GetFile(*this, index)), GetHandle()); } template<> inline File Resultset::Get(const ostring& name) const { return File(core::Check(OCI_GetFile2(*this,name.c_str())), GetHandle()); } template<> inline Clong Resultset::Get(unsigned int index) const { return Clong(core::Check(OCI_GetLong(*this, index)), GetHandle()); } template<> inline Clong Resultset::Get(const ostring& name) const { return Clong(core::Check(OCI_GetLong2(*this,name.c_str())), GetHandle()); } template<> inline Blong Resultset::Get(unsigned int index) const { return Blong(core::Check(OCI_GetLong(*this, index)), GetHandle()); } template<> inline Blong Resultset::Get(const ostring& name) const { return Blong(core::Check(OCI_GetLong2(*this,name.c_str())), GetHandle()); } template T Resultset::Get(unsigned int index) const { return T(core::Check(OCI_GetColl(*this, index)), GetHandle()); } template T Resultset::Get(const ostring& name) const { return T(core::Check(OCI_GetColl2(*this, name.c_str())), GetHandle()); } }