main.c 15.8 KB
Newer Older
1 2 3 4 5
#include "../src/todbc_log.h"

#ifdef _MSC_VER
#include <winsock2.h>
#include <windows.h>
F
freemine 已提交
6
#include "os.h"
7
#endif
F
freemine 已提交
8
#include <sql.h>
F
freemine 已提交
9
#include <sqlext.h>
F
freemine 已提交
10 11

#include <stdio.h>
F
freemine 已提交
12
#include <string.h>
F
freemine 已提交
13

F
freemine 已提交
14 15 16 17 18 19 20 21
#define CHK_TEST(statement)                       \
do {                                              \
  D("testing: %s", #statement);                   \
  int r = (statement);                            \
  if (r) return 1;                                \
} while (0);


F
freemine 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
typedef struct data_s            data_t;
struct data_s {
  int64_t                 ts;
  int8_t                  b;
  int8_t                  v1;
  int16_t                 v2;
  int32_t                 v4;
  int64_t                 v8;
  float                   f4;
  double                  f8;
  char                    bin[40+1];
  char                    blob[40+1]; // why 80?  ref: tests/examples/c/apitest.c
};

static const char *pre_stmts[] = {
  "create database db",
  "use db",
  "create table t (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10))"
};

static const char *pro_stmts[] = {
  // "insert into t values ('2019-07-15 00:00:00', 1)",
  // "insert into t values ('2019-07-15 01:00:00', 2)",
  "select * from t"
  // "drop database db"
};

F
freemine 已提交
49
#define CHK_RESULT(r, ht, h, fmt, ...)                                          \
F
freemine 已提交
50 51 52 53 54 55 56 57 58 59
do {                                                                            \
  if (r==0) break;                                                              \
  SQLCHAR      ss[10];                                                          \
  SQLINTEGER   ne = 0;                                                          \
  SQLCHAR      es[4096];                                                        \
  SQLSMALLINT  n  = 0;                                                          \
  ss[0] = '\0';                                                                 \
  es[0] = '\0';                                                                 \
  SQLRETURN ret = SQLGetDiagRec(ht, h, 1, ss, &ne, es, sizeof(es), &n);         \
  if (ret) break;                                                               \
F
freemine 已提交
60
  D("[%s]%s: " fmt "", ss, es, ##__VA_ARGS__);                                  \
F
freemine 已提交
61 62
} while (0)

F
freemine 已提交
63 64 65 66 67 68 69 70 71 72 73
static int open_connect(const char *dsn, const char *uid, const char *pwd, SQLHENV *pEnv, SQLHDBC *pConn) {
  SQLRETURN r;
  SQLHENV env = {0};
  SQLHDBC conn = {0};
  r = SQLAllocEnv(&env);
  if (r!=SQL_SUCCESS) return 1;
  do {
    r = SQLAllocConnect(env, &conn);
    CHK_RESULT(r, SQL_HANDLE_ENV, env, "");
    if (r!=SQL_SUCCESS) break;
    do {
74 75 76
      r = SQLConnect(conn, (SQLCHAR*)dsn, (SQLSMALLINT)strlen(dsn),
                           (SQLCHAR*)uid, (SQLSMALLINT)strlen(uid),
                           (SQLCHAR*)pwd, (SQLSMALLINT)strlen(pwd));
F
freemine 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
      CHK_RESULT(r, SQL_HANDLE_DBC, conn, "");
      if (r==SQL_SUCCESS) {
        *pEnv  = env;
        *pConn = conn;
        return 0;
      }
    } while (0);
    SQLFreeConnect(conn);
  } while (0);
  SQLFreeEnv(env);

  return 1;
}

static int open_driver_connect(const char *connstr, SQLHENV *pEnv, SQLHDBC *pConn) {
  SQLRETURN r;
  SQLHENV env = {0};
  SQLHDBC conn = {0};
  r = SQLAllocEnv(&env);
  if (r!=SQL_SUCCESS) return 1;
  do {
    r = SQLAllocConnect(env, &conn);
    CHK_RESULT(r, SQL_HANDLE_ENV, env, "");
    if (r!=SQL_SUCCESS) break;
    do {
      SQLCHAR buf[4096];
      SQLSMALLINT blen = 0;
      SQLHDBC         ConnectionHandle      = conn;
      SQLHWND         WindowHandle          = NULL;
      SQLCHAR *       InConnectionString    = (SQLCHAR*)connstr;
107
      SQLSMALLINT     StringLength1         = (SQLSMALLINT)strlen(connstr);
F
freemine 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
      SQLCHAR *       OutConnectionString   = buf;
      SQLSMALLINT     BufferLength          = sizeof(buf);
      SQLSMALLINT *   StringLength2Ptr      = &blen;
      SQLUSMALLINT    DriverCompletion      = SQL_DRIVER_NOPROMPT;
      r = SQLDriverConnect(ConnectionHandle, WindowHandle, InConnectionString,
                           StringLength1, OutConnectionString, BufferLength,
                           StringLength2Ptr, DriverCompletion);
      CHK_RESULT(r, SQL_HANDLE_DBC, conn, "");
      if (r==SQL_SUCCESS) {
        *pEnv  = env;
        *pConn = conn;
        return 0;
      }
    } while (0);
    SQLFreeConnect(conn);
  } while (0);
  SQLFreeEnv(env);

  return 1;
}
F
freemine 已提交
128 129 130
static int do_statement(SQLHSTMT stmt, const char *statement) {
  SQLRETURN r = 0;
  do {
F
freemine 已提交
131 132
    r = SQLExecDirect(stmt, (SQLCHAR*)statement, SQL_NTS);
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: [%s]", statement);
F
freemine 已提交
133
    if (r) break;
F
freemine 已提交
134 135 136
    SQLSMALLINT cols = 0;
    r = SQLNumResultCols(stmt, &cols);
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "");
F
freemine 已提交
137
    if (r) break;
F
freemine 已提交
138 139 140 141 142 143 144 145
    if (cols <= 0) break;
    char buf[4096];
    while (1) {
      SQLRETURN r = SQLFetch(stmt);
      if (r==SQL_NO_DATA) break;
      CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "");
      for (size_t i=0; i<cols; ++i) {
        SQLLEN soi = 0;
146
        r = SQLGetData(stmt, (SQLUSMALLINT)(i+1), SQL_C_CHAR, buf, sizeof(buf), &soi);
F
freemine 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
        CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "");
        if (r) {
          if (r!=SQL_SUCCESS_WITH_INFO) {
            if (i>0) fprintf(stdout, "\n");
            return r;
          }
        }
        if (soi==SQL_NULL_DATA) {
          fprintf(stdout, "%snull", i==0?"":",");
        } else {
          fprintf(stdout, "%s\"%s\"", i==0?"":",", buf);
        }
      }
      fprintf(stdout, "\n");
    }

    // r = SQLFetch(stmt);
    // if (r==SQL_NO_DATA) {
    //   D("..........");
    //   r = SQL_SUCCESS;
    //   break;
    // }
    // CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "");
    // if (r) break;
    // r = SQLPrepare(stmt, (SQLCHAR*)statement, strlen(statement));
    // CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "");
    // if (r) break;
    // r = SQLExecute(stmt);
    // CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
    // if (r) break;
F
freemine 已提交
177 178 179 180 181 182 183 184 185 186
  } while (0);
  return r;
}

