mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 15:51:32 +00:00

If an error occurs in mysql_real_query() it fell through and tried to get a result set anyway. This caused the MariaDB error message to be forgotten and a generic one returned instead. This fix returns the query error message and also uses the int error code for generic errors instead of casting it to an unsigned int.
98 lines
2.1 KiB
C++
98 lines
2.1 KiB
C++
/* Copyright (C) 2014 InfiniDB, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; version 2 of
|
|
the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
MA 02110-1301, USA. */
|
|
|
|
#ifndef UTILS_LIBMYSQL_CL_H
|
|
#define UTILS LIBMYSQL_CL_H
|
|
|
|
#include <my_config.h>
|
|
#include <mysql.h>
|
|
|
|
#include <boost/scoped_array.hpp>
|
|
|
|
namespace utils
|
|
{
|
|
|
|
class LibMySQL
|
|
{
|
|
public:
|
|
LibMySQL();
|
|
~LibMySQL();
|
|
|
|
// init: host port username passwd db
|
|
int init(const char*, unsigned int, const char*, const char*, const char*);
|
|
|
|
// run the query
|
|
int run(const char* q);
|
|
|
|
void handleMySqlError(const char*, int);
|
|
|
|
MYSQL* getMySqlCon()
|
|
{
|
|
return fCon;
|
|
}
|
|
int getFieldCount()
|
|
{
|
|
return mysql_num_fields(fRes);
|
|
}
|
|
int getRowCount()
|
|
{
|
|
return mysql_num_rows(fRes);
|
|
}
|
|
char** nextRow()
|
|
{
|
|
char** row = mysql_fetch_row(fRes);
|
|
fieldLengths = mysql_fetch_lengths(fRes);
|
|
fFields = mysql_fetch_fields(fRes);
|
|
return row;
|
|
}
|
|
long getFieldLength(int field)
|
|
{
|
|
return fieldLengths[field];
|
|
}
|
|
MYSQL_FIELD* getField(int field)
|
|
{
|
|
return &fFields[field];
|
|
}
|
|
const std::string& getError()
|
|
{
|
|
return fErrStr;
|
|
}
|
|
unsigned int getErrno()
|
|
{
|
|
return mysql_errno(fCon);
|
|
}
|
|
const char* getErrorMsg()
|
|
{
|
|
return mysql_error(fCon);
|
|
}
|
|
|
|
private:
|
|
MYSQL* fCon;
|
|
MYSQL_RES* fRes;
|
|
MYSQL_FIELD* fFields;
|
|
std::string fErrStr;
|
|
unsigned long* fieldLengths;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif // UTILS_LIBMYSQL_CL_H
|
|
|
|
// vim:ts=4 sw=4:
|