Skip to content

Commit 33eb670

Browse files
committed
Added stored proc and cursor, minor changes to interface
1 parent 798c866 commit 33eb670

File tree

9 files changed

+1105
-418
lines changed

9 files changed

+1105
-418
lines changed

Makefile_12.5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ INCLUDES = -I/opt/sybase12_5_64/OCS/include
88

99
# compiler path and flags
1010
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
11+
CFLAGS = -std=c++1y -Wall -Wno-unused -Wno-sequence-point -Wno-parentheses -c -ggdb3 -m64 -pthread -DSYB_LP64 -D_REENTRANT
1212

1313
# sybase libraries to include in the build
1414
CTLIB = -lct_r64 # client library

Makefile_15.0

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ INCLUDES = -I/opt/sybase15/OCS-15_0/include
88

99
# compiler path and flags
1010
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
11+
CFLAGS = -std=c++1y -Wall -Wno-unused -Wno-sequence-point -Wno-parentheses -c -ggdb3 -m64 -pthread -DSYB_LP64 -D_REENTRANT
1212

1313
# sybase libraries to include in the build
1414
CTLIB = -lsybct64 # client library

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ Header files based C++ database connection library.
33

44
This project is to create an easy to use, database agnostic, modular, and easily extendable C++ database connection library.
55

6-
At the moment this is work in progress and not a production-ready code that may have bugs!
7-
8-
Currently only a limited featured native Sybase driver is implemented, see sybase_example.cpp
6+
Currently only a native Sybase ASE driver is implemented, see sybase_example.cpp
97

108
If someone would like to contribute please ping me.
119

12-
TODO:
13-
- add support for more data types, stored procs, and cursor to Sybase driver
14-
- write unit tests
15-
- eventually add support for more databases

connection.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#define CONNECTION_HPP
2121

2222
#include <memory>
23-
#include "utilities.hpp"
24-
#include "driver.hpp"
2523
#include "statement.hpp"
2624

2725
// forward declaration
@@ -110,8 +108,8 @@ class connection {
110108
}
111109

