Skip to content

Commit 0fbb076

Browse files
committed
Initial code
1 parent 950bd57 commit 0fbb076

10 files changed

+2135
-0
lines changed

Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# program/library target and files
2+
TARGET = sample
3+
SRCS = sample.cpp
4+
5+
# explicit path to sybase library
6+
LIBPATH = -L/opt/sybase12_5_64/OCS/lib
7+
INCLUDES = -I/opt/sybase12_5_64/OCS/include
8+
9+
# compiler path and flags
10+
CC = /opt/gcc/bin/g++
11+
CFLAGS = -std=c++11 -Wall -Wno-unused -Wno-sequence-point -Wno-parentheses -c -ggdb3 -m64 -pthread -DSYB_LP64 -D_REENTRANT
12+
13+
# sybase libraries to include in the build
14+
CTLIB = -lct_r64 # client library
15+
CSLIB = -lcs_r64 # cs library
16+
TCLIB = -lsybtcl_r64 # transport control layer
17+
COMLIB = -lcomn_r64 # internal shared utility library
18+
INTLLIB = -lintl_r64 # internationalization support library
19+
BLKLIB = -lblk_r64 # bulk copy routines
20+
SYSLIBS = -Wl,-Bdynamic -ldl -lpthread -lnsl -lm
21+
LIBS = -Bstatic $(LIBPATH) $(CTLIB) $(CSLIB) $(TCLIB) $(COMLIB) $(INTLLIB) $(SYSLIBS)
22+
23+
# make env setup
24+
OBJDIR = obj
25+
OBJECTS = $(SRCS:.cpp=.o)
26+
FPOBJS = $(addprefix $(OBJDIR)/, $(SRCS:.cpp=.o))
27+
vpath %.o $(OBJDIR)
28+
29+
# compilation rules
30+
all: prep $(TARGET)
31+
32+
prep:
33+
rm -f make.log
34+
test -d $(OBJDIR) || mkdir $(OBJDIR)
35+
36+
.cpp.o:
37+
$(CC) $(CFLAGS) $(INCLUDES) $< -o $(OBJDIR)/$(*).o 2>&1 | tee make.log
38+
39+
$(TARGET): $(OBJECTS)
40+
$(CC) -o $(TARGET) $(FPOBJS) $(LIBS) 2>&1 | tee make.log
41+
42+
clean:
43+
rm -f $(TARGET) $(OBJDIR)/*
44+
45+
depend:
46+
rm -f make.dep
47+
touch make.dep
48+
$(CC) $(CFLAGS) -MMD $(INCLUDES) $(SRCS) 2>&1 | tee -a make.log

Makefile_12.5

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# program/library target and files
2+
TARGET = sample
3+
SRCS = sample.cpp
4+
5+
# explicit path to sybase library
6+
LIBPATH = -L/opt/sybase12_5_64/OCS/lib
7+
INCLUDES = -I/opt/sybase12_5_64/OCS/include
8+
9+
# compiler path and flags
10+
CC = /opt/gcc/bin/g++
11+
CFLAGS = -std=c++11 -Wall -Wno-unused -Wno-sequence-point -Wno-parentheses -c -ggdb3 -m64 -pthread -DSYB_LP64 -D_REENTRANT
12+
13+
# sybase libraries to include in the build
14+
CTLIB = -lct_r64 # client library
15+
CSLIB = -lcs_r64 # cs library
16+
TCLIB = -lsybtcl_r64 # transport control layer
17+
COMLIB = -lcomn_r64 # internal shared utility library
18+
INTLLIB = -lintl_r64 # internationalization support library
19+
BLKLIB = -lblk_r64 # bulk copy routines
20+
SYSLIBS = -Wl,-Bdynamic -ldl -lpthread -lnsl -lm
21+
LIBS = -Bstatic $(LIBPATH) $(CTLIB) $(CSLIB) $(TCLIB) $(COMLIB) $(INTLLIB) $(SYSLIBS)
22+
23+
# make env setup
24+
OBJDIR = obj
25+
OBJECTS = $(SRCS:.cpp=.o)
26+
FPOBJS = $(addprefix $(OBJDIR)/, $(SRCS:.cpp=.o))
27+
vpath %.o $(OBJDIR)
28+
29+
# compilation rules
30+
all: prep $(TARGET)
31+
32+
prep:
33+
rm -f make.log
34+
test -d $(OBJDIR) || mkdir $(OBJDIR)
35+
36+
.cpp.o:
37+
$(CC) $(CFLAGS) $(INCLUDES) $< -o $(OBJDIR)/$(*).o 2>&1 | tee make.log
38+
39+
$(TARGET): $(OBJECTS)
40+
$(CC) -o $(TARGET) $(FPOBJS) $(LIBS) 2>&1 | tee make.log
41+
42+
clean:
43+
rm -f $(TARGET) $(OBJDIR)/*
44+
45+
depend:
46+
rm -f make.dep
47+
touch make.dep
48+
$(CC) $(CFLAGS) -MMD $(INCLUDES) $(SRCS) 2>&1 | tee -a make.log

Makefile_15.0

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# program/library target and files
2+
TARGET = sample
3+
SRCS = sample.cpp
4+
5+
# explicit path to sybase library
6+
LIBPATH = -L/opt/sybase15/OCS-15_0/lib
7+
INCLUDES = -I/opt/sybase15/OCS-15_0/include
8+
9+
# compiler path and flags
10+
CC = /opt/gcc/bin/g++
11+
CFLAGS = -std=c++11 -Wall -Wno-unused -Wno-sequence-point -Wno-parentheses -c -ggdb3 -m64 -pthread -DSYB_LP64 -D_REENTRANT
12+
13+
# sybase libraries to include in the build
14+
CTLIB = -lsybct64 # client library
15+
CSLIB = -lsybcs64 # cs library
16+
TCLIB = -lsybtcl64 # transport control layer
17+
COMLIB = -lsybcomn64 # internal shared utility library
18+
INTLLIB = -lsybintl64 # internationalization support library
19+
UNICLIB = -lsybunic64 # unicode library
20+
BLKLIB = -lsybblk64 # bulk copy routines
21+
SYSLIBS = -Wl,-Bdynamic -ldl -lpthread -lnsl -lm
22+
LIBS = -Bstatic $(LIBPATH) $(CTLIB) $(CSLIB) $(TCLIB) $(COMLIB) $(INTLLIB) $(UNICLIB) $(SYSLIBS)
23+
24+
# make env setup
25+
OBJDIR = obj
26+
OBJECTS = $(SRCS:.cpp=.o)
27+
FPOBJS = $(addprefix $(OBJDIR)/, $(SRCS:.cpp=.o))
28+
vpath %.o $(OBJDIR)
29+
30+
# compilation rules
31+
all: prep $(TARGET)
32+
33+
prep:
34+
rm -f make.log
35+
test -d $(OBJDIR) || mkdir $(OBJDIR)
36+
37+
.cpp.o:
38+
$(CC) $(CFLAGS) $(INCLUDES) $< -o $(OBJDIR)/$(*).o 2>&1 | tee make.log
39+
40+
$(TARGET): $(OBJECTS)
41+
$(CC) -o $(TARGET) $(FPOBJS) $(LIBS) 2>&1 | tee make.log
42+
43+
clean:
44+
rm -f $(TARGET) $(OBJDIR)/*
45+
46+
depend:
47+
rm -f make.dep
48+
touch make.dep
49+
$(CC) $(CFLAGS) -MMD $(INCLUDES) $(SRCS) 2>&1 | tee -a make.log

connection.hpp

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* File: connection.hpp
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
*/
18+
19+
#ifndef CONNECTION_HPP
20+
#define CONNECTION_HPP
21+
22+
#include <memory>
23+
#include "utilities.hpp"
24+
#include "driver.hpp"
25+
#include "statement.hpp"
26+
27+
// forward declaration
28+
namespace vgi { namespace dbconn { namespace dbd {
29+
30+
template <typename T> class driver;
31+
32+
} } } // namespace vgi::dbconn::dbd
33+
34+
namespace vgi { namespace dbconn { namespace dbi {
35+
36+
/**
37+
* iconnection - is an interface that describes common functionality for all
38+
* concrete native implementations for a connection class
39+
*/
40+
struct iconnection
41+
{
42+
virtual ~iconnection() { };
43+
virtual bool connect() = 0;
44+
virtual void disconnect() = 0;
45+
virtual void commit() = 0;
46+
virtual void rollback() = 0;
47+
virtual bool connected() const = 0;
48+
virtual bool alive() const = 0;
49+
virtual istatement* get_statement(iconnection&) = 0;
50+
};
51+
52+
53+
/**
54+
* connection - is a class that manages native driver connection handle.
55+
* connection object cannot be instantiated directly, only via driver
56+
* get_connection() function call. connection objects automatically delete the
57+
* native connection handle they manage as soon as they themselves are destroyed,
58+
* or as soon as their value changes by an assignment operation. When an
59+
* assignment operation takes place between two connection objects, ownership of
60+
* native connection handle is transferred, which means that the object losing
61+
* ownership is no longer has access to the native connection handle.
62+
*/
63+
class connection {
64+
65+
public:
66+
connection(connection&& conn) : conn_impl(std::move(conn.conn_impl))
67+
{
68+
}
69+
70+
connection& operator=(connection&& conn)
71+
{
72+
if (this != &conn)
73+
conn_impl = std::move(conn.conn_impl);
74+
return *this;
75+
}
76+
77+
~connection()
78+
{
79+
disconnect();
80+
}
81+
82+
bool connect()
83+
{
84+
return conn_impl->connect();
85+
}
86+
87+
void disconnect()
88+
{
89+
conn_impl->disconnect();
90+
}
91+
92+
void commit()
93+
{
94+
conn_impl->commit();
95+
}
96+
97+
void rollback()
98+
{
99+
conn_impl->rollback();
100+
}
101+
102+
bool connected() const
103+
{
104+
return conn_impl->connected();
105+
}
106+
107+
bool alive() const
108+
{
109+
return conn_impl->alive();
110+
}
111+
112+
statement get_statement()
113+
{
114+
return statement(conn_impl->get_statement(*(conn_impl.get())));
115+
}
116+
117+
template <typename T>
118+
T& get_native_connection()
119+
{
120+
return dynamic_cast<T&>(*conn_impl);
121+
}
122+
123+
private:
124+
template <typename T> friend class dbd::driver;
125+
friend class statement;
126+
127+
connection(iconnection* conn) : conn_impl(conn) { }
128+
connection(const connection&) = delete;
129+
connection& operator=(const connection&) = delete;
130+
131+
private:
132+
std::unique_ptr<iconnection> conn_impl;
133+
134+
}; // connection
135+
136+
} } } // namespace vgi::dbconn::dbi
137+
138+
#endif // CONNECTION_HPP
139+

