mem.c
来自「在Linux/Unix下面访问WINDOWS SQLSERVER 的ODBC驱动」· C语言 代码 · 共 1,446 行 · 第 1/3 页
C
1,446 行
*/ tds_socket->option_flag2 = 0x03; tds_socket->env.block_size = bufsize; if (tds_iconv_alloc(tds_socket)) goto Cleanup; /* Jeff's hack, init to no timeout */ tds_socket->query_timeout = 0; tds_init_write_buf(tds_socket); tds_socket->s = INVALID_SOCKET; tds_socket->state = TDS_DEAD; tds_socket->env_chg_func = NULL; return tds_socket; Cleanup: tds_free_socket(tds_socket); return NULL;}TDSSOCKET *tds_realloc_socket(TDSSOCKET * tds, int bufsize){ unsigned char *new_out_buf; assert(tds && tds->out_buf); if (tds->env.block_size == bufsize) return tds; if ((new_out_buf = (unsigned char *) realloc(tds->out_buf, bufsize + TDS_ADDITIONAL_SPACE)) != NULL) { tds->out_buf = new_out_buf; tds->env.block_size = bufsize; return tds; } return NULL;}voidtds_free_socket(TDSSOCKET * tds){ if (tds) { if (tds->authentication) tds->authentication->free(tds, tds->authentication); tds->authentication = NULL; tds_free_all_results(tds); tds_free_env(tds); while (tds->dyns) tds_free_dynamic(tds, tds->dyns); while (tds->cursors) tds_cursor_deallocated(tds, tds->cursors); free(tds->in_buf); free(tds->out_buf);#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) tds_ssl_deinit(tds);#endif tds_close_socket(tds); free(tds->date_fmt); tds_iconv_free(tds); free(tds->product_name); free(tds); }}voidtds_free_locale(TDSLOCALE * locale){ if (!locale) return; free(locale->language); free(locale->server_charset); free(locale->date_fmt); free(locale->client_charset); free(locale);}voidtds_free_connection(TDSCONNECTION * connection){ tds_dstr_free(&connection->server_name); tds_dstr_free(&connection->client_host_name); tds_dstr_free(&connection->server_host_name); tds_dstr_free(&connection->language); tds_dstr_free(&connection->server_charset); tds_dstr_free(&connection->ip_addr); tds_dstr_free(&connection->database); tds_dstr_free(&connection->dump_file); tds_dstr_free(&connection->client_charset); tds_dstr_free(&connection->app_name); tds_dstr_free(&connection->user_name); /* cleared for security reason */ tds_dstr_zero(&connection->password); tds_dstr_free(&connection->password); tds_dstr_free(&connection->library); tds_dstr_free(&connection->instance_name); free(connection);}static voidtds_free_env(TDSSOCKET * tds){ if (tds->env.language) TDS_ZERO_FREE(tds->env.language); if (tds->env.charset) TDS_ZERO_FREE(tds->env.charset); if (tds->env.database) TDS_ZERO_FREE(tds->env.database);}voidtds_free_msg(TDSMESSAGE * message){ if (message) { message->priv_msg_type = 0; message->msgno = 0; message->state = 0; message->severity = 0; message->line_number = 0; if (message->message) TDS_ZERO_FREE(message->message); if (message->server) TDS_ZERO_FREE(message->server); if (message->proc_name) TDS_ZERO_FREE(message->proc_name); if (message->sql_state) TDS_ZERO_FREE(message->sql_state); }}#define SQLS_ENTRY(number,state) case number: p = state; breakchar *tds_alloc_client_sqlstate(int msgno){ char *p = NULL; switch (msgno) { SQLS_ENTRY(17000, "S1T00"); /* timeouts ??? */ SQLS_ENTRY(20004, "08S01"); /* Communication link failure */ SQLS_ENTRY(20006, "08S01"); SQLS_ENTRY(20009, "08S01"); SQLS_ENTRY(20020, "08S01"); SQLS_ENTRY(20019, "24000"); /* Invalid cursor state */ SQLS_ENTRY(20014, "28000"); /* Invalid authorization specification */ SQLS_ENTRY(2400, "42000"); /* Syntax error or access violation */ SQLS_ENTRY(2401, "42000"); SQLS_ENTRY(2403, "42000"); SQLS_ENTRY(2404, "42000"); SQLS_ENTRY(2402, "S1000"); /* General error */ } if (p != NULL) return strdup(p); else return NULL;}char *tds_alloc_lookup_sqlstate(TDSSOCKET * tds, int msgno){ const char *p = NULL; char *q = NULL; if (TDS_IS_MSSQL(tds)) { switch (msgno) { /* MSSQL Server */ SQLS_ENTRY(3621,"01000"); SQLS_ENTRY(8153,"01003"); /* Null in aggregate */ SQLS_ENTRY(911, "08004"); /* Server rejected connection */ SQLS_ENTRY(512, "21000"); /* Subquery returns more than one value */ SQLS_ENTRY(213, "21S01"); /* Insert column list mismatch */ SQLS_ENTRY(109, "21S01"); SQLS_ENTRY(110, "21S01"); SQLS_ENTRY(1774,"21S02"); /* Ref column mismatch */ SQLS_ENTRY(8152,"22001"); /* String data would be truncated */ SQLS_ENTRY(5146,"22003"); /* Numeric value out of range */ SQLS_ENTRY(168, "22003"); /* Arithmetic overflow */ SQLS_ENTRY(220, "22003"); SQLS_ENTRY(232, "22003"); SQLS_ENTRY(234, "22003"); SQLS_ENTRY(236, "22003"); SQLS_ENTRY(238, "22003"); SQLS_ENTRY(244, "22003"); SQLS_ENTRY(246, "22003"); SQLS_ENTRY(248, "22003"); SQLS_ENTRY(519, "22003"); SQLS_ENTRY(520, "22003"); SQLS_ENTRY(521, "22003"); SQLS_ENTRY(522, "22003"); SQLS_ENTRY(523, "22003"); SQLS_ENTRY(524, "22003"); SQLS_ENTRY(1007,"22003"); SQLS_ENTRY(3606,"22003"); SQLS_ENTRY(8115,"22003"); SQLS_ENTRY(206, "22005"); /* Error in assignment */ SQLS_ENTRY(235, "22005"); SQLS_ENTRY(247, "22005"); SQLS_ENTRY(249, "22005"); SQLS_ENTRY(256, "22005"); SQLS_ENTRY(257, "22005"); SQLS_ENTRY(305, "22005"); SQLS_ENTRY(409, "22005"); SQLS_ENTRY(518, "22005"); SQLS_ENTRY(529, "22005"); SQLS_ENTRY(210, "22007"); /* Invalid datetime format */ SQLS_ENTRY(241, "22007"); SQLS_ENTRY(295, "22007"); SQLS_ENTRY(242, "22008"); /* Datetime out of range */ SQLS_ENTRY(296, "22008"); SQLS_ENTRY(298, "22008"); SQLS_ENTRY(535, "22008"); SQLS_ENTRY(542, "22008"); SQLS_ENTRY(517, "22008"); SQLS_ENTRY(3607, "22012"); /* Div by zero */ SQLS_ENTRY(8134, "22012"); SQLS_ENTRY(245, "22018"); /* Syntax error? */ SQLS_ENTRY(2627, "23000"); /* Constraint violation */ SQLS_ENTRY(515, "23000"); SQLS_ENTRY(233, "23000"); SQLS_ENTRY(273, "23000"); SQLS_ENTRY(530, "23000"); SQLS_ENTRY(2601,"23000"); SQLS_ENTRY(2615,"23000"); SQLS_ENTRY(2626,"23000"); SQLS_ENTRY(3604,"23000"); SQLS_ENTRY(3605,"23000"); SQLS_ENTRY(544, "23000"); SQLS_ENTRY(547, "23000"); SQLS_ENTRY(550, "23000"); SQLS_ENTRY(4415, "23000"); SQLS_ENTRY(1505, "23000"); SQLS_ENTRY(1508, "23000"); SQLS_ENTRY(3725, "23000"); SQLS_ENTRY(3726, "23000"); SQLS_ENTRY(4712, "23000"); SQLS_ENTRY(10055, "23000"); SQLS_ENTRY(10065, "23000"); SQLS_ENTRY(11011, "23000"); SQLS_ENTRY(11040, "23000"); SQLS_ENTRY(16999, "24000"); /* Invalid cursor state */ SQLS_ENTRY(16905, "24000"); SQLS_ENTRY(16917, "24000"); SQLS_ENTRY(16946, "24000"); SQLS_ENTRY(16950, "24000"); SQLS_ENTRY(266, "25000"); /* Invalid transaction state */ SQLS_ENTRY(277,"25000"); SQLS_ENTRY(611,"25000"); SQLS_ENTRY(3906,"25000"); SQLS_ENTRY(3908,"25000"); SQLS_ENTRY(6401,"25000"); SQLS_ENTRY(626, "25000"); SQLS_ENTRY(627, "25000"); SQLS_ENTRY(628, "25000"); SQLS_ENTRY(3902, "25000"); SQLS_ENTRY(3903, "25000"); SQLS_ENTRY(3916, "25000"); SQLS_ENTRY(3918, "25000"); SQLS_ENTRY(3919, "25000"); SQLS_ENTRY(3921, "25000"); SQLS_ENTRY(3922, "25000"); SQLS_ENTRY(3926, "25000"); SQLS_ENTRY(7969, "25000"); SQLS_ENTRY(8506, "25000"); SQLS_ENTRY(15626, "25000"); SQLS_ENTRY(18456, "28000"); /* Login failed? */ SQLS_ENTRY(6104, "37000"); /* Syntax error or access violation */ SQLS_ENTRY(8114, "37000"); SQLS_ENTRY(131, "37000"); SQLS_ENTRY(137, "37000"); SQLS_ENTRY(170, "37000"); SQLS_ENTRY(174, "37000"); SQLS_ENTRY(201, "37000"); SQLS_ENTRY(2812, "37000"); SQLS_ENTRY(2526, "37000"); SQLS_ENTRY(8144, "37000"); SQLS_ENTRY(17308, "42000"); /* Syntax/Access violation */ SQLS_ENTRY(17571, "42000"); SQLS_ENTRY(18002, "42000"); SQLS_ENTRY(229, "42000"); SQLS_ENTRY(230, "42000"); SQLS_ENTRY(262, "42000"); SQLS_ENTRY(2557, "42000"); SQLS_ENTRY(2571, "42000"); SQLS_ENTRY(2760, "42000"); SQLS_ENTRY(3110, "42000"); SQLS_ENTRY(3704, "42000"); SQLS_ENTRY(4613, "42000"); SQLS_ENTRY(4618, "42000"); SQLS_ENTRY(4834, "42000"); SQLS_ENTRY(5011, "42000"); SQLS_ENTRY(5116, "42000"); SQLS_ENTRY(5812, "42000"); SQLS_ENTRY(6004, "42000"); SQLS_ENTRY(6102, "42000"); SQLS_ENTRY(7956, "42000"); SQLS_ENTRY(11010, "42000"); SQLS_ENTRY(11045, "42000"); SQLS_ENTRY(14126, "42000"); SQLS_ENTRY(15247, "42000"); SQLS_ENTRY(15622, "42000"); SQLS_ENTRY(20604, "42000"); SQLS_ENTRY(21049, "42000"); SQLS_ENTRY(113, "42000"); SQLS_ENTRY(2714, "42S01"); /* Table or view already exists */ SQLS_ENTRY(208, "42S02"); /* Table or view not found */ SQLS_ENTRY(3701, "42S02"); SQLS_ENTRY(1913, "42S11"); /* Index already exists */ SQLS_ENTRY(15605, "42S11"); SQLS_ENTRY(307, "42S12"); /* Index not found */ SQLS_ENTRY(308, "42S12"); SQLS_ENTRY(10033, "42S12"); SQLS_ENTRY(15323, "42S12"); SQLS_ENTRY(18833, "42S12"); SQLS_ENTRY(4925, "42S21"); /* Column already exists */ SQLS_ENTRY(21255, "42S21"); SQLS_ENTRY(1911, "42S22"); /* Column not found */ SQLS_ENTRY(207, "42S22"); SQLS_ENTRY(4924, "42S22"); SQLS_ENTRY(4926, "42S22"); SQLS_ENTRY(15645, "42S22"); SQLS_ENTRY(21166, "42S22"); } } else { switch (msgno) { /* Sybase */ SQLS_ENTRY(3621, "01000"); SQLS_ENTRY(9501, "01003"); /* Null in aggregate */ SQLS_ENTRY(911, "08004"); /* Server rejected connection */ SQLS_ENTRY(512, "21000"); /* Subquery returns more than one value */ SQLS_ENTRY(213, "21S01"); /* Insert column list mismatch */ SQLS_ENTRY(109, "21S01"); SQLS_ENTRY(110, "21S01"); SQLS_ENTRY(1715, "21S02"); /* Ref column mismatch */ SQLS_ENTRY(9502, "22001"); /* String data would be truncated */ SQLS_ENTRY(220, "22003"); /* Arithmetic overflow */ SQLS_ENTRY(168, "22003"); SQLS_ENTRY(227, "22003"); SQLS_ENTRY(232, "22003"); SQLS_ENTRY(234, "22003"); SQLS_ENTRY(236, "22003"); SQLS_ENTRY(238, "22003"); SQLS_ENTRY(244, "22003"); SQLS_ENTRY(246, "22003"); SQLS_ENTRY(247, "22003"); SQLS_ENTRY(248, "22003"); SQLS_ENTRY(519, "22003"); SQLS_ENTRY(520, "22003"); SQLS_ENTRY(521, "22003"); SQLS_ENTRY(522, "22003"); SQLS_ENTRY(523, "22003"); SQLS_ENTRY(524, "22003"); SQLS_ENTRY(3606, "22003"); SQLS_ENTRY(206, "22005"); /* Error in assignment */ SQLS_ENTRY(235, "22005"); SQLS_ENTRY(249, "22005"); SQLS_ENTRY(256, "22005"); SQLS_ENTRY(305, "22005"); SQLS_ENTRY(409, "22005"); SQLS_ENTRY(518, "22005"); SQLS_ENTRY(529, "22005"); SQLS_ENTRY(535, "22008"); /* Datetime out of range */ SQLS_ENTRY(542, "22008"); SQLS_ENTRY(517, "22008"); SQLS_ENTRY(3607, "22012"); /* Div by zero */ SQLS_ENTRY(245, "22018"); /* Syntax error? */ SQLS_ENTRY(544, "23000"); /* Constraint violation */ SQLS_ENTRY(233, "23000"); SQLS_ENTRY(273, "23000"); SQLS_ENTRY(530, "23000"); SQLS_ENTRY(2601,"23000"); SQLS_ENTRY(2615,"23000"); SQLS_ENTRY(2626,"23000"); SQLS_ENTRY(3604,"23000"); SQLS_ENTRY(3605,"23000"); SQLS_ENTRY(545, "23000"); SQLS_ENTRY(546, "23000"); SQLS_ENTRY(547, "23000"); SQLS_ENTRY(548, "23000"); SQLS_ENTRY(549, "23000"); SQLS_ENTRY(550, "23000"); SQLS_ENTRY(1505, "23000"); SQLS_ENTRY(1508, "23000"); SQLS_ENTRY(565, "24000"); /* Invalid cursor state */ SQLS_ENTRY(558, "24000"); SQLS_ENTRY(559, "24000"); SQLS_ENTRY(6235, "24000"); SQLS_ENTRY(583, "24000"); SQLS_ENTRY(6259, "24000"); SQLS_ENTRY(6260, "24000"); SQLS_ENTRY(562, "24000"); SQLS_ENTRY(277, "25000"); /* Invalid transaction state */ SQLS_ENTRY(611,"25000"); SQLS_ENTRY(3906,"25000"); SQLS_ENTRY(3908,"25000"); SQLS_ENTRY(6401,"25000"); SQLS_ENTRY(627, "25000"); SQLS_ENTRY(628, "25000"); SQLS_ENTRY(641, "25000"); SQLS_ENTRY(642, "25000"); SQLS_ENTRY(1276, "25000"); SQLS_ENTRY(3902, "25000"); SQLS_ENTRY(3903, "25000"); SQLS_ENTRY(6104, "37000"); /* Syntax error or access violation */ SQLS_ENTRY(102, "37000"); SQLS_ENTRY(137, "37000"); SQLS_ENTRY(7327, "37000"); SQLS_ENTRY(201, "37000"); SQLS_ENTRY(257, "37000"); SQLS_ENTRY(2812, "37000"); SQLS_ENTRY(2526, "37000"); SQLS_ENTRY(11021, "37000"); SQLS_ENTRY(229, "42000"); /* Syntax/Access violation */ SQLS_ENTRY(230, "42000"); SQLS_ENTRY(262, "42000"); SQLS_ENTRY(4602, "42000"); SQLS_ENTRY(4603, "42000"); SQLS_ENTRY(4608, "42000"); SQLS_ENTRY(10306, "42000"); SQLS_ENTRY(10323, "42000"); SQLS_ENTRY(10330, "42000"); SQLS_ENTRY(10331, "42000"); SQLS_ENTRY(10332, "42000"); SQLS_ENTRY(11110, "42000"); SQLS_ENTRY(11113, "42000"); SQLS_ENTRY(11118, "42000"); SQLS_ENTRY(11121, "42000"); SQLS_ENTRY(17222, "42000"); SQLS_ENTRY(17223, "42000"); SQLS_ENTRY(18350, "42000"); SQLS_ENTRY(18351, "42000"); SQLS_ENTRY(113, "42000"); SQLS_ENTRY(2714, "42S01"); /* Table or view already exists */ SQLS_ENTRY(208, "42S02"); /* Table or view not found */ SQLS_ENTRY(3701, "42S02"); SQLS_ENTRY(1913, "42S11"); /* Index already exists */ SQLS_ENTRY(307, "42S12"); /* Index not found */ SQLS_ENTRY(7010, "42S12"); SQLS_ENTRY(18091, "42S12"); SQLS_ENTRY(1921, "42S21"); /* Column already exists */ SQLS_ENTRY(1720, "42S22"); /* Column not found */ SQLS_ENTRY(207, "42S22"); SQLS_ENTRY(4934, "42S22"); SQLS_ENTRY(18117, "42S22"); } } if (p != NULL && (q = strdup(p)) != NULL) { /* FIXME correct here ?? */ /* Convert known ODBC 3.x states listed above to 2.x */ if (memcmp(q, "42S", 3) == 0) memcpy(q, "S00", 3); return q; } return NULL;}BCPCOLDATA *tds_alloc_bcp_column_data(int column_size){ BCPCOLDATA *coldata; TEST_MALLOC(coldata, BCPCOLDATA); TEST_CALLOC(coldata->data, unsigned char, column_size); return coldata;Cleanup: tds_free_bcp_column_data(coldata); return NULL;}voidtds_free_bcp_column_data(BCPCOLDATA * coldata){ if (!coldata) return; free(coldata->data); free(coldata);}/** @} */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?