30 #include <freetds/odbc.h>
32 #include "replacements.h"
34 #define ODBC_PARAM(p) static const char odbc_param_##p[] = #p;
39 #define ODBC_PARAM(p) odbc_param_##p,
40 static const char *odbc_param_names[] = {
46 #if !HAVE_SQLGETPRIVATEPROFILESTRING
53 #define SYS_ODBC_INI "/etc/odbc.ini"
100 #if defined(FILENAME_MAX) && FILENAME_MAX < 512
102 #define FILENAME_MAX 512
108 char *p = (
char *) strchr(server,
'\\');
117 p = (
char *) strchr(server,
',');
118 if (p && atoi(p+1) > 0) {
150 int freetds_conf_less = 1;
154 freetds_conf_less = 0;
161 odbc_errs_add(errs,
"HY000",
"You cannot specify both SERVERNAME and SERVER");
165 odbc_errs_add(errs,
"HY000",
"You cannot specify both SERVERNAME and ADDRESS");
171 if (freetds_conf_less) {
172 int address_specified = 0;
175 address_specified = 1;
179 odbc_errs_add(errs,
"HY000",
"Error parsing ADDRESS attribute");
188 if (!address_specified) {
280 enum { CFG_DSN = 1, CFG_SERVER = 2, CFG_SERVERNAME = 4 };
281 unsigned int cfgs = 0;
288 for (p = connect_string; p < connect_string_end && *p;) {
294 while (p < connect_string_end && *p ==
';')
298 end = (
const char *) memchr(p,
'=', connect_string_end - p);
303 while (p < end && *p ==
' ')
309 memcpy(
option, p, end - p);
319 while ((end = (
const char *) memchr(end,
'}', connect_string_end - end)) !=
NULL) {
320 if ((end + 1) != connect_string_end && end[1] ==
';')
325 end = (
const char *) memchr(p,
';', connect_string_end - p);
328 end = connect_string_end;
335 #define CHK_PARAM(p) (strcasecmp(option, odbc_param_##p) == 0 && (num_param=ODBC_PARAM_##p) >= 0)
338 if ((cfgs & (CFG_DSN|CFG_SERVERNAME)) != 0) {
340 odbc_errs_add(errs,
"HY000",
"Only one between SERVER, SERVERNAME and DSN can be specified");
353 if ((cfgs & (CFG_DSN|CFG_SERVER)) != 0) {
355 odbc_errs_add(errs,
"HY000",
"Only one between SERVER, SERVERNAME and DSN can be specified");
361 cfgs = CFG_SERVERNAME;
366 if ((cfgs & (CFG_SERVER|CFG_SERVERNAME)) != 0) {
368 odbc_errs_add(errs,
"HY000",
"Only one between SERVER, SERVERNAME and DSN can be specified");
417 }
else if (
CHK_PARAM(Trusted_Connection)) {
425 }
else if (
CHK_PARAM(AttachDbFilename)) {
427 }
else if (
CHK_PARAM(ApplicationIntent)) {
428 const char *readonly_intent;
431 readonly_intent =
"yes";
433 readonly_intent =
"no";
443 if (num_param >= 0 && parsed_params) {
444 parsed_params[num_param].
p = p;
445 parsed_params[num_param].
len = end - p;
454 if (p >= connect_string_end)
487 len += strlen(odbc_param_names[
n]) + params[
n].
len + 2;
501 p += sprintf(p,
"%s=%.*s;", odbc_param_names[
n], (
int) params[
n].
len, params[
n].p);
508 #if !HAVE_SQLGETPRIVATEPROFILESTRING
510 #if defined(_WIN32) && !defined(TDS_NO_DM)
511 # error There is something wrong in configuration...
537 #if defined(_WIN32) && defined(TDS_NO_DM)
549 pszSection, pszEntry, pszDefault, pRetBuffer, nRetBuffer, pszFileName);
566 if (pszFileName && *pszFileName ==
'/')
567 hFile = fopen(pszFileName,
"r");
576 param.
entry = pszEntry;
577 param.
buffer = pRetBuffer;
585 if (pszDefault && !param.
found) {
586 strlcpy(pRetBuffer, pszDefault, nRetBuffer);
605 if ((p = getenv(
"ODBCINI")) !=
NULL)
613 if (
asprintf(&fn,
"%s/.odbc.ini", p) > 0) {
614 ret = fopen(fn,
"r");
641 #define INI_MAX_LINE 1000
642 #define INI_MAX_OBJECT_NAME INI_MAX_LINE
643 #define INI_MAX_PROPERTY_NAME INI_MAX_LINE
644 #define INI_MAX_PROPERTY_VALUE INI_MAX_LINE
646 #define ODBCINST_PROMPTTYPE_LABEL 0
647 #define ODBCINST_PROMPTTYPE_TEXTEDIT 1
648 #define ODBCINST_PROMPTTYPE_LISTBOX 2
649 #define ODBCINST_PROMPTTYPE_COMBOBOX 3
650 #define ODBCINST_PROMPTTYPE_FILENAME 4
651 #define ODBCINST_PROMPTTYPE_HIDDEN 5
653 typedef struct tODBCINSTPROPERTY
655 struct tODBCINSTPROPERTY *pNext;
657 char szName[INI_MAX_PROPERTY_NAME + 1];
658 char szValue[INI_MAX_PROPERTY_VALUE + 1];
666 ODBCINSTPROPERTY, *HODBCINSTPROPERTY;
672 int ODBCINSTGetProperties(HODBCINSTPROPERTY hLastProperty);
674 static const char *
const aTDSver[] = {
686 static const char *
const aLanguage[] = {
691 static const char *
const aEncryption[] = {
698 static const char *
const aBoolean[] = {
713 static HODBCINSTPROPERTY
714 addProperty(HODBCINSTPROPERTY hLastProperty)
716 hLastProperty->pNext = (HODBCINSTPROPERTY)
calloc(1,
sizeof(ODBCINSTPROPERTY));
717 hLastProperty = hLastProperty->pNext;
718 return hLastProperty;
721 static HODBCINSTPROPERTY
722 definePropertyString(HODBCINSTPROPERTY hLastProperty,
const char *name,
const char *
value,
const char *comment)
724 hLastProperty = addProperty(hLastProperty);
725 hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT;
726 strlcpy(hLastProperty->szName, name, INI_MAX_PROPERTY_NAME);
727 strlcpy(hLastProperty->szValue,
value, INI_MAX_PROPERTY_VALUE);
728 hLastProperty->pszHelp = (
char *)
strdup(comment);
729 return hLastProperty;
732 static HODBCINSTPROPERTY
733 definePropertyBoolean(HODBCINSTPROPERTY hLastProperty,
const char *name,
const char *
value,
const char *comment)
735 hLastProperty = addProperty(hLastProperty);
736 hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_LISTBOX;
737 hLastProperty->aPromptData =
malloc(
sizeof(aBoolean));
738 memcpy(hLastProperty->aPromptData, aBoolean,
sizeof(aBoolean));
739 strlcpy(hLastProperty->szName, name, INI_MAX_PROPERTY_NAME);
740 strlcpy(hLastProperty->szValue,
value, INI_MAX_PROPERTY_VALUE);
741 hLastProperty->pszHelp = (
char *)
strdup(comment);
742 return hLastProperty;
745 static HODBCINSTPROPERTY
746 definePropertyHidden(HODBCINSTPROPERTY hLastProperty,
const char *name,
const char *
value,
const char *comment)
748 hLastProperty = addProperty(hLastProperty);
749 hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_HIDDEN;
750 strlcpy(hLastProperty->szName, name, INI_MAX_PROPERTY_NAME);
751 strlcpy(hLastProperty->szValue,
value, INI_MAX_PROPERTY_VALUE);
752 hLastProperty->pszHelp = (
char *)
strdup(comment);
753 return hLastProperty;
756 static HODBCINSTPROPERTY
757 definePropertyList(HODBCINSTPROPERTY hLastProperty,
const char *name,
const char *
value,
const void *list,
int size,
const char *comment)
759 hLastProperty = addProperty(hLastProperty);
760 hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_LISTBOX;
762 memcpy(hLastProperty->aPromptData, list,
size);
763 strlcpy(hLastProperty->szName, name, INI_MAX_PROPERTY_NAME);
764 strlcpy(hLastProperty->szValue,
value, INI_MAX_PROPERTY_VALUE);
765 hLastProperty->pszHelp = (
char *)
strdup(comment);
766 return hLastProperty;
770 ODBCINSTGetProperties(HODBCINSTPROPERTY hLastProperty)
772 hLastProperty = definePropertyString(hLastProperty, odbc_param_Servername,
"",
773 "Name of FreeTDS connection to connect to.\n"
774 "This server name refer to entry in freetds.conf file, not real server name.\n"
775 "This property cannot be used with Server property.");
777 hLastProperty = definePropertyString(hLastProperty, odbc_param_Server,
"",
778 "Name of server to connect to.\n"
779 "This should be the name of real server.\n"
780 "This property cannot be used with Servername property.");
782 hLastProperty = definePropertyString(hLastProperty, odbc_param_Address,
"",
783 "The hostname or ip address of the server.");
785 hLastProperty = definePropertyString(hLastProperty, odbc_param_Port,
"1433",
786 "TCP/IP Port to connect to.");
788 hLastProperty = definePropertyString(hLastProperty, odbc_param_Database,
"",
789 "Default database.");
791 hLastProperty = definePropertyList(hLastProperty, odbc_param_TDS_Version,
"4.2", (
void*) aTDSver,
sizeof(aTDSver),
792 "The TDS protocol version.\n"
793 " 4.2 MSSQL 6.5 or Sybase < 10.x\n"
794 " 5.0 Sybase >= 10.x\n"
799 " 7.4 MSSQL 2012 or 2014"
802 hLastProperty = definePropertyList(hLastProperty, odbc_param_Language,
"us_english", (
void*) aLanguage,
sizeof(aLanguage),
803 "The default language setting.");
805 hLastProperty = definePropertyHidden(hLastProperty, odbc_param_TextSize,
"",
806 "Text datatype limit.");
825 hLastProperty = definePropertyString(hLastProperty, odbc_param_PacketSize,
"",
826 "Size of network packets.");
828 hLastProperty = definePropertyString(hLastProperty, odbc_param_ClientCharset,
"",
829 "The client character set name to convert application characters to UCS-2 in TDS 7.0 and higher.");
831 hLastProperty = definePropertyString(hLastProperty, odbc_param_DumpFile,
"",
832 "Specifies the location of a tds dump file and turns on logging.");
834 hLastProperty = definePropertyBoolean(hLastProperty, odbc_param_DumpFileAppend,
"",
835 "Appends dump file instead of overwriting it. Useful for debugging when many processes are active.");
837 hLastProperty = definePropertyString(hLastProperty, odbc_param_DebugFlags,
"",
838 "Sets granularity of logging. A set of bit that specify levels and informations. See table below for bit specification.");
840 hLastProperty = definePropertyList(hLastProperty, odbc_param_Encryption,
TDS_STR_ENCRYPTION_OFF, aEncryption,
sizeof(aEncryption),
841 "The encryption method.");
std::ofstream out("events_result.xml")
main entry point for tests
void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg)
add an error to list
@ ODBC_PARAM_Trusted_Connection
#define TDS_STR_READONLY_INTENT
#define TDS_STR_CLCHARSET
#define TDS_STR_ENCRYPTION_REQUEST
#define TDS_STR_ENCRYPTION_OFF
#define TDS_STR_DEBUGFLAGS
#define TDS_STR_ENCRYPTION
#define TDS_STR_APPENDMODE
#define TDS_STR_USENTLMV2
#define TDS_STR_DBFILENAME
#define TDS_STR_ENCRYPTION_REQUIRE
static int myGetPrivateProfileString(const char *DSN, const char *key, char *buf)
int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN *login)
Read connection information from given DSN.
int odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN *login, TDS_PARSED_PARAM *parsed_params)
Parse connection string and fill login according.
static FILE * tdoGetIniFileName(void)
Call this to get the INI file containing Data Source Names.
static void tdoParseProfile(const char *option, const char *value, void *param)
static void odbc_dstr_swap(DSTR *a, DSTR *b)
Swap two DSTR.
static int parse_server(TDS_ERRS *errs, char *server, TDSLOGIN *login)
static int SQLGetPrivateProfileString(LPCSTR pszSection, LPCSTR pszEntry, LPCSTR pszDefault, LPSTR pRetBuffer, int nRetBuffer, LPCSTR pszFileName)
SQLGetPrivateProfileString.
#define tds_read_conf_file
#define tds_lookup_host_set
#define tds_read_conf_section
#define tds_parse_conf_section
#define tds_config_boolean
static const char * tds_dstr_cstr(DSTR *s)
Returns a C version (NUL terminated string) of dstr.
#define tds_dstr_empty(s)
Make a string empty.
#define DSTR_INITIALIZER
Initializer, used to initialize string like in the following example.
DSTR * tds_dstr_copyn(DSTR *s, const char *src, size_t length) TDS_WUR
Set string to a given buffer of characters.
void tds_dstr_free(DSTR *s)
free string
DSTR * tds_dstr_copy(DSTR *s, const char *src) TDS_WUR
copy a string from another
static int tds_dstr_isempty(DSTR *s)
test if string is empty
unsigned int
A callback function used to compare two keys in a database.
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Structure to hold a string.
DSTR user_name
account for login
struct addrinfo * ip_addrs
ip(s) of server
DSTR password
password of account login
DSTR db_filename
database filename to attach (MSSQL)
DSTR server_name
server name (in freetds.conf)
int port
port of database service
voidp calloc(uInt items, uInt size)