112110
/**
113-
* Function sets autocommit option, default is 'true'
114-
* @param ac - true to set autocommit ON, false - OFF
111+
* Function sets auto-commit option, default is 'true'
112+
* @param ac - true to set auto-commit ON, false - OFF
115113
*/
116114
void autocommit(bool ac)
117115
{

driver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ template <typename T>
4343
class driver : public T
4444
{
4545
public:
46-
// c++11 guaranties no threading issues
46+
// c++1y guarantees no threading issues
4747
static T& load()
4848
{
4949
static driver<T> d;

result_set.hpp

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef RESULT_SET_HPP
2020
#define RESULT_SET_HPP
2121

22+
#include "utilities.hpp"
23+
2224
namespace vgi { namespace dbconn { namespace dbi {
2325

2426
class statement;
@@ -37,6 +39,9 @@ struct iresult_set
3739
virtual size_t rows_affected() const = 0;
3840
virtual size_t column_count() const = 0;
3941
virtual bool next() = 0;
42+
virtual bool prev() = 0;
43+
virtual bool first() = 0;
44+
virtual bool last() = 0;
4045
virtual std::string column_name(size_t col_idx) = 0;
4146
virtual int column_index(const std::string& col_name) = 0;
4247
virtual bool is_null(size_t col_idx) = 0;
@@ -48,7 +53,6 @@ struct iresult_set
4853
virtual uint64_t get_ulong(size_t col_idx) = 0;
4954
virtual float get_float(size_t col_idx) = 0;
5055
virtual double get_double(size_t col_idx) = 0;
51-
virtual long double get_ldouble(size_t col_idx) = 0;
5256
virtual bool get_bool(size_t col_idx) = 0;
5357
virtual char get_char(size_t col_idx) = 0;
5458
virtual std::string get_string(size_t col_idx) = 0;
@@ -57,8 +61,7 @@ struct iresult_set
5761
virtual time_t get_datetime(size_t col_idx) = 0;
5862
virtual char16_t get_unichar(size_t col_idx) = 0;
5963
virtual std::u16string get_unistring(size_t col_idx) = 0;
60-
virtual std::vector<uint8_t> get_image(size_t col_idx) = 0;
61-
// TODO: add xml, binary, money, lob
64+
virtual std::vector<uint8_t> get_binary(size_t col_idx) = 0;
6265
};
6366

6467

@@ -165,8 +168,8 @@ class result_set
165168

166169
/**
167170
* Function returns column name by column index or throws an exception if
168-
* index is invalid
169-
* @param col_idx
171+
* index is invalid
172+
* @param col_idx
170173
* @return column name string or exception is thrown if index is invalid
171174
*/
172175
const std::string column_name(size_t col_idx)
@@ -194,6 +197,36 @@ class result_set
194197
return rs_impl->next();
195198
}
196199

200+
/**
201+
* Function moves iterator to the previous row of the current result data set
202+
* This function can only be used with scrollable cursor.
203+
* @return true on success, or false if there is no more rows
204+
*/
205+
bool prev()
206+
{
207+
return rs_impl->prev();
208+
}
209+
210+
/**
211+
* Function moves iterator to the first row of the current result data set
212+
* This function can only be used with scrollable cursor.
213+
* @return true on success, or false if there is no more rows
214+
*/
215+
bool first()
216+
{
217+
return rs_impl->first();
218+
}
219+
220+
/**
221+
* Function moves iterator to the last row of the current result data set
222+
* This function can only be used with scrollable cursor.
223+
* @return true on success, or false if there is no more rows
224+
*/
225+
bool last()
226+
{
227+
return rs_impl->last();
228+
}
229+
197230
/**
198231
* Function checks if cell data is NULL by column index or throws an exception
199232
* if index is invalid.
@@ -235,8 +268,6 @@ class result_set
235268
float get_type_by_name(float);
236269
double get_type_by_index(double);
237270
double get_type_by_name(double);
238-
long double get_type_by_index(ldouble);
239-
long double get_type_by_name(ldouble);
240271
bool get_type_by_index(bool);
241272
bool get_type_by_name(bool);
242273
char get_type_by_index(char);
@@ -253,8 +284,8 @@ class result_set
253284
char16_t get_type_by_name(unichar);
254285
std::u16string get_type_by_index(unistring);
255286
std::u16string get_type_by_name(unistring);
256-
std::vector<uint8_t> get_type_by_index(image);
257-
std::vector<uint8_t> get_type_by_name(image);
287+
std::vector<uint8_t> get_type_by_index(binary);
288+
std::vector<uint8_t> get_type_by_name(binary);
258289

259290

260291
private:

statement.hpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ struct istatement
3333
{
3434
virtual ~istatement() { };
3535
virtual void prepare(const std::string& sql) = 0;
36-
virtual iresult_set* execute(const std::string& sql) = 0;
36+
virtual void call(const std::string& sql) = 0;
37+
virtual iresult_set* execute(const std::string& sql, bool cursor = false, bool scrollable = false) = 0;
3738
virtual iresult_set* execute() = 0;
3839
virtual bool cancel() = 0;
39-
virtual bool cancel_all() = 0;
40+
virtual int proc_retval() = 0;
4041
virtual void set_null(size_t col_idx) = 0;
4142
virtual void set_short(size_t col_idx, int16_t val) = 0;
4243
virtual void set_ushort(size_t col_idx, uint16_t val) = 0;
@@ -46,7 +47,6 @@ struct istatement
4647
virtual void set_ulong(size_t col_idx, uint64_t val) = 0;
4748
virtual void set_float(size_t col_idx, float val) = 0;
4849
virtual void set_double(size_t col_idx, double val) = 0;
49-
virtual void set_ldouble(size_t col_idx, long double val) = 0;
5050
virtual void set_bool(size_t col_idx, bool val) = 0;
5151
virtual void set_char(size_t col_idx, char val) = 0;
5252
virtual void set_string(size_t col_idx, const std::string& val) = 0;
@@ -55,7 +55,7 @@ struct istatement
5555
virtual void set_datetime(size_t col_idx, time_t val) = 0;
5656
virtual void set_unichar(size_t col_idx, char16_t val) = 0;
5757
virtual void set_unistring(size_t col_idx, const std::u16string& val) = 0;
58-
virtual void set_image(size_t col_idx, const std::vector<uint8_t>& val) = 0;
58+
virtual void set_binary(size_t col_idx, const std::vector<uint8_t>& val) = 0;
5959
};
6060

6161

@@ -101,6 +101,15 @@ class statement
101101
stmt_impl->prepare(sql);
102102
}
103103

104+
/**
105+
* Function prepares SQL stored procedure
106+
* @param sql stored procedure to be executed
107+
*/
108+
void call(const std::string& proc)
109+
{
110+
stmt_impl->call(proc);
111+
}
112+
104113
/**
105114
* Function runs last executed SQL statement
106115
* @return result set object
@@ -113,22 +122,35 @@ class statement
113122
/**
114123
* Function runs SQL statement
115124
* @param sql statement to be executed
125+
* @param cursor = true to use cursor with select statements
126+
* @param scrollable = true to use scrollable cursor
116127
* @return result set object
117128
*/
118-
result_set execute(const std::string& sql)
129+
result_set execute(const std::string& sql, bool cursor = false, bool scrollable = false)
119130
{
120-
return result_set(stmt_impl->execute(sql));
131+
return result_set(stmt_impl->execute(sql, cursor, scrollable));
121132
}
122133

123134
/**
124-
* Function cancels currently running SQL statement
135+
* Function cancels currently running SQL statements
125136
* @return true if canceled, false otherwise
126137
*/
127138
bool cancel()
128139
{
129140
return stmt_impl->cancel();
130141
}
131142

143+
/**
144+
* Function returns stored procedure return value.
145+
* This function must be called after all result sets from stored proc select
146+
* statements had been processed
147+
* @return int
148+
*/
149+
int proc_retval()
150+
{
151+
return stmt_impl->proc_retval();
152+
}
153+
132154
virtual void set_null(size_t col_idx)
133155
{
134156
stmt_impl->set_null(col_idx);
@@ -174,11 +196,6 @@ class statement
174196
stmt_impl->set_double(col_idx, val);
175197
}
176198

177-
virtual void set_ldouble(size_t col_idx, long double val)
178-
{
179-
stmt_impl->set_ldouble(col_idx, val);
180-
}
181-
182199
virtual void set_bool(size_t col_idx, bool val)
183200
{
184201
stmt_impl->set_bool(col_idx, val);
@@ -219,11 +236,10 @@ class statement
219236
stmt_impl->set_unistring(col_idx, val);
220237
}
221238

222-
virtual void set_image(size_t col_idx, const std::vector<uint8_t>& val)
239+
virtual void set_binary(size_t col_idx, const std::vector<uint8_t>& val)
223240
{
224-
stmt_impl->set_image(col_idx, val);
241+
stmt_impl->set_binary(col_idx, val);
225242
}
226-
// TODO: add xml, binary, money, lob
227243

228244
private:
229245
friend class connection;

0 commit comments

Comments
 (0)