static int do_insert(SQLHSTMT stmt, data_t data) {
  SQLRETURN r = 0;
  SQLLEN 		lbin;
  SQLLEN    lblob;

  const char *statement = "insert into t values (?, ?, ?, ?, ?, ?, ?, ?, ?,?)";
187
  #define ignored 0
F
freemine 已提交
188 189

  do {
190
    r = SQLPrepare(stmt, (SQLCHAR*)statement, (SQLINTEGER)strlen(statement));
F
freemine 已提交
191
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
192 193
    if (r) break;

194
    r = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_TIMESTAMP, ignored, ignored, &data.ts, ignored, NULL);
F
freemine 已提交
195
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
196 197
    if (r) break;

198
    r = SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_BIT, SQL_BIT, ignored, ignored, &data.b, ignored, NULL);
F
freemine 已提交
199
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
200 201
    if (r) break;

202
    r = SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_TINYINT, SQL_TINYINT, ignored, ignored, &data.v1, ignored, NULL);
F
freemine 已提交
203
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
204 205
    if (r) break;

206
    r = SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_SHORT, SQL_SMALLINT, ignored, ignored, &data.v2, ignored, NULL);
F
freemine 已提交
207
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
208 209
    if (r) break;

210
    r = SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, ignored, ignored, &data.v4, ignored, NULL);
