aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-11-16 10:59:14 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-11-16 10:59:14 +0200
commit7e704a7e6e57cf877614fd762d4667ef32be2eea (patch)
tree167f6059a5a935585499fc006886abc69a4df6c8 /odb
parent9cce004234838754b8bd7776b4ed37686c9a17c2 (diff)
Add build infrastructure, options file and exceptions implementation
Diffstat (limited to 'odb')
-rw-r--r--odb/mssql/details/config.h.in14
-rw-r--r--odb/mssql/details/config.hxx20
-rw-r--r--odb/mssql/details/export.hxx41
-rw-r--r--odb/mssql/details/options.cli57
-rw-r--r--odb/mssql/exceptions.cxx82
-rw-r--r--odb/mssql/exceptions.hxx116
-rw-r--r--odb/mssql/forward.hxx63
-rw-r--r--odb/mssql/makefile131
-rw-r--r--odb/mssql/mssql-fwd.hxx22
-rw-r--r--odb/mssql/odbc.hxx25
-rw-r--r--odb/mssql/version.hxx45
11 files changed, 616 insertions, 0 deletions
diff --git a/odb/mssql/details/config.h.in b/odb/mssql/details/config.h.in
new file mode 100644
index 0000000..de88c81
--- /dev/null
+++ b/odb/mssql/details/config.h.in
@@ -0,0 +1,14 @@
+/* file : odb/mssql/details/config.h.in
+ * author : Constantin Michael <constantin@codesynthesis.com>
+ * copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+ * license : ODB NCUEL; see accompanying LICENSE file
+ */
+
+/* This file is automatically processed by configure. */
+
+#ifndef ODB_MSSQL_DETAILS_CONFIG_H
+#define ODB_MSSQL_DETAILS_CONFIG_H
+
+#undef LIBODB_MSSQL_STATIC_LIB
+
+#endif /* ODB_MSSQL_DETAILS_CONFIG_H */
diff --git a/odb/mssql/details/config.hxx b/odb/mssql/details/config.hxx
new file mode 100644
index 0000000..f66d567
--- /dev/null
+++ b/odb/mssql/details/config.hxx
@@ -0,0 +1,20 @@
+// file : odb/mssql/details/config.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_DETAILS_CONFIG_HXX
+#define ODB_MSSQL_DETAILS_CONFIG_HXX
+
+// no pre
+
+#ifdef _MSC_VER
+#elif defined(ODB_COMPILER)
+# error libodb-mssql header included in odb-compiled header
+#else
+# include <odb/mssql/details/config.h>
+#endif
+
+// no post
+
+#endif // ODB_MSSQL_DETAILS_CONFIG_HXX
diff --git a/odb/mssql/details/export.hxx b/odb/mssql/details/export.hxx
new file mode 100644
index 0000000..3f24f3c
--- /dev/null
+++ b/odb/mssql/details/export.hxx
@@ -0,0 +1,41 @@
+// file : odb/mssql/details/export.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_DETAILS_EXPORT_HXX
+#define ODB_MSSQL_DETAILS_EXPORT_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/mssql/details/config.hxx>
+
+#ifdef LIBODB_MSSQL_STATIC_LIB
+# define LIBODB_MSSQL_EXPORT
+#else
+# ifdef _WIN32
+# ifdef _MSC_VER
+# ifdef LIBODB_MSSQL_DYNAMIC_LIB
+# define LIBODB_MSSQL_EXPORT __declspec(dllexport)
+# else
+# define LIBODB_MSSQL_EXPORT __declspec(dllimport)
+# endif
+# else
+# ifdef LIBODB_MSSQL_DYNAMIC_LIB
+# ifdef DLL_EXPORT
+# define LIBODB_MSSQL_EXPORT __declspec(dllexport)
+# else
+# define LIBODB_MSSQL_EXPORT
+# endif
+# else
+# define LIBODB_MSSQL_EXPORT __declspec(dllimport)
+# endif
+# endif
+# else
+# define LIBODB_MSSQL_EXPORT
+# endif
+#endif
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_DETAILS_EXPORT_HXX
diff --git a/odb/mssql/details/options.cli b/odb/mssql/details/options.cli
new file mode 100644
index 0000000..693f644
--- /dev/null
+++ b/odb/mssql/details/options.cli
@@ -0,0 +1,57 @@
+// file : odb/mssql/details/options.cli
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+include <string>;
+
+namespace odb
+{
+ namespace mssql
+ {
+ namespace details
+ {
+ class options
+ {
+ std::string --user | --username
+ {
+ "<name>",
+ "PostgreSQL database user."
+ };
+
+ std::string --password
+ {
+ "<str>",
+ "PostgreSQL database password."
+ };
+
+ std::string --database | --dbname
+ {
+ "<name>",
+ "PostgreSQL database name."
+ };
+
+ std::string --host
+ {
+ "<str>",
+ "PostgreSQL database host name or address (localhost by default)."
+ };
+
+ std::string --port
+ {
+ "<str>",
+ "PostgreSQL database port number or socket file name extension for
+ Unix-domain connections."
+ };
+
+ std::string --options-file
+ {
+ "<file>",
+ "Read additional options from <file>. Each option appearing on a
+ separate line optionally followed by space and an option value.
+ Empty lines and lines starting with \cb{#} are ignored."
+ };
+ };
+ }
+ }
+}
diff --git a/odb/mssql/exceptions.cxx b/odb/mssql/exceptions.cxx
new file mode 100644
index 0000000..1b415a7
--- /dev/null
+++ b/odb/mssql/exceptions.cxx
@@ -0,0 +1,82 @@
+// file : odb/mssql/exceptions.cxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#include <sstream>
+
+#include <odb/mssql/exceptions.hxx>
+
+using namespace std;
+
+namespace odb
+{
+ namespace mssql
+ {
+ //
+ // database_exception
+ //
+
+ database_exception::record::
+ record (SQLINTEGER e, const string& s, const string& m)
+ : error_ (e), sqlstate_ (s), message_ (m)
+ {
+ }
+
+ database_exception::
+ ~database_exception () throw ()
+ {
+ }
+
+ database_exception::
+ database_exception ()
+ {
+ }
+
+ database_exception::
+ database_exception (SQLINTEGER e, const string& s, const string& m)
+ {
+ append (e, s, m);
+ }
+
+ void database_exception::
+ append (SQLINTEGER e, const string& s, const string& m)
+ {
+ records_.push_back (record (e, s, m));
+
+ if (!what_.empty ())
+ what_ += '\n';
+
+ ostringstream ostr;
+ ostr << e << " (" << s << "): " << m;
+ what_ += ostr.str ();
+ }
+
+ const char* database_exception::
+ what () const throw ()
+ {
+ return what_.c_str ();
+ }
+
+ //
+ // cli_exception
+ //
+
+ cli_exception::
+ cli_exception (const string& what)
+ : what_ (what)
+ {
+ }
+
+ cli_exception::
+ ~cli_exception () throw ()
+ {
+ }
+
+ const char* cli_exception::
+ what () const throw ()
+ {
+ return what_.c_str ();
+ }
+ }
+}
diff --git a/odb/mssql/exceptions.hxx b/odb/mssql/exceptions.hxx
new file mode 100644
index 0000000..321a41d
--- /dev/null
+++ b/odb/mssql/exceptions.hxx
@@ -0,0 +1,116 @@
+// file : odb/mssql/exceptions.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_EXCEPTIONS_HXX
+#define ODB_MSSQL_EXCEPTIONS_HXX
+
+#include <odb/pre.hxx>
+
+#include <string>
+#include <vector>
+
+#include <odb/exceptions.hxx>
+
+#include <odb/mssql/version.hxx>
+#include <odb/mssql/mssql-fwd.hxx>
+#include <odb/mssql/details/export.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ struct LIBODB_MSSQL_EXPORT database_exception: odb::database_exception
+ {
+ struct record
+ {
+ record (SQLINTEGER error,
+ const std::string& sqlstate,
+ const std::string& message);
+
+ SQLINTEGER
+ error () const
+ {
+ return error_;
+ }
+
+ const std::string&
+ sqlstate () const
+ {
+ return sqlstate_;
+ }
+
+ const std::string&
+ message () const
+ {
+ return message_;
+ }
+
+ private:
+ SQLINTEGER error_;
+ std::string sqlstate_;
+ std::string message_;
+ };
+
+ typedef std::vector<record> records;
+
+ typedef records::size_type size_type;
+ typedef records::const_iterator iterator;
+
+ iterator
+ begin () const
+ {
+ return records_.begin ();
+ }
+
+ iterator
+ end () const
+ {
+ return records_.end ();
+ }
+
+ size_type
+ size () const
+ {
+ return records_.size ();
+ }
+
+ virtual const char*
+ what () const throw ();
+
+ public:
+ ~database_exception () throw ();
+
+ database_exception ();
+ database_exception (SQLINTEGER error,
+ const std::string& sqlstate,
+ const std::string& message);
+
+ void
+ append (SQLINTEGER error,
+ const std::string& sqlstate,
+ const std::string& message);
+
+ private:
+ records records_;
+ std::string what_;
+ };
+
+ struct LIBODB_MSSQL_EXPORT cli_exception: odb::exception
+ {
+ cli_exception (const std::string& what);
+ ~cli_exception () throw ();
+
+ virtual const char*
+ what () const throw ();
+
+ private:
+ std::string what_;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_EXCEPTIONS_HXX
diff --git a/odb/mssql/forward.hxx b/odb/mssql/forward.hxx
new file mode 100644
index 0000000..c81ebf9
--- /dev/null
+++ b/odb/mssql/forward.hxx
@@ -0,0 +1,63 @@
+// file : odb/mssql/forward.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_FORWARD_HXX
+#define ODB_MSSQL_FORWARD_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/forward.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ class database;
+ class connection;
+ typedef details::shared_ptr<connection> connection_ptr;
+ class connection_factory;
+ class statement;
+ class transaction;
+ class tracer;
+ class query;
+
+ // Implementation details.
+ //
+ enum statement_kind
+ {
+ statement_select,
+ statement_insert,
+ statement_update
+ };
+
+ class binding;
+ class select_statement;
+
+ template <typename T>
+ class object_statements;
+
+ template <typename T>
+ class object_statements_no_id;
+
+ template <typename T>
+ class view_statements;
+
+ template <typename T>
+ class container_statements;
+ }
+
+ namespace details
+ {
+ template <>
+ struct counter_type<mssql::connection>
+ {
+ typedef shared_base counter;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_FORWARD_HXX
diff --git a/odb/mssql/makefile b/odb/mssql/makefile
new file mode 100644
index 0000000..98749c1
--- /dev/null
+++ b/odb/mssql/makefile
@@ -0,0 +1,131 @@
+# file : odb/mssql/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# author : Constantin Michael <constantin@codesynthesis.com>
+# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cxx := \
+exceptions.cxx
+
+
+cli_tun := details/options.cli
+cxx_tun := $(cxx)
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(cli_tun:.cli=.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+odb_mssql.l := $(out_base)/odb-mssql.l
+odb_mssql.l.cpp-options := $(out_base)/odb-mssql.l.cpp-options
+
+default := $(out_base)/
+dist := $(out_base)/.dist
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/cli/stub.make,\
+ cli: cli,cli-rules: cli_rules)
+
+$(call import,\
+ $(scf_root)/import/libodb/stub.make,\
+ l: odb.l,cpp-options: odb.l.cpp-options)
+
+# @@ TODO
+#
+#$(call import,\
+# $(scf_root)/import/libpq/stub.make,\
+# l: pq.l,\
+# cpp-options: pq.l.cpp-options,\
+# cpp-options-inline: pq_cpp_options)
+
+# Build.
+#
+$(odb_mssql.l): $(cxx_obj) $(odb.l) -lodbc32 # @@ TODO
+$(odb_mssql.l.cpp-options): value := -I$(out_root) -I$(src_root)
+$(odb_mssql.l.cpp-options): $(odb.l.cpp-options)
+
+$(cxx_obj) $(cxx_od): $(odb_mssql.l.cpp-options) $(out_base)/details/config.h
+
+genf := $(cli_tun:.cli=.hxx) $(cli_tun:.cli=.ixx) $(cli_tun:.cli=.cxx)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(cli)
+$(gen): cli := $(cli)
+$(gen): cli_options += \
+--long-usage \
+--generate-specifier \
+--generate-file-scanner \
+--cli-namespace odb::mssql::details::cli \
+--guard-prefix LIBODB_MSSQL_DETAILS
+
+$(out_base)/details/config.h: | $(out_base)/details/.
+ @echo '/* file : odb/mssql/details/config.h' >$@
+ @echo ' * author : automatically generated' >>$@
+ @echo ' */' >>$@
+ @echo '' >>$@
+ @echo '#ifndef ODB_MSSQL_DETAILS_CONFIG_H' >>$@
+ @echo '#define ODB_MSSQL_DETAILS_CONFIG_H' >>$@
+ @echo '' >>$@
+ @echo '#endif /* ODB_MSSQL_DETAILS_CONFIG_H */' >>$@
+
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen) $(out_base)/details/config.h)
+
+# Convenience alias for default target.
+#
+$(out_base)/: $(odb_mssql.l)
+
+# Dist.
+#
+$(dist): sources_dist := $(cxx)
+$(dist): export sources := $(sources_dist) $(cli_tun:.cli=.cxx)
+$(dist): headers_dist = $(subst $(src_base)/,,$(shell find $(src_base) \
+-name '*.hxx' -o -name '*.ixx' -o -name '*.txx'))
+$(dist): gen_headers := $(cli_tun:.cli=.hxx) $(cli_tun:.cli=.ixx)
+$(dist): export headers = $(sort $(headers_dist) $(gen_headers))
+$(dist): gen_dist := $(gen)
+$(dist): data_dist := $(cli_tun) details/config.h.in
+$(dist): export extra_dist := $(data_dist) libodb-mssql-vc9.vcproj \
+libodb-mssql-vc10.vcxproj libodb-mssql-vc10.vcxproj.filters
+$(dist): export interface_version = $(shell sed -e \
+'s/^\([0-9]*\.[0-9]*\).*/\1/' $(src_root)/version)
+
+$(dist): $(gen)
+ $(call dist-data,$(sources_dist) $(headers_dist) $(data_dist))
+ $(call dist-data,$(gen_dist),$(dist_prefix)/odb/mssql/details)
+ $(call meta-vc9proj,$(src_base)/libodb-mssql-vc9.vcproj)
+ $(call meta-vc10proj,$(src_base)/libodb-mssql-vc10.vcxproj)
+ $(call meta-automake)
+
+# Clean.
+#
+$(clean): $(odb_mssql.l).o.clean \
+ $(odb_mssql.l.cpp-options).clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addprefix $(out_base)/,$(cli_tun:.cli=.cxx.cli.clean))
+ $(call message,rm $$1,rm -f $$1,$(out_base)/details/config.h)
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(odb_mssql.l): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := details/config.h $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/dist.make)
+$(call include,$(bld_root)/meta/vc9proj.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(cli_rules))
+$(call include,$(bld_root)/cxx/o-l.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
diff --git a/odb/mssql/mssql-fwd.hxx b/odb/mssql/mssql-fwd.hxx
new file mode 100644
index 0000000..434edb1
--- /dev/null
+++ b/odb/mssql/mssql-fwd.hxx
@@ -0,0 +1,22 @@
+// file : odb/mssql/mssql-fwd.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_MSSQL_FWD_HXX
+#define ODB_MSSQL_MSSQL_FWD_HXX
+
+#include <odb/pre.hxx>
+
+// Forward declaration for some of the types defined in sqltypes.h or
+// sqlncli.h. This allows us to avoid having to include these files
+// in public headers.
+//
+#ifdef _WIN32
+typedef long SQLINTEGER;
+typedef unsigned long SQLUINTEGER;
+#endif
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_MSSQL_FWD_HXX
diff --git a/odb/mssql/odbc.hxx b/odb/mssql/odbc.hxx
new file mode 100644
index 0000000..91023b3
--- /dev/null
+++ b/odb/mssql/odbc.hxx
@@ -0,0 +1,25 @@
+// file : odb/mssql/odbc.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_ODBC_HXX
+#define ODB_MSSQL_ODBC_HXX
+
+#include <odb/pre.hxx>
+
+#ifdef _WIN32
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+#endif
+
+#include <sqlext.h> // Standard ODBC.
+
+//#define _SQLNCLI_ODBC_
+//#include <sqlncli.h> // SQL Server native client driver specifics.
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_ODBC_HXX
diff --git a/odb/mssql/version.hxx b/odb/mssql/version.hxx
new file mode 100644
index 0000000..ca474ea
--- /dev/null
+++ b/odb/mssql/version.hxx
@@ -0,0 +1,45 @@
+// file : odb/mssql/version.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_VERSION_HXX
+#define ODB_Mssql_VERSION_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/version.hxx>
+#include <odb/mssql/details/config.hxx>
+
+// Version format is AABBCCDD where
+//
+// AA - major version number
+// BB - minor version number
+// CC - bugfix version number
+// DD - alpha / beta (DD + 50) version number
+//
+// When DD is not 00, 1 is subtracted from AABBCC. For example:
+//
+// Version AABBCCDD
+// 2.0.0 02000000
+// 2.1.0 02010000
+// 2.1.1 02010100
+// 2.2.0.a1 02019901
+// 3.0.0.b2 02999952
+//
+
+// Check that we have compatible ODB version.
+//
+#if ODB_VERSION != 10601
+# error incompatible odb interface version detected
+#endif
+
+// libodb-mssql version: odb interface version plus the bugfix
+// version.
+//
+#define LIBODB_MSSQL_VERSION 1069901
+#define LIBODB_MSSQL_VERSION_STR "1.7.0.a1"
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_VERSION_HXX