12 #include <sys/param.h>
15 #include <freetds/time.h>
17 #if HAVE_SYS_RESOURCE_H
18 #include <sys/resource.h>
21 #include "replacements.h"
25 #if !defined(PATH_MAX)
42 #if HAVE_MALLOC_OPTIONS
43 extern const char *malloc_options;
50 #if HAVE_MALLOC_OPTIONS
57 malloc_options =
"AJR";
61 #if defined(__MINGW32__) || defined(_MSC_VER)
63 tds_dirname(
char* path)
67 for (p = path + strlen(path); --p > path && (*p ==
'/' || *p ==
'\\');)
70 p = strrchr(path,
'/');
73 p2 = strrchr(p,
'\\');
77 if (*p ==
'/' || *p ==
'\\')
84 #define dirname tds_dirname
111 #if !defined(__MINGW32__) && !defined(_MSC_VER)
117 static const char *
PWD =
"../../../PWD";
118 struct {
char *username, *password, *servername, *
database;
char fverbose; } options;
120 #if defined(HAVE_SETRLIMIT) && defined(RLIMIT_STACK)
121 #define MAX_STACK (8*1024*1024)
125 if (!getrlimit(RLIMIT_STACK, &rlim) && (rlim.rlim_cur == RLIM_INFINITY || rlim.rlim_cur > MAX_STACK)) {
126 rlim.rlim_cur = MAX_STACK;
127 setrlimit(RLIMIT_STACK, &rlim);
131 setbuf(stdout,
NULL);
132 setbuf(stderr,
NULL);
139 s1 = strrchr(argv[0],
';');
141 const char *unixspec = decc$translate_vms(argv[0]);
150 #if defined(_WIN32) || defined(__VMS)
156 memset(&options, 0,
sizeof(options));
158 #if !defined(__MINGW32__) && !defined(_MSC_VER)
160 while ((ch =
getopt(argc, (
char**)argv,
"U:P:S:D:f:v")) != -1) {
178 options.fverbose = 1;
182 fprintf(stderr,
"usage: %s \n"
183 " [-U username] [-P password]\n"
184 " [-S servername] [-D database]\n"
185 " [-i input filename] [-o output filename] "
186 "[-e error filename]\n"
192 strcpy(filename,
PWD);
194 s1 = getenv(
"TDSPWDFILE");
198 in = fopen(filename,
"r");
200 in = fopen(
"PWD",
"r");
204 in = fopen(filename,
"r");
206 fprintf(stderr,
"Can not open %s file\n\n", filename);
211 while (fgets(line, 512,
in)) {
212 s1 = strtok(line,
"=");
213 s2 = strtok(
NULL,
"\n");
218 }
else if (!
strcmp(s1,
"SRV")) {
220 }
else if (!
strcmp(s1,
"PWD")) {
222 }
else if (!
strcmp(s1,
"DB")) {
230 if (options.username) {
231 strcpy(
USER, options.username);
232 free(options.username);
234 if (options.password) {
236 free(options.password);
238 if (options.servername) {
239 strcpy(
SERVER, options.servername);
240 free(options.servername);
242 if (options.database) {
244 free(options.database);
248 fprintf(stderr,
"no servername provided, quitting.\n");
264 fprintf(stderr,
"could not open SQL input file \"%s\"\n",
sql_file);
271 printf(
"SQL text will be read from %s\n",
sql_file);
282 char line[2048], *p = line;
287 fprintf(stderr,
"%s: error: SQL input file \"%s\" not opened\n",
BASENAME,
sql_file);
292 printf(
"\t%3d: %s", ++
i, p);
294 fprintf(stderr,
"%s: error: could write \"%s\" to dbcmd()\n",
BASENAME, p);
300 fprintf(stderr,
"%s: error: could not read SQL input file \"%s\"\n",
BASENAME,
sql_file);
326 fprintf(stderr,
"could not open SQL input file \"%s\"\n",
sql_file);
336 int *pexpected_msgno;
358 if (pexpected_msgno && *pexpected_msgno == msgno) {
359 fprintf(stdout,
"OK: anticipated message arrived: %d %s\n", (
int) msgno, msgtext);
360 *pexpected_msgno = 0;
369 if (severity >= 0 || msgno == 0) {
375 if (msgno > 0 && severity > 0) {
376 fprintf(stderr,
"Msg %d, Level %d, State %d\n", (
int) msgno, (
int) severity, (
int) msgstate);
377 fprintf(stderr,
"Server '%s'", srvname);
378 if (procname !=
NULL && *procname !=
'\0')
379 fprintf(stderr,
", Procedure '%s'", procname);
381 fprintf(stderr,
", Line %d", line);
382 fprintf(stderr,
"\n");
383 fprintf(stderr,
"%s\n", msgtext);
390 fprintf(stdout,
"%s\n", msgtext);
397 fprintf(stderr,
"exit: no unanticipated messages allowed in unit tests\n");
406 int *pexpected_dberr;
421 if (pexpected_dberr && *pexpected_dberr == dberr) {
422 fprintf(stdout,
"OK: anticipated error %d (%s) arrived\n", dberr, dberrstr);
423 *pexpected_dberr = 0;
430 "DB-LIBRARY error (dberr %d (severity %d): \"%s\"; oserr %d: \"%s\")\n",
431 dberr, severity, dberrstr ? dberrstr :
"(null)", oserr, oserrstr ? oserrstr :
"(null)");
448 fprintf(stderr,
"error: no unanticipated errors allowed in unit tests\n");
CS_RETCODE read_login_info(void)
int syb_err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
static const char * BASENAME
RETCODE sql_cmd(DBPROCESS *dbproc)
char free_file_registered
int syb_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line)
RETCODE sql_reopen(const char *fn)
void set_malloc_options(void)
static char sql_file[256]
static void free_file(void)
static DBPROCESS * dbproc
#define DBDEAD(x)
Sybase macro mapping to the Microsoft (lower-case) function.
RETCODE dbcmd(DBPROCESS *dbproc, const char cmdstring[])
Append SQL to the command buffer.
void dbrecftos(const char filename[])
Record to a file all SQL commands sent to the server.
BYTE * dbgetuserdata(DBPROCESS *dbproc)
Get address of user-allocated data from a DBPROCESS.
use only n Cassandra database for the lookups</td > n</tr > n< tr > n< td > yes</td > n< td > do not use tables BIOSEQ_INFO and BLOB_PROP in the Cassandra database
int strcmp(const char *str1, const char *str2)
std::istream & in(std::istream &in_, double &x_)