F
freemine 已提交
211
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
212 213
    if (r) break;

214
    r = SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_BIGINT, ignored, ignored, &data.v8, ignored, NULL);
F
freemine 已提交
215
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
216 217
    if (r) break;

218
    r = SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, ignored, ignored, &data.f4, ignored, NULL);
F
freemine 已提交
219
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
220 221
    if (r) break;

222
    r = SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, ignored, ignored, &data.f8, ignored, NULL);
F
freemine 已提交
223
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
224 225 226
    if (r) break;

    lbin = SQL_NTS;
227
    r = SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, sizeof(data.bin)-1, ignored, &data.bin, ignored, &lbin);
F
freemine 已提交
228
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
229 230 231
    if (r) break;

    lblob = SQL_NTS;
232
    r = SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(data.blob)-1, ignored, &data.blob, ignored, &lblob);
F
freemine 已提交
233
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
234 235 236
    if (r) break;

    r = SQLExecute(stmt);
F
freemine 已提交
237
    CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
F
freemine 已提交
238 239 240 241 242 243 244
    if (r) break;

    // ts += 1;
    // v  = 2;
    // r = SQLExecute(stmt);
    // if (r) break;
  } while (0);
245 246

  #undef ignored
F
freemine 已提交
247 248 249
  return r;
}

F
freemine 已提交
250
static int test1(const char *dsn, const char *uid, const char *pwd) {
F
freemine 已提交
251 252
  SQLHENV env = {0};
  SQLHDBC conn = {0};
F
freemine 已提交
253 254 255
  int n = open_connect(dsn, uid, pwd, &env, &conn);
  if (n) return 1;

256
  int ok = 0;
F
freemine 已提交
257
  do {
258
    SQLRETURN r = SQL_SUCCESS;
F
freemine 已提交
259 260
    SQLHSTMT stmt = {0};
    r = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
F
freemine 已提交
261
    if (r!=SQL_SUCCESS) break;
F
freemine 已提交
262
    do {
F
freemine 已提交
263 264 265 266
      if (do_statement(stmt, "drop database if exists db")) {
        break;
      }
      for (size_t i=0; i<sizeof(pre_stmts)/sizeof(pre_stmts[0]); ++i) {
267 268
        n = do_statement(stmt, pre_stmts[i]);
        if (n) break;
F
freemine 已提交
269
      }
F
freemine 已提交
270
      do {
F
freemine 已提交
271 272 273 274 275 276 277
        data_t       data = {0};
        data.ts      = 1591060628001;
        data.b       = 1;
        data.v1      = 127;
        data.v2      = 32767;
        data.v4      = 2147483647;
        data.v8      = 9223372036854775807;
278
        data.f4      = 123.456f;
F
freemine 已提交
279 280 281 282 283 284
        data.f8      = 9999999.999999;
        memset(data.bin, 0, sizeof(data.bin));
        memset(data.blob, 0, sizeof(data.blob));
        snprintf(data.bin, sizeof(data.bin), "hel我lo");
        snprintf(data.blob, sizeof(data.blob), "world");
        snprintf(data.blob, sizeof(data.blob), "wo人rld");
F
freemine 已提交
285 286 287 288
        SQLHSTMT stmt = {0};
        r = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
        if (r!=SQL_SUCCESS) break;
        do {
289 290
          n = do_insert(stmt, data);
          if (n) break;
F
freemine 已提交
291 292
        } while (0);
        SQLFreeHandle(SQL_HANDLE_STMT, stmt);
F
freemine 已提交
293 294 295 296 297 298 299 300

        // r = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
        // if (r!=SQL_SUCCESS) break;
        // do {
        //   r = do_insert(stmt, ts++, v++);
        //   if (r!=SQL_SUCCESS) break;
        // } while (0);
        // SQLFreeHandle(SQL_HANDLE_STMT, stmt);
301
        ok = 1;
F
freemine 已提交
302
      } while (0);
303 304
      if (!ok) break;
      ok = 0;
F
freemine 已提交
305
      for (size_t i=0; i<sizeof(pro_stmts)/sizeof(pro_stmts[0]); ++i) {
306 307
        n = do_statement(stmt, pro_stmts[i]);
        if (n) break;
F
freemine 已提交
308
      }
309
      ok = 1;
F
freemine 已提交
310
    } while (0);
F
freemine 已提交
311
    SQLFreeHandle(SQL_HANDLE_STMT, stmt);
F
freemine 已提交
312
  } while (0);
F
freemine 已提交
313 314
  SQLDisconnect(conn);
  SQLFreeConnect(conn);
F
freemine 已提交
315
  SQLFreeEnv(env);
F
freemine 已提交
316

317
  return ok ? 0 : 1;
F
freemine 已提交
318 319
}

