|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "libaquery.h"
|
|
|
|
#include "libaquery.h"
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "monetdb_conn.h"
|
|
|
|
#include "monetdb_conn.h"
|
|
|
|
#include "monetdbe.h"
|
|
|
|
#include "monetdbe.h"
|
|
|
|
#include "table.h"
|
|
|
|
#include "table.h"
|
|
|
@ -35,9 +36,19 @@ const unsigned char monetdbe_type_szs[] = {
|
|
|
|
// should be last:
|
|
|
|
// should be last:
|
|
|
|
1
|
|
|
|
1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace types{
|
|
|
|
|
|
|
|
const Type_t monetdbe_type_aqtypes[] = {
|
|
|
|
|
|
|
|
ABOOL, AINT8, AINT16, AINT32, AINT64,
|
|
|
|
|
|
|
|
#ifdef HAVE_HGE
|
|
|
|
|
|
|
|
AINT128,
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
AUINT64, AFLOAT, ADOUBLE, ASTR,
|
|
|
|
|
|
|
|
// blob?
|
|
|
|
|
|
|
|
AINT64,
|
|
|
|
|
|
|
|
ADATE, ATIME, ATIMESTAMP, ERROR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
Server::Server(Context* cxt){
|
|
|
|
Server::Server(Context* cxt){
|
|
|
|
if (cxt){
|
|
|
|
if (cxt){
|
|
|
|
connect(cxt);
|
|
|
|
connect(cxt);
|
|
|
@ -80,7 +91,7 @@ void Server::connect(Context *cxt){
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
if(server)
|
|
|
|
if(server)
|
|
|
|
free(server);
|
|
|
|
free(server);
|
|
|
|
this->server = 0;
|
|
|
|
this->server = nullptr;
|
|
|
|
status = false;
|
|
|
|
status = false;
|
|
|
|
puts(ret == -1 ? "Allocation Error." : "Internal Database Error.");
|
|
|
|
puts(ret == -1 ? "Allocation Error." : "Internal Database Error.");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -103,20 +114,58 @@ void Server::exec(const char* q){
|
|
|
|
|
|
|
|
|
|
|
|
bool Server::haserror(){
|
|
|
|
bool Server::haserror(){
|
|
|
|
if (last_error){
|
|
|
|
if (last_error){
|
|
|
|
last_error = 0;
|
|
|
|
last_error = nullptr;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Server::print_results(const char* sep, const char* end){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!haserror()){
|
|
|
|
|
|
|
|
auto _res = static_cast<monetdbe_result*> (res);
|
|
|
|
|
|
|
|
const auto& ncols = _res->ncols;
|
|
|
|
|
|
|
|
monetdbe_column** cols = static_cast<monetdbe_column**>(malloc(sizeof(monetdbe_column*) * ncols));
|
|
|
|
|
|
|
|
std::string* printf_string = new std::string[ncols];
|
|
|
|
|
|
|
|
const char** col_data = static_cast<const char**> (malloc(sizeof(char*) * ncols));
|
|
|
|
|
|
|
|
uint8_t* szs = static_cast<uint8_t*>(alloca(ncols));
|
|
|
|
|
|
|
|
std::string header_string = "";
|
|
|
|
|
|
|
|
const char* err_msg = nullptr;
|
|
|
|
|
|
|
|
for(uint32_t i = 0; i < ncols; ++i){
|
|
|
|
|
|
|
|
err_msg = monetdbe_result_fetch(_res, &cols[i], i);
|
|
|
|
|
|
|
|
printf_string[i] =
|
|
|
|
|
|
|
|
std::string(types::printf_str[types::monetdbe_type_aqtypes[cols[i]->type]])
|
|
|
|
|
|
|
|
+ (i < ncols - 1 ? sep : "");
|
|
|
|
|
|
|
|
puts(printf_string[i].c_str());
|
|
|
|
|
|
|
|
col_data[i] = static_cast<char *>(cols[i]->data);
|
|
|
|
|
|
|
|
szs [i] = monetdbe_type_szs[cols[i]->type];
|
|
|
|
|
|
|
|
header_string = header_string + cols[i]->name + sep + '|' + sep;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t l_sep = strlen(sep) + 1;
|
|
|
|
|
|
|
|
if (header_string.size() - l_sep >= 0)
|
|
|
|
|
|
|
|
header_string.resize(header_string.size() - l_sep);
|
|
|
|
|
|
|
|
header_string += end + std::string(header_string.size(), '=') + end;
|
|
|
|
|
|
|
|
fputs(header_string.c_str(), stdout);
|
|
|
|
|
|
|
|
for(uint64_t i = 0; i < cnt; ++i){
|
|
|
|
|
|
|
|
for(uint32_t j = 0; j < ncols; ++j){
|
|
|
|
|
|
|
|
printf(printf_string[j].c_str(), *((void**)col_data[j]));
|
|
|
|
|
|
|
|
col_data[j] += szs[j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs(end, stdout);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
free(cols);
|
|
|
|
|
|
|
|
delete[] printf_string;
|
|
|
|
|
|
|
|
free(col_data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Server::close(){
|
|
|
|
void Server::close(){
|
|
|
|
if(this->server){
|
|
|
|
if(this->server){
|
|
|
|
auto server = static_cast<monetdbe_database*>(this->server);
|
|
|
|
auto server = static_cast<monetdbe_database*>(this->server);
|
|
|
|
monetdbe_close(*(server));
|
|
|
|
monetdbe_close(*(server));
|
|
|
|
free(server);
|
|
|
|
free(server);
|
|
|
|
this->server = 0;
|
|
|
|
this->server = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -140,7 +189,7 @@ void* Server::getCol(int col_idx){
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
puts("Error: No result.");
|
|
|
|
puts("Error: No result.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Server::~Server(){
|
|
|
|
Server::~Server(){
|
|
|
|