Skip to content

Commit b9c64a5

Browse files
committed
Implementing buffered/not buffered support
1 parent e98b371 commit b9c64a5

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ database bindings visit the [Node.js db-mysql homepage] [homepage].
77

88
Before proceeding with installation, you need to have the libmysql
99
development libraries and include files. Access to the mysql_config
10-
binary is mandatory, and has to be part of the path prior to
11-
installation. If the path to your mysql_config is
12-
/usr/local/bin/mysql_config make sure to do the following (Ubuntu
13-
users need to install the libmysqlclient-dev package):
10+
binary is mandatory, and its path has to be specified prior to
11+
installation (if its not within the system's path). For example, if
12+
the path to your mysql_config is /usr/local/bin/mysql_config make
13+
sure to do the following (Ubuntu users need to install the
14+
libmysqlclient-dev package):
1415

15-
$ export PATH=/usr/local/bin:$PATH
16+
$ export MYSQL_CONFIG=/usr/local/bin/mysql_config
1617

17-
Once you are sure mysql_config is part of the path, install with npm:
18+
Once you are sure that either mysql_config is part of the path or that
19+
you specified the MYSQL_CONFIG environment var, install with npm:
1820

1921
$ npm install db-mysql
2022

lib/node-db

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
, "description" : "MySQL database bindings for Node.JS"
33
, "keywords": ["database","db","native","binding","library","plugin","client","mysql","libmysql"]
44
, "homepage" : "http://nodejsdb.org/db-mysql"
5-
, "version" : "0.5.3"
5+
, "version" : "0.5.4"
66
, "engines" : { "node" : ">=0.4.1" }
77
, "maintainers" :
88
[ { "name": "Mariano Iglesias"

src/result.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ node_db::Result::Column::type_t node_db_mysql::Result::Column::getType() const {
7070
node_db_mysql::Result::Result(MYSQL* connection, MYSQL_RES* result) throw(node_db::Exception&)
7171
: columns(NULL),
7272
totalColumns(0),
73-
totalRows(0),
7473
rowNumber(0),
7574
connection(connection),
7675
result(result),
@@ -85,7 +84,6 @@ node_db_mysql::Result::Result(MYSQL* connection, MYSQL_RES* result) throw(node_d
8584
throw node_db::Exception("Could not buffer columns");
8685
}
8786

88-
this->totalRows = mysql_num_rows(this->result);
8987
this->totalColumns = mysql_num_fields(this->result);
9088
if (this->totalColumns > 0) {
9189
this->columns = new Column*[this->totalColumns];
@@ -117,7 +115,7 @@ bool node_db_mysql::Result::hasNext() const {
117115
return (this->nextRow != NULL);
118116
}
119117

120-
const char** node_db_mysql::Result::next() throw(node_db::Exception&) {
118+
char** node_db_mysql::Result::next() throw(node_db::Exception&) {
121119
if (this->nextRow == NULL) {
122120
return NULL;
123121
}
@@ -126,7 +124,7 @@ const char** node_db_mysql::Result::next() throw(node_db::Exception&) {
126124
this->previousRow = this->nextRow;
127125
this->nextRow = this->row();
128126

129-
return (const char**) this->previousRow;
127+
return this->previousRow;
130128
}
131129

132130
unsigned long* node_db_mysql::Result::columnLengths() throw(node_db::Exception&) {
@@ -167,6 +165,13 @@ uint16_t node_db_mysql::Result::columnCount() const {
167165
return this->totalColumns;
168166
}
169167

170-
uint64_t node_db_mysql::Result::count() const throw() {
171-
return this->totalRows;
168+
uint64_t node_db_mysql::Result::count() const throw(node_db::Exception&) {
169+
if (!this->isBuffered()) {
170+
throw node_db::Exception("Result is not buffered");
171+
}
172+
return mysql_num_rows(this->result);
173+
}
174+
175+
bool node_db_mysql::Result::isBuffered() const throw() {
176+
return (!this->result->handle || this->result->handle->status != MYSQL_STATUS_USE_RESULT);
172177
}

src/result.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ class Result : public node_db::Result {
2828
explicit Result(MYSQL* connection, MYSQL_RES* result) throw(node_db::Exception&);
2929
~Result();
3030
bool hasNext() const;
31-
const char** next() throw(node_db::Exception&);
31+
char** next() throw(node_db::Exception&);
3232
unsigned long* columnLengths() throw(node_db::Exception&);
3333
uint64_t index() const throw(std::out_of_range&);
3434
Column* column(uint16_t i) const throw(std::out_of_range&);
3535
uint64_t insertId() const;
3636
uint16_t columnCount() const;
3737
uint64_t affectedCount() const;
3838
uint16_t warningCount() const;
39-
uint64_t count() const throw();
39+
uint64_t count() const throw(node_db::Exception&);
40+
bool isBuffered() const throw();
4041

4142
protected:
42-
Column **columns;
43+
Column** columns;
4344
uint16_t totalColumns;
44-
uint64_t totalRows;
4545
uint64_t rowNumber;
4646

47-
char **row() throw(node_db::Exception&);
47+
char** row() throw(node_db::Exception&);
4848

4949
private:
5050
MYSQL* connection;

wscript

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ from os.path import exists
1111

1212
srcdir = "."
1313
blddir = "build"
14-
VERSION = "0.5.3"
14+
VERSION = "0.5.4"
1515

1616
def set_options(opt):
1717
opt.tool_options("compiler_cxx")
18-
opt.add_option('--mysql-config', action='store', default='mysql_config', help='Path to mysql_config, e.g. /usr/bin/mysql_config')
1918
opt.add_option('--debug', action='store_true', help='Run tests with nodeunit_g')
2019
opt.add_option('--warn', action='store_true', help='Enable extra -W* compiler flags')
2120

@@ -32,17 +31,11 @@ def configure(conf):
3231
conf.env.append_unique('CXXFLAGS', ["-Wconversion", "-Wshadow", "-Wsign-conversion", "-Wunreachable-code", "-Wredundant-decls", "-Wcast-qual"])
3332

3433
# MySQL flags and libraries
35-
mysql_config = conf.find_program(Options.options.mysql_config, mandatory=True)
34+
mysql_config = conf.find_program('mysql_config', var='MYSQL_CONFIG', mandatory=True)
35+
3636
conf.env.append_unique('CXXFLAGS', Utils.cmd_output(mysql_config + ' --include').split())
3737
conf.env.append_unique('LINKFLAGS', Utils.cmd_output(mysql_config + ' --libs_r').split())
38-
39-
if not conf.check_cxx(lib="mysqlclient_r", errmsg="not found, try to find nonthreadsafe libmysqlclient"):
40-
# link flags are needed to find the libraries
41-
conf.env.append_unique('LINKFLAGS', Utils.cmd_output(mysql_config + ' --libs').split())
42-
if conf.check_cxx(lib="mysqlclient"):
43-
conf.env.append_unique('CXXDEFINES', ["MYSQL_NON_THREADSAFE"])
44-
else:
45-
conf.fatal("Missing both libmysqlclient_r and libmysqlclient from libmysqlclient-devel or mysql-devel package")
38+
conf.check_cxx(lib="mysqlclient_r", errmsg="Missing libmysqlclient_r")
4639

4740
def build(bld):
4841
obj = bld.new_task_gen("cxx", "shlib", "node_addon")

0 commit comments

Comments
 (0)