@@ -67,36 +67,40 @@ node_db::Result::Column::type_t node_db_mysql::Result::Column::getType() const {
67
67
return this ->type ;
68
68
}
69
69
70
- node_db_mysql::Result::Result (MYSQL* connection, MYSQL_RES* result ) throw(node_db::Exception&)
70
+ node_db_mysql::Result::Result (MYSQL* connection) throw(node_db::Exception&)
71
71
: columns(NULL ),
72
72
totalColumns(0 ),
73
73
rowNumber(0 ),
74
+ empty(true ),
74
75
connection(connection),
75
- result(result),
76
76
previousRow(NULL ),
77
77
nextRow(NULL ) {
78
- if (this ->result == NULL ) {
79
- throw node_db::Exception (" Invalid result" );
80
- }
81
78
82
- MYSQL_FIELD* fields = mysql_fetch_fields (this ->result );
83
- if (fields == NULL ) {
84
- throw node_db::Exception (" Could not buffer columns" );
85
- }
79
+ this ->result = mysql_store_result (this ->connection );
80
+ if (result == NULL && mysql_field_count (this ->connection ) != 0 ) {
81
+ throw node_db::Exception (mysql_error (this ->connection ));
82
+ } else if (result != NULL ) {
83
+ this ->empty = false ;
86
84
87
- this ->totalColumns = mysql_num_fields (this ->result );
88
- if (this ->totalColumns > 0 ) {
89
- this ->columns = new Column*[this ->totalColumns ];
90
- if (this ->columns == NULL ) {
91
- throw node_db::Exception (" Could not allocate storage for columns" );
85
+ MYSQL_FIELD* fields = mysql_fetch_fields (this ->result );
86
+ if (fields == NULL ) {
87
+ throw node_db::Exception (" Could not buffer columns" );
92
88
}
93
89
94
- for (uint16_t i = 0 ; i < this ->totalColumns ; i++) {
95
- this ->columns [i] = new Column (fields[i]);
90
+ this ->totalColumns = mysql_num_fields (this ->result );
91
+ if (this ->totalColumns > 0 ) {
92
+ this ->columns = new Column*[this ->totalColumns ];
93
+ if (this ->columns == NULL ) {
94
+ throw node_db::Exception (" Could not allocate storage for columns" );
95
+ }
96
+
97
+ for (uint16_t i = 0 ; i < this ->totalColumns ; i++) {
98
+ this ->columns [i] = new Column (fields[i]);
99
+ }
96
100
}
97
- }
98
101
99
- this ->nextRow = this ->row ();
102
+ this ->nextRow = this ->row ();
103
+ }
100
104
}
101
105
102
106
node_db_mysql::Result::~Result () {
@@ -175,3 +179,7 @@ uint64_t node_db_mysql::Result::count() const throw(node_db::Exception&) {
175
179
bool node_db_mysql::Result::isBuffered () const throw() {
176
180
return (!this ->result ->handle || this ->result ->handle ->status != MYSQL_STATUS_USE_RESULT);
177
181
}
182
+
183
+ bool node_db_mysql::Result::isEmpty () const throw() {
184
+ return this ->empty ;
185
+ }
0 commit comments