### Test ODBC Setup with osql Source: https://www.freetds.org/userguide/index.html Use the 'osql' utility to test the ODBC setup. This command allows you to connect to a database and execute SQL queries. ```bash osql -S myserver -U myuser -P mypassword ``` -------------------------------- ### Example `freetds.conf` File Source: https://www.freetds.org/userguide/freetdsconf.html This example demonstrates the structure of a `freetds.conf` file, including global settings and specific server configurations. ```ini [global] tds version = auto [myserver] host = ntbox.mydomain.com port = 1433 [myserver2] host = unixbox.mydomain.com port = 4000 tds version = 5.0 [myserver3] host = instancebox.mydomain.com instance = foo ``` -------------------------------- ### Make and Install PHP with CT-Library Source: https://www.freetds.org/userguide/php.html Complete the build and installation process for PHP after modifying the Makefile for CT-Library support. ```bash $ **make** $ **sudo make install** ``` -------------------------------- ### Run Sybase Python Example Source: https://www.freetds.org/userguide/Python.html Command to execute the example Python script after installation. Note that FreeTDS might require version 100 symbols instead of 110. ```bash $ **python example.py** ``` -------------------------------- ### Example interfaces File Configuration Source: https://www.freetds.org/userguide/interfacesformat.html This example demonstrates the basic structure of an interfaces file, including the server name and service line with connection details. FreeTDS primarily uses the 'query' service line. ```text myserver query tcp 4.2 127.0.0.1 4000 master tcp ether 127.0.0.1 4000 ``` -------------------------------- ### Initialize DB-Library Source: https://www.freetds.org/userguide/samplecode.html Initializes the DB-Library and sets up login credentials. Always make dbinit() the first DB-Library call and install error/message handlers immediately. ```c if (dbinit() == FAIL) { fprintf(stderr, "%s:%d: dbinit() failed\n", options.appname, __LINE__); exit(1); } dberrhandle(err_handler); dbmsghandle(msg_handler); if ((login = dblogin()) == NULL) { fprintf(stderr, "%s:%d: unable to allocate login structure\n", options.appname, __LINE__); exit(1); } DBSETLUSER(login, options.username); DBSETLPWD(login, options.password); ``` -------------------------------- ### Test ODBC setup with osql Source: https://www.freetds.org/userguide/odbcdiagnose.html Use the osql utility to test your ODBC configuration. This script checks your setup and then invokes the unixODBC isql utility for connection testing. ```bash $ **osql -S machine -U mr_ed -P hayseed** looking for odbc.ini and odbcinst.ini in /usr/local/etc reading "/usr/home/mr_ed/.odbc.ini" [machine] found in "/usr/home/mr_ed/.odbc.ini" found this section: [machine] Database = testdb Servername = machine Trace = Yes TraceFile = /tmp/unixodbc.trace looking for driver for DSN [machine] no driver mentioned for [machine] in .odbc.ini looking for driver for DSN [default] driver "FreeTDS" found for [default] in .odbc.ini found driver named "FreeTDS" FreeTDS is not a readable file looking for entry named [FreeTDS] in /usr/local/etc/odbcinst.ini driver "/usr/local/lib/libtdsodbc.so" found for [FreeTDS] in odbcinst.ini /usr/local/lib/libtdsodbc.so is a readable file Using ODBC-Combined strategy FreeTDS servername is "machine" (from /usr/home/mr_ed/.odbc.ini) looking for [machine] in /usr/home/mr_ed/.freetds.conf "/usr/home/mr_ed/.freetds.conf" is a readable file found this section: [machine] host = machine.example.com port = 2500 tds version = 7.1 machine.example.com has address 10.82.32.177 DSN: machine Driver: /usr/local/lib/libtdsodbc.so Server's hostname: machine.example.com Address: 10.82.32.177 Attempting connection as mr_ed ... + exec isql machine mr_ed hayseed -v +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> ``` -------------------------------- ### Build FreeTDS for Experts Source: https://www.freetds.org/userguide/config.html This sequence of commands is for expert users building FreeTDS. It specifies a custom installation prefix. ```bash $ **./configure --prefix=/usr/local** $ **make** $ **sudo make install** ``` -------------------------------- ### Build DBD::Sybase with FreeTDS Source: https://www.freetds.org/userguide/perl.html Steps to build and install the DBD::Sybase module. FreeTDS environment variables should be set prior to execution. ```bash cd DBD-Sybase-0.91 export SYBASE=/usr/local/freetds perl Makefile.PL make sudo make install ``` -------------------------------- ### PHP and DB-Library for Sybase Source: https://www.freetds.org/userguide/index.html Example of using PHP with DB-Library to connect to a Sybase database. This demonstrates server interaction from a web application. ```php ``` -------------------------------- ### Compile-Time Settings with tsql Source: https://www.freetds.org/userguide/index.html Use the 'tsql' utility to display compile-time settings for FreeTDS. This is useful for verifying installation and configuration. ```bash tsql -C ``` -------------------------------- ### Getting Instance Information with tsql Source: https://www.freetds.org/userguide/ConfirmInstall.html Use `tsql -L` to list available servers and their connection details, including instance name, version, and network protocols (TCP/NP). This helps verify server configuration. ```bash $ **tsql -LH _servername_ ** locale is "C" locale charset is "646" ServerName TITAN InstanceName MSSQLSERVER IsClustered No Version 8.00.194 tcp 1433 np \\TITAN\pipe\sql\query ``` -------------------------------- ### UCS-2 and UTF-8 Encoding Example Source: https://www.freetds.org/userguide/index.html Illustrates the "HELLO" string represented in both UCS-2 and UTF-8 encoding. This is useful for understanding character set differences. ```text UCS-2: 0048 0045 004C 004C 004F UTF-8: 48 45 4C 4C 4F ``` -------------------------------- ### Build DBD::ODBC with FreeTDS Source: https://www.freetds.org/userguide/perl.html Steps to build and install the DBD::ODBC module. Ensure FreeTDS environment variables are set correctly. ```bash cd DBD-ODBC-0.28 export SYBASE=/usr/local/freetds export ODBCHOME=/usr/local export DBI_DSN=dbi:ODBC:JDBC export DBI_USER=guest export DBI_PASS=sybase perl Makefile.PL make sudo make install ``` -------------------------------- ### DB-Library: Fetch Results and Bind Columns Source: https://www.freetds.org/userguide/samplecode.html This example demonstrates fetching results from a database using DB-Library. It iterates through results, reads column metadata, binds columns to application variables, and processes rows. Ensure all rows are processed before executing a new query. ```c while ((erc = dbresults(dbproc)) != NO_MORE_RESULTS) { struct COL { char *name; char *buffer; int type, size, status; } *columns, *pcol; int ncols; int row_code; if (erc == FAIL) { fprintf(stderr, "%s:%d: dbresults failed\n", options.appname, __LINE__); exit(1); } ncols = dbnumcols(dbproc); if ((columns = calloc(ncols, sizeof(struct COL))) == NULL) { perror(NULL); exit(1); } /* * Read metadata and bind. */ for (pcol = columns; pcol - columns < ncols; pcol++) { int c = pcol - columns + 1; pcol->name = dbcolname(dbproc, c); pcol->type = dbcoltype(dbproc, c); pcol->size = dbcollen(dbproc, c); if (SYBCHAR != pcol->type) { pcol->size = dbprcollen(dbproc, c); if (pcol->size > 255) pcol->size = 255; } printf("%*s ", pcol->size, pcol->name); if ((pcol->buffer = calloc(1, pcol->size + 1)) == NULL){ perror(NULL); exit(1); } erc = dbbind(dbproc, c, NTBSTRINGBIND, pcol->size+1, (BYTE*)pcol->buffer); if (erc == FAIL) { fprintf(stderr, "%s:%d: dbbind(%d) failed\n", options.appname, __LINE__, c); exit(1); } erc = dbnullbind(dbproc, c, &pcol->status); if (erc == FAIL) { fprintf(stderr, "%s:%d: dbnullbind(%d) failed\n", options.appname, __LINE__, c); exit(1); } } printf("\n"); /* * Print the data to stdout. */ while ((row_code = dbnextrow(dbproc)) != NO_MORE_ROWS){ switch (row_code) { case REG_ROW: for (pcol=columns; pcol - columns < ncols; pcol++) { char *buffer = pcol->status == -1? "NULL" : pcol->buffer; printf("%*s ", pcol->size, buffer); } printf("\n"); break; case BUF_FULL: assert(row_code != BUF_FULL); break; case FAIL: fprintf(stderr, "%s:%d: dbresults failed\n", options.appname, __LINE__); exit(1); break; default: printf("Data for computeid %d ignored\n", row_code); } } /* free metadata and data buffers */ for (pcol=columns; pcol - columns < ncols; pcol++) { free(pcol->buffer); } free(columns); /* * Get row count, if available. */ if (DBCOUNT(dbproc) > -1) fprintf(stderr, "%d rows affected\n", DBCOUNT(dbproc)); /* * Check return status */ if (dbhasretstat(dbproc) == TRUE) { printf("Procedure returned %d\n", dbretstatus(dbproc)); } } dbclose(dbproc); dbexit(); exit(0); } ``` -------------------------------- ### Connect to Server with DBD::Sybase Source: https://www.freetds.org/userguide/perl.html Connect to a SQL Server using the DBD::Sybase module. This example is similar to the DBD::ODBC connection, highlighting DBI's consistent interface. ```perl #!/usr/bin/env perl # use DBI; my $dbh = DBI->connect("dbi:Sybase:server=JDBC", 'guest', 'sybase', {PrintError => 0}); die "Unable for connect to server $DBI::errstr" unless $dbh; my $rc; my $sth; $sth = $dbh->prepare("select @@servername"); if($sth->execute) { while(@dat = $sth->fetchrow) { print "@dat\n"; } } ``` -------------------------------- ### Install Sybase Python Module Source: https://www.freetds.org/userguide/Python.html Steps to download, extract, and install the Sybase Python module (version 0.37) with FreeTDS support. Ensure FreeTDS environment variables are set correctly. ```bash $ **tar xvfz sybase-0.37.tgz** $ **cd sybase-0.37** $ **export SYBASE=/usr/local/freetds** $ **export CFLAGS "-DHAVE_FREETDS"** $ **export LD_LIBRARY_PATH=/usr/local/freetds/lib:${LD_LIBRARY_PATH}** $ **python setup.py install** ``` -------------------------------- ### cs_manage_convert Source: https://www.freetds.org/userguide/ctlib.api.summary.html Installs or retrieves a user-defined character set conversion routine. ```APIDOC ## cs_manage_convert ### Description Installs or retrieves a user-defined character set conversion routine. ### Status stub ``` -------------------------------- ### Show Compile-Time Settings with tsql Source: https://www.freetds.org/userguide/ConfirmInstall.html Use 'tsql -C' to display FreeTDS compile-time settings, including the location of freetds.conf and enabled features. This helps verify the installation environment. ```bash $ **tsql -C ** Password: Compile-time settings (established with the "configure" script) Version: freetds v1.5 freetds.conf directory: /usr/local/etc MS db-lib source compatibility: no Sybase binary compatibility: no Thread safety: yes iconv library: yes TDS version: auto iODBC: no unixODBC: no SSPI "trusted" logins: no Keberos: no OpenSSL: yes GnuTLS: no MARS: yes ``` -------------------------------- ### Sample ODBC-only odbc.ini file Source: https://www.freetds.org/userguide/odbcinionly.html This configuration file defines data source names (DSNs) and their associated connection parameters for ODBC. Ensure the Driver path is correct for your FreeTDS installation. ```ini [ODBC Data Sources][12] JDBC = Sybase JDBC Server [JDBC] Driver = /usr/local/freetds/lib/libtdsodbc.so Description = Sybase JDBC Server Trace = No Server = jdbc.sybase.com Database = pubs2 Port = 4444 TDS_Version = 5.0 [Default] Driver = /usr/local/freetds/lib/libtdsodbc.so ``` -------------------------------- ### Configure TDS Connection Pool (`pool.conf`) Source: https://www.freetds.org/userguide/tdspool.html Example configuration file for the FreeTDS connection pool server. It demonstrates global settings for connection limits and idle timeouts, as well as specific settings for a pool named 'mypool'. ```ini [global] min pool conn = 5 max pool conn = 10 max member age = 120 [mypool] user = webuser password = secret database = ebiz server = fooserv max pool conn = 7 port = 5000 ``` -------------------------------- ### Build Sample Code Source: https://www.freetds.org/userguide/samplecode.html Commands to extract and compile the DB-Library sample code. Ensure include and library paths are correctly set for your system. ```bash $ **../doc/grep_sample_code ../doc/userguide.xml > sample.c** $ **cc -I /usr/local/include -Wl,-L/usr/local/lib -Wl,-R/usr/local/lib sample.c -lsybdb -o sample** ``` -------------------------------- ### Connect to the Server Source: https://www.freetds.org/userguide/samplecode.html Establishes a connection to the database server using the provided login information and optionally selects a specific database. dbopen() forms the connection, and dbuse() switches to the desired database. ```c if ((dbproc = dbopen(login, options.servername)) == NULL) { fprintf(stderr, "%s:%d: unable to connect to %s as %s\n", options.appname, __LINE__, options.servername, options.username); exit(1); } if (options.dbname && (erc = dbuse(dbproc, options.dbname)) == FAIL) { fprintf(stderr, "%s:%d: unable to use to database %s\n", options.appname, __LINE__, options.dbname); exit(1); } ``` -------------------------------- ### Login with Domain Credentials Source: https://www.freetds.org/userguide/index.html Demonstrates how to log in to a server using domain credentials. This typically involves specifying the domain in the username. ```bash tsql -U MYDOMAIN\myuser -P mypassword ``` -------------------------------- ### cs_set_convert Source: https://www.freetds.org/userguide/ctlib.api.summary.html Installs or retrieves a user-defined conversion routine. ```APIDOC ## cs_set_convert ### Description Installs or retrieves a user-defined conversion routine. ### Status stub ``` -------------------------------- ### DB-Library Prolog: Argument Parsing Source: https://www.freetds.org/userguide/samplecode.html Parses command-line options for server, database, username, and password using getopt. Initializes DB-Library structures. ```c extern char *optarg; extern int optind; const static char syntax[] = "syntax: example -S server -D db -U user -P passwd\n"; struct { char *appname, *servername, *dbname, *username, *password; } options = {0,0,0,0,0}; int main(int argc, char *argv[]) { int i, ch; LOGINREC *login; DBPROCESS *dbproc; RETCODE erc; options.appname = basename(argv[0]); while ((ch = getopt(argc, argv, "U:P:S:D:")) != -1) { switch (ch) { case 'S': options.servername = strdup(optarg); break; case 'D': options.dbname = strdup(optarg); break; case 'U': options.username = strdup(optarg); break; case 'P': options.password = strdup(optarg); break; case '?': default: fprintf(stderr, syntax); exit(1); } } argc -= optind; argv += optind; if (! (options.servername && options.username && options.password)) { fprintf(stderr, syntax); exit(1); } ``` -------------------------------- ### Configure UTF-8 freetds.conf Setting Source: https://www.freetds.org/userguide/index.html Example of configuring the 'client charset' to UTF-8 in 'freetds.conf'. This is essential for handling a wide range of characters. ```ini [myserver] client charset = UTF-8 ``` -------------------------------- ### blk_init Source: https://www.freetds.org/userguide/ctlib.api.summary.html Initiates a bulk copy operation. ```APIDOC ## blk_init ### Description Initiates a bulk copy operation. ### Status OK ``` -------------------------------- ### DSN-less Configuration Sample Source: https://www.freetds.org/userguide/index.html Provides a sample configuration for connecting to a database without using a Data Source Name (DSN). This is useful for application-specific configurations. ```ini [myserver] host = 192.168.1.100 port = 1433 database = mydb ``` -------------------------------- ### Sample odbc.ini Configuration Source: https://www.freetds.org/userguide/uothread.html This is a sample odbc.ini file showing how to reference the FreeTDS driver. It includes server details like Server and Port. ```ini [Server1] Driver = FreeTDS Server = myServer1 Port = 1433 ``` -------------------------------- ### Run TDS Connection Pool Server Source: https://www.freetds.org/userguide/tdspool.html Command to start the FreeTDS connection pool server, specifying the name of the pool configuration to use. ```bash $ ** tdspool mypool** ``` -------------------------------- ### Set SYBASE and TDSVER in csh Source: https://www.freetds.org/userguide/envvar.html Use the 'setenv' command to set the SYBASE and TDSVER environment variables in csh. Ensure the SYBASE path points to your FreeTDS installation. ```shell $ **setenv SYBASE /usr/local/freetds** $ **setenv TDSVER 7.4** ``` -------------------------------- ### DB-Library Initialize Source: https://www.freetds.org/userguide/index.html Code snippet for initializing the DB-Library environment. This is a prerequisite for using DB-Library functions. ```c #include #include // ... DBPROCESS *dbproc; LOGINREC *loginrec; loginrec = dblogin(); // ... ``` -------------------------------- ### tsql Hostname Resolution Failure Source: https://www.freetds.org/userguide/ConfirmInstall.html This example illustrates a FreeTDS connection failure when the server name is found in freetds.conf but the specified hostname cannot be resolved. It shows the resulting error message from tsql. ```bash $ **tsql -S _nonesuch_ -U _sa_ ** Password: locale is "C" locale charset is "646" Error 20013 (severity 2): Unknown host machine name. There was a problem connecting to the server ``` -------------------------------- ### Set SYBASE and TDSVER in Bourne Shell Source: https://www.freetds.org/userguide/envvar.html Use the 'export' command to set the SYBASE and TDSVER environment variables in Bourne shell, ksh, or bash. Adjust the SYBASE path to your FreeTDS installation directory. ```shell $ **export SYBASE=/usr/local/freetds** # (or your favorite directory) $ **export TDSVER=7.4** ``` -------------------------------- ### Configure PHP with DB-Library Source: https://www.freetds.org/userguide/php.html Configure PHP to use the FreeTDS DB-Library. This enables 'Sybase' server compatibility. ```bash $ **cd php** $ **./configure --with-sybase=/usr/local/freetds** $ **make** $ **sudo make install** ``` -------------------------------- ### ODBC-combined odbc.ini Sample Source: https://www.freetds.org/userguide/index.html A sample 'odbc.ini' file that combines ODBC and FreeTDS settings. This allows for more integrated configurations. ```ini [myserver] Driver = FreeTDS Servername = myserver Database = mydb [another_server] Driver = FreeTDS Servername = another_server Database = another_db ``` -------------------------------- ### Static Linker: Library Not Found Source: https://www.freetds.org/userguide/linker.how.html This error indicates that the linker cannot locate a specified library. The library may be installed but not in the linker's default search path. You might need to specify the library's location. ```bash $ **gcc -o bsqldb bsqldb.o -l sybdb** ld: cannot find -lsybdb ``` -------------------------------- ### Build SQSH Makefile Source: https://www.freetds.org/userguide/index.html The Makefile for building the SQSH utility. This is a command-line SQL client for Sybase and SQL Server. ```makefile # SQSH Makefile # Define the C compiler and flags CC = gcc CFLAGS = -O2 -Wall # Define the libraries to link against LIBS = -L/usr/lib -lsybdb # Define the executable name TARGET = sqsh # Define the source files SRCS = sqsh.c commands.c parse.c util.c # Define the object files OBJS = $(SRCS:.c=.o) # Default target all: $(TARGET) $(TARGET): $(OBJS) $(CC) $(OBJS) -o $(TARGET) $(LIBS) %.o: % $(CC) $(CFLAGS) -c $< -o $@ clean: rm -f $(OBJS) $(TARGET) ``` -------------------------------- ### tsql Servername Lookup Failure Source: https://www.freetds.org/userguide/ConfirmInstall.html This example demonstrates troubleshooting a FreeTDS connection failure where the server name is not found in configuration files or cannot be resolved by DNS. It shows the error messages produced by tsql and the 'host' command. ```bash $ **tsql -S _nobox_ -U _sa_ ** Password: locale is "C" locale charset is "646" Password: Error 20012 (severity 2): Server name not found in configuration files. Error 20013 (severity 2): Unknown host machine name. There was a problem connecting to the server $ **host nobox** Host not found. ``` -------------------------------- ### Login with Domain Account - tsql Source: https://www.freetds.org/userguide/domains.html Use this syntax with the 'tsql' command-line tool to log in using a domain account when SSPI or Kerberos is not enabled. The username must be prefixed with the domain name and a backslash. ```bash $ **tsql -S camelot -U 'NOTTINGHAM\lancelot' -P roundtable** locale is "C" locale charset is "646" Msg 5703, Level 0, State 1, Server CPRO200, Line 0 Changed language setting to middle_english. 1> ``` -------------------------------- ### Clone FreeTDS Git Repository Source: https://www.freetds.org/userguide/packages.html Use this command to clone the FreeTDS git repository. This provides access to the latest development code, which often includes fixes and new features not yet in release versions. Ensure you have git installed. ```bash $ **git clone https://github.com/FreeTDS/freetds.git** $ ``` -------------------------------- ### DB-Library Connect to Server Source: https://www.freetds.org/userguide/index.html Code snippet for establishing a connection to a database server using DB-Library. This involves using login records and DBPROCESS structures. ```c #include #include // ... DBPROCESS *dbproc; LOGINREC *loginrec; loginrec = dblogin(); dbinit(loginrec, "myserver"); dbopen(loginrec, "myuser", "mypassword"); dbproc = dbopen(loginrec, "myserver"); // ... ``` -------------------------------- ### Sample odbc.ini for Threading Model Source: https://www.freetds.org/userguide/index.html A sample 'odbc.ini' file configured for a specific threading model. This complements the 'odbcinst.ini' settings. ```ini [myserver] Driver = FreeTDS Servername = myserver Database = mydb Threading = 1 ``` -------------------------------- ### DB-Library Error Handler Example Source: https://www.freetds.org/userguide/samplecode.html Implement a custom error handler for DB-Library. This function logs DB-Library errors or operating system errors to stderr, indicating the application name, error number, and severity. It returns INT_CANCEL to abort the operation. ```c int err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) { if (dberr) { fprintf(stderr, "%s: Msg %d, Level %d\n", options.appname, dberr, severity); fprintf(stderr, "%s\n\n", dberrstr); } else { fprintf(stderr, "%s: DB-LIBRARY error:\n\t", options.appname); fprintf(stderr, "%s\n", dberrstr); } return INT_CANCEL; } ``` -------------------------------- ### Sample odbcinst.ini for Threading Model Source: https://www.freetds.org/userguide/index.html A sample 'odbcinst.ini' file demonstrating the configuration for a specific threading model. This is crucial for multi-threaded applications. ```ini [ODBC Drivers] FreeTDS = Installed [FreeTDS] Description = FreeTDS ODBC Driver Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsSrv.so UsageCount = 1 Threading = 1 ``` -------------------------------- ### DB-Library Message Handler Example Source: https://www.freetds.org/userguide/samplecode.html Implement a custom message handler for DB-Library. This function processes server messages, returning 0 for benign messages like database or language changes, and logs others to stderr. It exits the application for messages with severity greater than 10. ```c int msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line) { enum {changed_database = 5701, changed_language = 5703 }; if (msgno == changed_database || msgno == changed_language) return 0; if (msgno > 0) { fprintf(stderr, "Msg %ld, Level %d, State %d\n", (long) msgno, severity, msgstate); if (strlen(srvname) > 0) fprintf(stderr, "Server '%s', ", srvname); if (strlen(procname) > 0) fprintf(stderr, "Procedure '%s', ", procname); if (line > 0) fprintf(stderr, "Line %d", line); fprintf(stderr, "\n\t"); } fprintf(stderr, "%s\n", msgtext); if (severity > 10) { fprintf(stderr, "%s: error: severity %d > 10, exiting\n", options.appname, severity); exit(severity); } return 0; } ``` -------------------------------- ### C: Connecting with DSN-less Configuration (explicit details) Source: https://www.freetds.org/userguide/dsnless.html This C code snippet shows how to connect without referencing freetds.conf or odbc.ini. All connection parameters like host, port, and TDS version are explicitly provided in the connection string. ```c /* * application call */ const char servername[] = "jdbc.sybase.com"; [11] sprintf(tmp, "DRIVER=FreeTDS[10];SERVER=%s;UID=%s;PWD=%s;DATABASE=%s;TDS_Version=5.0;Port=4444;", servername, username, password, dbname); res = SQLDriverConnect(Connection, NULL, (SQLCHAR *) tmp, SQL_NTS, (SQLCHAR *) tmp, sizeof(tmp), &len, SQL_DRIVER_NOPROMPT); if (!SQL_SUCCEEDED(res)) { fprintf(stderr, "Unable to open data source (ret=%d)\n", res); exit(1); } ``` -------------------------------- ### Connect with tsql using Hostname and Port Source: https://www.freetds.org/userguide/index.html Demonstrates connecting to a FreeTDS server using the 'tsql' utility, specifying both the hostname and port number. ```bash tsql -H myhost.example.com -p 1433 ``` -------------------------------- ### Sample odbc.ini for ODBC-combined configuration Source: https://www.freetds.org/userguide/odbcombo.html This file defines the ODBC data sources and their connection details. The 'Servername' in the DSN entry must match an entry in freetds.conf. ```ini [ODBC Data Sources][13] JDBCdsn = Sybase JDBC Server [JDBCdsn] Driver = /usr/local/freetds/lib/libtdsodbc.so Description = Sybase JDBC Server Trace = No Servername = JDBC[14] Database = pubs2 [Default] Driver = /usr/local/freetds/lib/libtdsodbc.so ``` -------------------------------- ### Configure FreeTDS on VMS Source: https://www.freetds.org/userguide/osissues.html Run the configure script on VMS to generate the descrip.mms file. Ensure you are in the top-level source directory. ```shell $ @[.vms]configure ``` -------------------------------- ### Compare UCS-2 and UTF-8 Encoding of 'HELLO' Source: https://www.freetds.org/userguide/UnicodeUtf.html Compares the byte representation of the string 'HELLO' when encoded in UCS-2 and UTF-8, demonstrating UTF-8's ASCII compatibility. The last two commands show the output of UTF-8 and plain ASCII, which are identical. ```shell $ echo HELLO | iconv -f ascii -t UCS-2 | hexdump -C 00000000 00 48 00 45 00 4c 00 4c 00 4f 00 0a |.H.E.L.L.O..| 0000000c ``` ```shell $ echo HELLO | iconv -f ascii -t utf-8 | hexdump -C 00000000 48 45 4c 4c 4f 0a |HELLO.| 00000006 ``` ```shell $ echo HELLO | hexdump -C 00000000 48 45 4c 4c 4f 0a |HELLO.| 00000006 ``` -------------------------------- ### Basic FreeTDS Configuration Source: https://www.freetds.org/userguide/config.html The simplest way to run the 'configure' script for FreeTDS. This command generates the Makefile for compilation. ```bash $ **./configure** ``` -------------------------------- ### Connect to Server Using freetds.conf Source: https://www.freetds.org/userguide/index.html Connect to a FreeTDS server using the configuration defined in 'freetds.conf'. This relies on the server entry in the configuration file. ```bash tsql -S myserver -U myuser -P mypassword -D mydb ``` -------------------------------- ### Build FreeTDS for DB-Library Source: https://www.freetds.org/userguide/php.html Standard build process for FreeTDS. Ensure FreeTDS is built before configuring PHP. ```bash $ **./configure --prefix=/usr/local/freetds** $ **make** $ **sudo make install** ``` -------------------------------- ### Sample freetds.conf for ODBC-combined configuration Source: https://www.freetds.org/userguide/odbcombo.html This file contains server connection details, referenced by the 'Servername' in the odbc.ini file. It specifies the host, port, and TDS version. ```ini ; ; freetds.conf ; [JDBC] host = jdbc.sybase.com port = 4444 tds version = 5.0 ```