F
freemine 已提交
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
int test_statements(const char *dsn, const char *uid, const char *pwd, const char **statements) {
  SQLRETURN r = SQL_SUCCESS;
  SQLHENV env = {0};
  SQLHDBC conn = {0};
  int n = open_connect(dsn, uid, pwd, &env, &conn);
  if (n) return 1;
  do {
    SQLHSTMT stmt = {0};
    r = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
    if (r!=SQL_SUCCESS) break;
    const char **p = statements;
    while (*p) {
      if (do_statement(stmt, *p)) {
        r = SQL_ERROR;
        break;
      }
      ++p;
    }
    SQLFreeHandle(SQL_HANDLE_STMT, stmt);
  } while (0);
  SQLDisconnect(conn);
  SQLFreeConnect(conn);
  SQLFreeEnv(env);
  return r ? 1 : 0;
}

int test_driver_connect(const char *connstr) {
  SQLRETURN r = SQL_SUCCESS;
  SQLHENV env = {0};
  SQLHDBC conn = {0};
  int n = open_driver_connect(connstr, &env, &conn);
  if (n) return 1;
  SQLDisconnect(conn);
  SQLFreeConnect(conn);
  SQLFreeEnv(env);
  return r ? 1 : 0;
}

int create_statement(SQLHENV env, SQLHDBC conn, SQLHSTMT *pStmt) {
  SQLHSTMT stmt = {0};
  SQLRETURN r = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
  CHK_RESULT(r, SQL_HANDLE_DBC, conn, "");
  if (r==SQL_SUCCESS) {
    *pStmt = stmt;
    return 0;
  }
  if (r==SQL_SUCCESS_WITH_INFO) {
    SQLFreeHandle(SQL_HANDLE_STMT, stmt);
  }
  return 1;
}

int do_statements(SQLHSTMT stmt, const char **statements) {
  const char **p = statements;
  while (p && *p) {
    CHK_TEST(do_statement(stmt, *p));
    ++p;
  }
  return 0;
}

int tests_stmt(SQLHENV env, SQLHDBC conn, SQLHSTMT stmt) {
  const char *statements[] = {
    "drop database if exists m",
    "create database m",
    "use m",
    // "create table t (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, blob binary(1), name nchar(1))",
    "create table t (ts timestamp, b bool)",
    "insert into t values('2020-10-10 00:00:00', 0)",
    "insert into t values('2020-10-10 00:00:00.001', 1)",
    NULL
  };
  CHK_TEST(do_statements(stmt, statements));
  return 0;
}

int tests(SQLHENV env, SQLHDBC conn) {
  SQLHSTMT stmt = {0};
  CHK_TEST(create_statement(env, conn, &stmt));
  int r = tests_stmt(env, conn, stmt);
  SQLFreeHandle(SQL_HANDLE_STMT, stmt);
  return r ? 1 : 0;
}