driver.hpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* File: driver.hpp
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
*/
18+
19+
#ifndef DRIVER_HPP
20+
#define DRIVER_HPP
21+
22+
#include <memory>
23+
#include <functional>
24+
#include <map>
25+
#include "connection.hpp"
26+
27+
namespace vgi { namespace dbconn { namespace dbd {
28+
29+
/**
30+
* idriver - is an interface for driver classes which declares function for creating
31+
* a connection object
32+
*/
33+
struct idriver
34+
{
35+
virtual dbi::connection create_connection(dbi::iconnection* iconn) = 0;
36+
};
37+
38+
/**
39+
* driver is a singleton template class which creates a concrete driver on load()
40+
* and returns its instance
41+
*/
42+
template <typename T>
43+
class driver : public T
44+
{
45+
public:
46+
// c++11 guaranties no threading issues
47+
static T& load()
48+
{
49+
static driver<T> d;
50+
return d;
51+
}
52+
53+
protected:
54+
virtual dbi::connection create_connection(dbi::iconnection* iconn)
55+
{
56+
return dbi::connection(iconn);
57+
}
58+
59+
private:
60+
driver() {}
61+
driver(const driver&);
62+
driver(driver&&);
63+
driver& operator=(const driver&);
64+
driver& operator=(driver&&);
65+
driver** operator&();
66+
}; // driver
67+
68+
69+
}}} // namespace vgi::dbconn::dbd
70+
71+
#endif // DRIVER_HPP
72+

0 commit comments

Comments
 (0)