6 #include <sys/socket.h>
14 #include <netinet/in.h>
17 #if defined(UNIXODBC) || defined(_WIN32)
24 #define TDS_SDIR_SEPARATOR "\\"
46 size_t len = strlen(path);
50 f = fopen(path,
"rb");
75 ".libs/libtdsodbc.so",
76 ".libs/libtdsodbc.sl",
77 ".libs/libtdsodbc.dylib",
78 ".libs/libtdsodbc.dll",
79 "_libs/libtdsodbc.dll",
81 "release/tdsodbc.dll",
90 static const char *
PWD =
"../../../PWD";
94 const char *
const *search_p;
97 #if defined(_WIN32) && !defined(TDS_NO_DM)
98 UWORD old_config_mode;
101 setbuf(stdout,
NULL);
102 setbuf(stderr,
NULL);
104 s1 = getenv(
"TDSPWDFILE");
108 in = fopen(
PWD,
"r");
110 in = fopen(
"PWD",
"r");
113 fprintf(stderr,
"Can not open PWD file\n\n");
116 while (fgets(line, 512,
in)) {
117 s1 = strtok(line,
"=");
118 s2 = strtok(
NULL,
"\n");
123 }
else if (!
strcmp(s1,
"SRV")) {
125 }
else if (!
strcmp(s1,
"PWD")) {
127 }
else if (!
strcmp(s1,
"DB")) {
135 if (!getcwd(path,
sizeof(path)))
137 if (!_getcwd(path,
sizeof(path)))
143 const char *unixspec = decc$translate_vms(path);
144 if ( (
int)unixspec != 0 && (
int)unixspec != -1 ) strcpy(path, unixspec);
163 #if !defined(_WIN32) || defined(TDS_NO_DM)
165 sprintf(path,
"odbc.ini.%d", (
int) getpid());
166 in = fopen(path,
"w");
170 setenv(
"ODBCINI",
"./odbc.ini", 1);
171 setenv(
"SYSODBCINI",
"./odbc.ini", 1);
172 rename(path,
"odbc.ini");
209 fprintf(stderr,
"%s:%d %s\n",
file, line, errmsg);
211 fprintf(stderr,
"%s\n", errmsg);
215 fprintf(stderr,
"SQL error %s -- %s\n",
C(sqlstate),
C(msg));
231 fprintf(stderr,
"%s:%d rc=%d %s\n",
file, line, (
int) rc, errmsg);
233 fprintf(stderr,
"rc=%d %s\n", (
int) rc, errmsg);
237 fprintf(stderr,
"SQL error %s -- %s\n",
C(sqlstate),
C(msg));
262 printf(
"odbctest\n--------\n\n");
263 printf(
"connection parameters:\nserver: '%s'\nuser: '%s'\npassword: '%s'\ndatabase: '%s'\n",
266 p = getenv(
"ODBC_MARS");
267 if (p && atoi(p) != 0)
270 (*odbc_set_conn_attr)();
395 fprintf(stderr,
"Strange type returned trying to detect protocol version\n");
415 fprintf(stderr,
"Strange type returned trying to detect protocol version\n");
433 fprintf(stderr,
"Strange type or scale returned trying to detect protocol version\n");
492 return (h << 24) | ((l & 0xFFu) << 16);
506 fprintf(stderr,
"%s:%d: Expected %d columns returned %d\n",
file, line,
n, (
int) cols);
524 fprintf(stderr,
"%s:%d: Expected %d rows returned %d\n",
file, line,
n, (
int) rows);
541 const char *p = getenv(
"TDS_SKIP_SUCCESS");
542 if (p && atoi(p) != 0)
560 if (
strcmp(
C(sqlstate),
"01S02") == 0) {
561 printf(
"Your connection seems to not support cursors, probably you are using wrong protocol version or Sybase\n");
581 }
else if (*p ==
'I') {
585 }
else if (*p ==
'E') {
589 }
else if (
strncmp(p,
"No", 2) == 0) {
593 }
else if (
strncmp(p,
"Ne", 2) == 0) {
658 dst[
i] = (
unsigned char) src[
i];
668 for (
n=1; *p++ != 0; ++
n)
671 for (
i = 0;
i <
n; ++
i) {
673 dst[
i] = (char) src[
i];
725 for (
n=1; *p++ != 0; ++
n)
734 struct sockaddr_in sin;
745 struct stat file_stat;
747 if (fstat(fd, &file_stat))
749 if ((file_stat.st_mode & S_IFSOCK) != S_IFSOCK)
753 addr_len =
sizeof(addr);
757 addr_len =
sizeof(addr);
780 return (
mask >> shift) & 1;
784 #define FOR_ALL_SOCKETS(i) for (i = 4; i <= (4096*4); i += 4)
786 #define FOR_ALL_SOCKETS(i) for (i = 3; i < 1024; ++i)
813 unsigned num_found = 0,
n;
818 struct sockaddr_in *
in;
819 socklen_t remote_addr_len, local_addr_len;
828 remote_addr_len =
sizeof(remote_addr);
831 if (remote_addr.
sa.sa_family != AF_INET
833 && remote_addr.
sa.sa_family != AF_INET6
837 local_addr_len =
sizeof(local_addr);
842 if (num_found >= 8) {
843 memmove(found, found+1,
sizeof(found) -
sizeof(found[0]));
846 info = &found[num_found++];
848 info->local_port = -1;
849 info->remote_port = -1;
852 in = &remote_addr.
sin;
853 if (
in->sin_family != AF_INET)
857 info->remote_port = ntohs(
in->sin_port);
858 in = &local_addr.
sin;
859 if (
in->sin_family != AF_INET)
863 info->local_port = ntohs(
in->sin_port);
864 for (
n = 0;
n < num_found - 1; ++
n) {
865 if (found[
n].remote_port !=
info->local_port
866 || found[
n].local_port !=
info->remote_port)
878 return found[num_found-1].sock;
896 fprintf(stderr,
"Data not expected here, query:\n\t%s\n",
query);
#define CHKMoreResults(res)
#define odbc_reset_statement()
#define CHKAllocHandle(a, b, c, res)
#define CHKNumResultCols(a, res)
#define CHKAllocStmt(a, res)
#define CHKR(func, params, res)
#define CHKExecDirect(a, b, res)
#define CHKDescribeCol(a, b, c, d, e, f, g, h, res)
#define CHKConnect(a, b, c, d, e, f, res)
#define CHKAllocConnect(a, res)
#define CHKGetDiagRec(a, b, c, d, e, f, g, h, res)
#define ODBC_VECTOR_SIZE(x)
#define CHKAllocEnv(a, res)
#define CHKRowCount(a, res)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
std::ofstream out("events_result.xml")
main entry point for tests
int strncmp(const char *str1, const char *str2, size_t count)
int strcmp(const char *str1, const char *str2)
std::istream & in(std::istream &in_, double &x_)
double f(double x_, const double &y_)
const char * odbc_db_version(void)
#define FOR_ALL_SOCKETS(i)
unsigned int odbc_db_version_int(void)
void odbc_report_error(const char *errmsg, int line, const char *file)
void odbc_test_skipped(void)
void odbc_check_cursor(void)
void odbc_check_rows(int n, int line, const char *file)
static unsigned char fd_bitmask[NUM_FDS/8]
int odbc_disconnect(void)
int odbc_read_login_info(void)
void odbc_buf_free(ODBC_BUF **buf)
SQLWCHAR * odbc_get_sqlwchar(ODBC_BUF **buf, const char *s)
static char db_str_version[32]
SQLRETURN odbc_check_res(const char *file, int line, SQLRETURN rc, SQLSMALLINT handle_type, SQLHANDLE handle, const char *func, const char *res)
void odbc_check_cols(int n, int line, const char *file)
SQLINTEGER odbc_to_sqlwchar(SQLWCHAR *dst, const char *src, SQLINTEGER n)
void odbc_reset_statement_proc(SQLHSTMT *stmt, const char *file, int line)
static void ReportODBCError(const char *errmsg, SQLSMALLINT handletype, SQLHANDLE handle, SQLRETURN rc, int line, const char *file)
static const char *const search_driver[]
void odbc_mark_sockets_opened(void)
SQLRETURN odbc_command_proc(HSTMT stmt, const char *command, const char *file, int line, const char *res)
static int odbc_tds_version_long(void)
int odbc_db_is_microsoft(void)
static int fd_is_socket(int fd)
static int check_lib(char *path, const char *file)
void(* odbc_set_conn_attr)(void)
TDS_SYS_SOCKET odbc_find_last_socket(void)
void odbc_check_no_row(const char *query)
char * odbc_get_sqlchar(ODBC_BUF **buf, SQLWCHAR *s)
void odbc_read_error(void)
SQLSMALLINT odbc_alloc_handle_err_type(SQLSMALLINT type)
int odbc_tds_version(void)
static int mark_fd(int fd)
int odbc_driver_is_freetds(void)
void odbc_setenv(const char *name, const char *value, int overwrite)
void * odbc_buf_get(ODBC_BUF **buf, size_t s)
static int freetds_driver
SQLRETURN odbc_command_with_result(HSTMT stmt, const char *command)
SQLINTEGER odbc_from_sqlwchar(char *dst, const SQLWCHAR *src, SQLINTEGER n)
#define SQLSetConnectAttr(h, n, p, t)
int SQLSetConfigMode(UWORD wConfigMode)
int SQLWritePrivateProfileString(LPCSTR lpszSection, LPCSTR lpszEntry, LPCSTR lpszString, LPCSTR lpszFilename)
int SQLGetConfigMode(UWORD *pwConfigMode)
static pcre_uint8 * buffer
static SQLCHAR output[256]
SQLRETURN SQLSetEnvAttr(SQLHENV EnvironmentHandle, SQLINTEGER Attribute, SQLPOINTER Value, SQLINTEGER StringLength)
SQLRETURN SQLExecDirect(SQLHSTMT StatementHandle, SQLCHAR *StatementText, SQLINTEGER TextLength)
SQLRETURN SQLGetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber, SQLCHAR *Sqlstate, SQLINTEGER *NativeError, SQLCHAR *MessageText, SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
SQLRETURN SQLGetInfo(SQLHDBC ConnectionHandle, SQLUSMALLINT InfoType, SQLPOINTER InfoValue, SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
SQLRETURN SQLFreeStmt(SQLHSTMT StatementHandle, SQLUSMALLINT Option)
SQLRETURN SQLFreeEnv(SQLHENV EnvironmentHandle)
SQLRETURN SQLAllocStmt(SQLHDBC ConnectionHandle, SQLHSTMT *StatementHandle)
SQLRETURN SQLSetStmtAttr(SQLHSTMT StatementHandle, SQLINTEGER Attribute, SQLPOINTER Value, SQLINTEGER StringLength)
SQLRETURN SQLFreeConnect(SQLHDBC ConnectionHandle)
#define SQL_SUCCESS_WITH_INFO
SQLRETURN SQLDisconnect(SQLHDBC ConnectionHandle)
SQLRETURN SQLMoreResults(SQLHSTMT hstmt)
#define SQL_ATTR_CONCURRENCY
#define SQL_ATTR_ODBC_VERSION
#define SQL_CONCUR_ROWVER
unsigned long SQLUINTEGER
signed short int SQLSMALLINT
Information for a server connection.
voidp calloc(uInt items, uInt size)