summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2008-11-13 14:45:11 +0000
committerrandomdan <randomdan@localhost>2008-11-13 14:45:11 +0000
commitefd292508070835781a0d92448a3661279dfd307 (patch)
tree0d2592bacfdb0cd159ebc5780dd69f86cc893af0
parentFix the C++ template errors (diff)
downloadlibdbpp-odbc-efd292508070835781a0d92448a3661279dfd307.tar.bz2
libdbpp-odbc-efd292508070835781a0d92448a3661279dfd307.tar.xz
libdbpp-odbc-efd292508070835781a0d92448a3661279dfd307.zip
Lots of little fixes
-rw-r--r--libodbcpp/Doxyfile275
-rw-r--r--libodbcpp/column.cpp6
-rw-r--r--libodbcpp/column.h12
-rwxr-xr-xlibodbcpp/configure2
-rw-r--r--libodbcpp/connection.cpp42
-rw-r--r--libodbcpp/connection.h3
-rw-r--r--libodbcpp/dsn.h2
-rw-r--r--libodbcpp/error.cpp26
-rw-r--r--libodbcpp/error.h8
-rw-r--r--libodbcpp/makefile.in16
-rw-r--r--libodbcpp/param.cpp3
-rw-r--r--libodbcpp/selectcommand.cpp24
-rw-r--r--libodbcpp/selectcommand.h3
-rw-r--r--libodbcpp/timetypepair.cpp1
-rw-r--r--libodbcpp/ustring.cpp (renamed from libodbcpp/string.cpp)2
-rw-r--r--libodbcpp/ustring.h (renamed from libodbcpp/string.h)0
16 files changed, 393 insertions, 32 deletions
diff --git a/libodbcpp/Doxyfile b/libodbcpp/Doxyfile
new file mode 100644
index 0000000..3c4760c
--- /dev/null
+++ b/libodbcpp/Doxyfile
@@ -0,0 +1,275 @@
+# Doxyfile 1.4.7
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME = libodbc++
+PROJECT_NUMBER =
+OUTPUT_DIRECTORY = docs
+CREATE_SUBDIRS = NO
+OUTPUT_LANGUAGE = English
+USE_WINDOWS_ENCODING = NO
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH = /home/randomdan/src/libodbcpp/
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+DETAILS_AT_TOP = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 8
+ALIASES =
+OPTIMIZE_OUTPUT_FOR_C = NO
+OPTIMIZE_OUTPUT_JAVA = NO
+BUILTIN_STL_SUPPORT = NO
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = YES
+EXTRACT_STATIC = YES
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = YES
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_BY_SCOPE_NAME = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_DIRECTORIES = NO
+FILE_VERSION_FILTER =
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = /home/randomdan/src/libodbcpp
+FILE_PATTERNS = *.c \
+ *.cc \
+ *.cxx \
+ *.cpp \
+ *.c++ \
+ *.d \
+ *.java \
+ *.ii \
+ *.ixx \
+ *.ipp \
+ *.i++ \
+ *.inl \
+ *.h \
+ *.hh \
+ *.hxx \
+ *.hpp \
+ *.h++ \
+ *.idl \
+ *.odl \
+ *.cs \
+ *.php \
+ *.php3 \
+ *.inc \
+ *.m \
+ *.mm \
+ *.dox \
+ *.py \
+ *.C \
+ *.CC \
+ *.C++ \
+ *.II \
+ *.I++ \
+ *.H \
+ *.HH \
+ *.H++ \
+ *.CS \
+ *.PHP \
+ *.PHP3 \
+ *.M \
+ *.MM \
+ *.PY
+RECURSIVE = NO
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS = *
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = YES
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION = YES
+REFERENCES_LINK_SOURCE = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_ALIGN_MEMBERS = YES
+GENERATE_HTMLHELP = YES
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+BINARY_TOC = NO
+TOC_EXPAND = YES
+DISABLE_INDEX = NO
+ENUM_VALUES_PER_LINE = 4
+GENERATE_TREEVIEW = YES
+TREEVIEW_WIDTH = 250
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4wide
+EXTRA_PACKAGES =
+LATEX_HEADER =
+PDF_HYPERLINKS = NO
+USE_PDFLATEX = NO
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = NO
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = YES
+EXTERNAL_GROUPS = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = YES
+HIDE_UNDOC_RELATIONS = NO
+HAVE_DOT = YES
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = YES
+TEMPLATE_RELATIONS = YES
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = YES
+CALLER_GRAPH = YES
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+DOT_PATH =
+DOTFILE_DIRS =
+MAX_DOT_GRAPH_WIDTH = 1024
+MAX_DOT_GRAPH_HEIGHT = 1024
+MAX_DOT_GRAPH_DEPTH = 1000
+DOT_TRANSPARENT = YES
+DOT_MULTI_TARGETS = YES
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+SEARCHENGINE = NO
diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp
index 212b792..58f9b31 100644
--- a/libodbcpp/column.cpp
+++ b/libodbcpp/column.cpp
@@ -2,7 +2,7 @@
#include "error.h"
#include "timetypepair.h"
-ODBC::Column::Column(String n, u_int i) :
+ODBC::Column::Column(String n, unsigned int i) :
colNo(i),
name(n),
fresh(false)
@@ -24,12 +24,12 @@ ODBC_DEFAULT_COLUMN_CAST(SQLINTEGER, long long);
ODBC_DEFAULT_COLUMN_CAST(SQLINTEGER, int);
ODBC_DEFAULT_COLUMN_CAST(SQLDOUBLE, double);
ODBC_DEFAULT_COLUMN_CAST(SQLDOUBLE, float);
-ODBC_DEFAULT_COLUMN_CAST(SQLCHAR*, const unsigned char * const);
+ODBC_DEFAULT_COLUMN_CAST(SQLCHAR*, const unsigned char *);
ODBC_DEFAULT_COLUMN_CAST(SQLCHAR*, String);
ODBC::Column::operator std::string() const {
return (const char*)((dynamic_cast<const _Column<SQLCHAR*>& >(*this)).value);
}
-ODBC::Column::operator const char * const () const {
+ODBC::Column::operator const char * () const {
return (const char*)((dynamic_cast<const _Column<SQLCHAR*>& >(*this)).value);
}
ODBC::Column::operator const struct tm & () const {
diff --git a/libodbcpp/column.h b/libodbcpp/column.h
index 9f597c7..87c7edf 100644
--- a/libodbcpp/column.h
+++ b/libodbcpp/column.h
@@ -1,13 +1,13 @@
#ifndef ODBC_COLUMN_H
#define ODBC_COLUMN_H
-#include "string.h"
+#include "ustring.h"
#include "bind.h"
namespace ODBC {
class Column : public BindBase {
public:
- Column(String, u_int);
+ Column(String, unsigned int);
virtual ~Column();
void bind(SQLHANDLE, SQLUINTEGER, SQLSMALLINT, void*, size_t);
operator int () const;
@@ -16,13 +16,13 @@ namespace ODBC {
operator unsigned long long () const;
operator double () const;
operator float () const;
- operator const unsigned char * const () const;
- operator const char * const () const;
+ operator const unsigned char * () const;
+ operator const char * () const;
operator std::string () const;
operator String () const;
operator const struct tm & () const;
- const u_int colNo;
+ const unsigned int colNo;
const String name;
private:
mutable bool fresh;
@@ -31,7 +31,7 @@ namespace ODBC {
template <class t>
class _Column : public Bind<t>, public Column {
public:
- _Column(String, u_int);
+ _Column(String, unsigned int);
~_Column() {}
};
}
diff --git a/libodbcpp/configure b/libodbcpp/configure
index a7d295d..7cd931c 100755
--- a/libodbcpp/configure
+++ b/libodbcpp/configure
@@ -1,4 +1,4 @@
#!/bin/bash
cp makefile.in makefile
-makedepend *.cpp
+makedepend *.cpp 2> /dev/null
diff --git a/libodbcpp/connection.cpp b/libodbcpp/connection.cpp
index 7fa32fd..ad1c2a7 100644
--- a/libodbcpp/connection.cpp
+++ b/libodbcpp/connection.cpp
@@ -4,7 +4,6 @@
#include "error.h"
ODBC::Connection::Connection(const DSN& d) :
- DSN(d),
env(0),
conn(0),
txDepth(0),
@@ -15,7 +14,7 @@ ODBC::Connection::Connection(const DSN& d) :
throw Error(dberr, SQL_HANDLE_ENV, env, "Allocate handle");
}
- dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
+ dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC2, 0);
if ((dberr != SQL_SUCCESS)) {
throw Error(dberr, SQL_HANDLE_ENV, env, "Set ODBC version");
}
@@ -30,7 +29,44 @@ ODBC::Connection::Connection(const DSN& d) :
throw Error(dberr, SQL_HANDLE_ENV, env, "Set connection attributes");
}
- dberr = SQLConnect(conn, dsn, SQL_NTS, username, SQL_NTS, password, SQL_NTS);
+ dberr = SQLConnect(conn, d.dsn, SQL_NTS, d.username, SQL_NTS, d.password, SQL_NTS);
+ if ((dberr != SQL_SUCCESS)) {
+ throw Error(dberr, SQL_HANDLE_DBC, conn, "Connect");
+ }
+
+ dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
+ if ((dberr != SQL_SUCCESS)) {
+ throw Error(dberr, SQL_HANDLE_DBC, conn, "Set default auto commit");
+ }
+}
+
+ODBC::Connection::Connection(const String & s) :
+ env(0),
+ conn(0),
+ txDepth(0),
+ txAborted(false)
+{
+ SQLRETURN dberr = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
+ if ((dberr != SQL_SUCCESS)) {
+ throw Error(dberr, SQL_HANDLE_ENV, env, "Allocate handle");
+ }
+
+ dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC2, 0);
+ if ((dberr != SQL_SUCCESS)) {
+ throw Error(dberr, SQL_HANDLE_ENV, env, "Set ODBC version");
+ }
+
+ dberr = SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);
+ if ((dberr != SQL_SUCCESS)) {
+ throw Error(dberr, SQL_HANDLE_ENV, env, "Allocate DBC handle");
+ }
+
+ dberr = SQLSetConnectAttr(conn, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0);
+ if ((dberr != SQL_SUCCESS)) {
+ throw Error(dberr, SQL_HANDLE_ENV, env, "Set connection attributes");
+ }
+
+ dberr = SQLDriverConnect(conn, NULL, s, s.length(), NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
if ((dberr != SQL_SUCCESS)) {
throw Error(dberr, SQL_HANDLE_DBC, conn, "Connect");
}
diff --git a/libodbcpp/connection.h b/libodbcpp/connection.h
index 8593e82..a2a99cf 100644
--- a/libodbcpp/connection.h
+++ b/libodbcpp/connection.h
@@ -5,9 +5,10 @@
#include <sql.h>
namespace ODBC {
- class Connection : private DSN {
+ class Connection {
public:
Connection(const DSN& d);
+ Connection(const String& str);
~Connection();
SQLHENV env;
SQLHDBC conn;
diff --git a/libodbcpp/dsn.h b/libodbcpp/dsn.h
index ac4b6f5..0aee953 100644
--- a/libodbcpp/dsn.h
+++ b/libodbcpp/dsn.h
@@ -1,7 +1,7 @@
#ifndef DSN_H
#define DSN_H
-#include "string.h"
+#include "ustring.h"
namespace ODBC {
class DSN {
diff --git a/libodbcpp/error.cpp b/libodbcpp/error.cpp
index c7f16c7..5497f4d 100644
--- a/libodbcpp/error.cpp
+++ b/libodbcpp/error.cpp
@@ -6,7 +6,7 @@
static
void
-odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * actionfmt, va_list ap)
+odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * actionfmt, va_list ap, char ** msg)
{
SQLCHAR sqlstatus[6];
SQLINTEGER sqlerr;
@@ -20,16 +20,22 @@ odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const *
switch (rc) {
case SQL_SUCCESS:
case SQL_SUCCESS_WITH_INFO:
+ asprintf(msg, "%d: %ld: %5.5s: \"%s\" while attempting to %s",
+ err, sqlerr, sqlstatus, sqlerrmsg, action);
syslog(LOG_WARNING, "%s: %d: %ld: %5.5s: \"%s\" while attempting to %s",
__FUNCTION__, err, sqlerr, sqlstatus, sqlerrmsg, action);
break;
case SQL_INVALID_HANDLE:
+ asprintf(msg, "(%d) Invalid handle passed into function trying to %s.",
+ err, action);
syslog(LOG_ERR, "%s: (%d) Invalid handle passed into function trying to %s.",
__FUNCTION__, err, action);
break;
case SQL_NO_DATA:
+ asprintf(msg, "(%d) No error data available for record trying to %s.",
+ err, action);
syslog(LOG_ERR, "%s: (%d) No error data available for record trying to %s.",
__FUNCTION__, err, action);
break;
@@ -47,8 +53,8 @@ ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char c
va_list ap;
va_start(ap, action);
- odbc_verror(err, handletype, handle, action, ap);
- va_end(ap);
+ odbc_verror(err, handletype, handle, action, ap, &msg);
+ va_end(ap);
}
ODBC::Error::Error(char const * action, ...)
@@ -56,7 +62,19 @@ ODBC::Error::Error(char const * action, ...)
va_list ap;
va_start(ap, action);
- vsyslog(LOG_ERR, action, ap);
+ vsyslog(LOG_ERR, action, ap);
+ vasprintf(&msg, action, ap);
va_end(ap);
}
+ODBC::Error::~Error() throw()
+{
+ free(msg);
+}
+
+const char *
+ODBC::Error::what() const throw()
+{
+ return msg;
+}
+
diff --git a/libodbcpp/error.h b/libodbcpp/error.h
index f7c2958..f283a7c 100644
--- a/libodbcpp/error.h
+++ b/libodbcpp/error.h
@@ -2,14 +2,20 @@
#define ODBC_ERROR_H
#include <sql.h>
+#include <exception>
namespace ODBC {
- class Error {
+ class Error : public std::exception {
public:
Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action, ...)
__attribute__((format(printf, 5, 6)));
Error(char const * action, ...)
__attribute__((format(printf, 2, 3)));
+ ~Error() throw();
+
+ const char * what() const throw();
+ private:
+ char * msg;
};
}
diff --git a/libodbcpp/makefile.in b/libodbcpp/makefile.in
index 93b361b..fc4c341 100644
--- a/libodbcpp/makefile.in
+++ b/libodbcpp/makefile.in
@@ -1,11 +1,13 @@
-default : libodbcpp.so libodbcpp.a
+MYCXXFLAGS=$(CXXFLAGS) -c
+MYLDFLAGS=$(LDFLAGS)
+ALL=libodbcpp.a
OBJS = \
error.o \
connection.o \
dsn.o \
command.o \
- string.o \
+ ustring.o \
bind.o \
param.o \
column.o \
@@ -13,14 +15,12 @@ OBJS = \
modifycommand.o \
selectcommand.o
-libodbcpp.so : ${OBJS}
- ${CXX} -shared -o $@ ${OBJS} -lodbc
libodbcpp.a : ${OBJS}
ar rc $@ ${OBJS}
+%.o : %.cpp
+ $(CXX) $(MYCXXFLAGS) -o $@ $<
.PHONY: clean
-.PHONY: reallyclean
+
clean:
- rm -f *.o *.a *.so
-reallyclean: clean
- rm makefile
+ rm -f ${OBJS} ${ALL}
diff --git a/libodbcpp/param.cpp b/libodbcpp/param.cpp
index 0e49067..a2a90f0 100644
--- a/libodbcpp/param.cpp
+++ b/libodbcpp/param.cpp
@@ -2,6 +2,7 @@
#include "param.h"
#include "command.h"
#include "error.h"
+#include <string.h>
ODBC::Param::Param() :
bound(false)
@@ -147,7 +148,7 @@ void
ODBC::Command::bindParamS(unsigned int i, const unsigned char * val)
{
const unsigned char * x = val;
- while (*val++);
+ while (*val++) ;
bindParamS(i, val, val - x);
}
void
diff --git a/libodbcpp/selectcommand.cpp b/libodbcpp/selectcommand.cpp
index e097865..9d385b9 100644
--- a/libodbcpp/selectcommand.cpp
+++ b/libodbcpp/selectcommand.cpp
@@ -45,7 +45,7 @@ ODBC::SelectCommand::fetch()
// This is here cos it needs to be referenced by (and only by) execute
template <class t>
-ODBC::_Column<t>::_Column(String n, u_int i) : Column(n, i)
+ODBC::_Column<t>::_Column(String n, unsigned int i) : Column(n, i)
{
}
@@ -78,6 +78,7 @@ ODBC::SelectCommand::execute()
}
colName[nameLen] = '\0';
switch (bindType) {
+ case -9:
case SQL_CHAR:
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
@@ -109,6 +110,7 @@ ODBC::SelectCommand::execute()
columns[col] = i;
break;
}
+ case 11:
case SQL_DATETIME:
case SQL_TYPE_TIME:
case SQL_TYPE_DATE:
@@ -133,7 +135,27 @@ ODBC::SelectCommand::execute()
const ODBC::Column&
ODBC::SelectCommand::operator[](unsigned int col) const
{
+ if (col > columns.size()) {
+ throw ODBC::Error("Column index (%u) out of range", col);
+ }
return *columns[col];
}
+const ODBC::Column&
+ODBC::SelectCommand::operator[](const String & colName) const
+{
+ for (Columns::const_iterator col = columns.begin(); col != columns.end(); col++) {
+ if ((*col)->name == colName) {
+ return **col;
+ }
+ }
+ throw ODBC::Error("Column (%s) does not exist", colName.c_str());
+}
+
+unsigned int
+ODBC::SelectCommand::columnCount() const
+{
+ return columns.size();
+}
+
diff --git a/libodbcpp/selectcommand.h b/libodbcpp/selectcommand.h
index fee1afc..0294d07 100644
--- a/libodbcpp/selectcommand.h
+++ b/libodbcpp/selectcommand.h
@@ -11,7 +11,8 @@ namespace ODBC {
SelectCommand (const Connection&, String sql);
~SelectCommand();
bool fetch();
- const Column& operator[](unsigned int col) const;
+ const Column & operator[](unsigned int col) const;
+ const Column & operator[](const String &) const;
unsigned int columnCount() const;
private:
void execute();
diff --git a/libodbcpp/timetypepair.cpp b/libodbcpp/timetypepair.cpp
index 17a840e..55373bb 100644
--- a/libodbcpp/timetypepair.cpp
+++ b/libodbcpp/timetypepair.cpp
@@ -1,4 +1,5 @@
#include "command.h"
+#include <string.h>
ODBC::TimeTypePair::TimeTypePair()
{
diff --git a/libodbcpp/string.cpp b/libodbcpp/ustring.cpp
index d04e141..07a1f44 100644
--- a/libodbcpp/string.cpp
+++ b/libodbcpp/ustring.cpp
@@ -1,5 +1,5 @@
#include <stdarg.h>
-#include "string.h"
+#include "ustring.h"
ODBC::String::String()
{
diff --git a/libodbcpp/string.h b/libodbcpp/ustring.h
index d3c4d41..d3c4d41 100644
--- a/libodbcpp/string.h
+++ b/libodbcpp/ustring.h