int test_env(void) {
  SQLRETURN r;
  SQLHENV env = {0};
  r = SQLAllocEnv(&env);
  if (r!=SQL_SUCCESS) return 1;
  SQLFreeEnv(env);
  return 0;
}

int test_sqls_in_stmt(SQLHENV env, SQLHDBC conn, SQLHSTMT stmt, const char *sqls) {
  FILE *f = fopen(sqls, "rb");
  if (!f) {
    D("failed to open file [%s]", sqls);
    return -1;
  }

  int r = 0;
  while (!feof(f)) {
    char *line = NULL;
    size_t len = 0;

F
freemine 已提交
425 426
    ssize_t n = 0;
#ifdef _MSC_VER
427
    n = taosGetline(&line, &len, f);
F
freemine 已提交
428 429 430
#else
    n = getline(&line, &len, f);
#endif
F
freemine 已提交
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
    if (n==-1) break;

    const char *p = NULL;
    do {
      if (line[0] == '#') break;
      if (line[n-1] == '\n') line[n-1]='\0';
      p = line;
      while (isspace(*p)) ++p;

      if (*p==0) break;

      int positive = 1;
      if (strncmp(p, "N:", 2)==0) {
        positive = 0;
        p += 2;
      } else if (strncmp(p, "P:", 2)==0) {
        p += 2;
      }

      D("statement: [%s]", p);
      r = do_statement(stmt, p);

      if (positive && r==0) break;
      if (!positive && r) { r = 0; break; }
      if (positive) return r;
      D("expecting negative result, but got positive");
      return -1;
    } while (0);

    free(line);

    if (r) break;
  }

  fclose(f);
  return r ? 1 : 0;
}

int test_sqls_in_conn(SQLHENV env, SQLHDBC conn, const char *sqls) {
  SQLHSTMT stmt = {0};
  CHK_TEST(create_statement(env, conn, &stmt));
  int r = test_sqls_in_stmt(env, conn, stmt, sqls);
  SQLFreeHandle(SQL_HANDLE_STMT, stmt);
  return r ? 1 : 0;
}

int test_sqls(const char *dsn, const char *uid, const char *pwd, const char *connstr, const char *sqls) {
  int r = 0;
  SQLHENV env  = {0};
  SQLHDBC conn = {0};
  if (dsn) {
    CHK_TEST(open_connect(dsn, uid, pwd, &env, &conn));
  } else {
    CHK_TEST(open_driver_connect(connstr, &env, &conn));
  }
  r = test_sqls_in_conn(env, conn, sqls);
  SQLDisconnect(conn);
  SQLFreeConnect(conn);
  SQLFreeEnv(env);
  return r ? 1 : 0;
}

int main(int argc, char *argv[]) {
  if (argc==1) {
    CHK_TEST(test_env());
    return 0;
  }

  const char *dsn = (argc>1) ? argv[1] : NULL;
  const char *uid = (argc>2) ? argv[2] : NULL;
  const char *pwd = (argc>3) ? argv[3] : NULL;
  const char *connstr = (argc>4) ? argv[4] : NULL;
  const char *sqls = (argc>5) ? argv[5] : NULL;

505 506 507 508 509 510
  dsn = NULL;
  uid = NULL;
  pwd = NULL;
  connstr = argv[1];
  sqls = argv[2];
  if (0) {
F
freemine 已提交
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
    CHK_TEST(test_env());

    CHK_TEST(test1(dsn, uid, pwd));

    const char *statements[] = {
      "drop database if exists m",
      "create database m",
      "use m",
      "drop database m",
      NULL
    };
    CHK_TEST(test_statements(dsn, uid, pwd, statements));

    if (connstr)
      CHK_TEST(test_driver_connect(connstr));

    if (connstr) {
      SQLHENV env  = {0};
      SQLHDBC conn = {0};
      CHK_TEST(open_driver_connect(connstr, &env, &conn));
      int r = tests(env, conn);
      SQLDisconnect(conn);
      SQLFreeConnect(conn);
      SQLFreeEnv(env);
      if (r) return 1;
    }
  }

  if ((dsn || connstr) && 1) {
    CHK_TEST(test_sqls(dsn, uid, pwd, connstr, sqls));
  }

  return 0;
}