Skip to content

Commit e2b8df6

Browse files
committed
session support
1 parent 785c4f0 commit e2b8df6

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

prebuilds/linux-x64/node.napi.node

272 Bytes
Binary file not shown.

src/addon.cc

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ char *Execute(char *query, char *format) {
2020
// Query - 10 characters + length of query
2121
localQuery = (char *) malloc(strlen(query)+10);
2222
if(localQuery == NULL) {
23-
23+
2424
printf("Out of memmory\n");
2525
return NULL;
2626
}
27-
27+
2828
sprintf(localQuery, "--query=%s", query);
2929
argv[3]=strdup(localQuery);
3030
free(localQuery);
@@ -41,7 +41,7 @@ char *Execute(char *query, char *format) {
4141

4242
char *ExecuteSession(char *query, char *format, char *path) {
4343

44-
char * argv[] = {(char *)"clickhouse", (char *)"--multiquery", (char *)"--output-format=CSV", (char *)"--query=", (char *)"--path="};
44+
char * argv[] = {(char *)"clickhouse", (char *)"--multiquery", (char *)"--output-format=CSV", (char *)"--query=", (char *)"--path=."};
4545
char dataFormat[100];
4646
char dataPath[100];
4747
char *localQuery;
@@ -50,7 +50,7 @@ char *ExecuteSession(char *query, char *format, char *path) {
5050
struct local_result *result;
5151

5252
// Format
53-
snprintf(dataFormat, sizeof(dataFormat), "--format=%s", format);
53+
snprintf(dataFormat, sizeof(dataFormat), "--output-format=%s", format);
5454
argv[2]=strdup(dataFormat);
5555

5656
// Query - 10 characters + length of query
@@ -67,16 +67,22 @@ char *ExecuteSession(char *query, char *format, char *path) {
6767

6868
// Path
6969
snprintf(dataPath, sizeof(dataPath), "--path=%s", path);
70-
argv[4]=strdup(dataFormat);
70+
argv[4]=strdup(dataPath);
7171

7272
// Main query and result
7373
result = query_stable(argc, argv);
7474

7575
//Free it
7676
free(argv[2]);
7777
free(argv[3]);
78+
free(argv[4]);
7879

79-
return result->buf;
80+
81+
if (result == NULL) {
82+
return NULL;
83+
} else {
84+
return result->buf;
85+
}
8086
}
8187

8288
Napi::Value ExecuteWrapped(const Napi::CallbackInfo& info) {
@@ -104,7 +110,7 @@ Napi::Value ExecuteWrapped(const Napi::CallbackInfo& info) {
104110
Napi::Value SessionWrapped(const Napi::CallbackInfo& info) {
105111
Napi::Env env = info.Env();
106112

107-
if (info.Length() < 2 || !info[0].IsString() || !info[1].IsString()) {
113+
if (info.Length() < 3 || !info[0].IsString() || !info[1].IsString() || !info[2].IsString()) {
108114
Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException();
109115
return env.Null();
110116
}
@@ -115,8 +121,9 @@ Napi::Value SessionWrapped(const Napi::CallbackInfo& info) {
115121

116122
char *result = ExecuteSession((char *)query.c_str(), (char *)format.c_str(), (char *)path.c_str());
117123
if (result == NULL) {
118-
Napi::TypeError::New(env, "Out of memory").ThrowAsJavaScriptException();
119-
return env.Null();
124+
Napi::String returnValue = Napi::String::New(env, "");
125+
return returnValue;
126+
// return env.Null();
120127
}
121128

122129
Napi::String returnValue = Napi::String::New(env, result);

0 commit comments

Comments
 (0)