├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── AUTHORS ├── BUGS ├── CMakeLists.txt ├── COPYING ├── COPYING.LIB ├── ChangeLog ├── ChangeLog-0.82 ├── ChangeLog-0.91 ├── ChangeLog-2001 ├── ChangeLog-2002 ├── ChangeLog-2003 ├── ChangeLog-2004 ├── ChangeLog-2005 ├── ChangeLog-2006 ├── ChangeLog-2007 ├── INSTALL ├── INSTALL.GIT ├── Makefile.am ├── NEWS ├── PWD.in ├── README ├── README.Windows ├── TODO ├── TODO.freddy ├── Thanks-0.95 ├── autogen.sh ├── config.rpath ├── configure.ac ├── doc ├── .gitignore ├── CodingStyle ├── Makefile.am ├── README.releasing ├── api_status.txt ├── bcp.txt ├── bsqldb.1.in ├── bsqlodbc.1.in ├── cap.txt ├── datacopy.1.in ├── dblib_errors.txt ├── defncopy.1.in ├── developer ├── fisql.1.in ├── freebcp.1.in ├── freetds.conf.5.in ├── getting_started.txt ├── grep_sample_code ├── htdoc │ ├── contrib.html │ ├── docs.html │ ├── faq.html │ ├── freetds.css │ ├── freetdslogo3.gif │ ├── index.html │ ├── mars.html │ ├── news.html │ ├── software.html │ ├── support.html │ └── which_api.html ├── images │ ├── callouts │ │ ├── 1.gif │ │ ├── 10.gif │ │ ├── 2.gif │ │ ├── 3.gif │ │ ├── 4.gif │ │ ├── 5.gif │ │ ├── 6.gif │ │ ├── 7.gif │ │ ├── 8.gif │ │ └── 9.gif │ ├── caution.gif │ ├── important.gif │ ├── note.gif │ ├── tip.gif │ └── warning.gif ├── osql.1.in ├── policy.txt ├── tds.html ├── tds_ssl.html ├── tsql.1.in ├── userguide.css ├── userguide.dsl.in └── userguide.sgml ├── freetds.conf ├── freetds.spec.in ├── include ├── .gitignore ├── Makefile.am ├── bkpublic.h ├── cspublic.h ├── cstypes.h ├── ctlib.h ├── ctpublic.h ├── dblib.h ├── des.h ├── freetds │ ├── Makefile.am │ ├── bool.h │ ├── bytes.h │ ├── checks.h │ ├── configs.h │ ├── convert.h │ ├── data.h │ ├── dlist.h │ ├── dlist.tmpl.h │ ├── enum_cap.h │ ├── iconv.h │ ├── odbc.h │ ├── popvis.h │ ├── proto.h │ ├── pushvis.h │ ├── server.h │ ├── stream.h │ ├── string.h │ ├── sysdep_private.h │ ├── tds.h │ ├── thread.h │ ├── time.h │ ├── tls.h │ └── version.h.in ├── hmac_md5.h ├── md4.h ├── md5.h ├── odbcss.h ├── replacements.h ├── replacements │ ├── poll.h │ └── readpassphrase.h ├── sqldb.h ├── sqlfront.h ├── sybdb.dox.h ├── sybdb.h ├── syberror.h ├── sybfront.h └── tds_sysdep_public.h.in ├── interfaces ├── locales.conf ├── m4 ├── .gitignore ├── ac_caolan_func_which_gethostbyname_r.m4 ├── ac_have_inaddr_none.m4 ├── ac_have_malloc_options.m4 ├── ac_nullzero.m4 ├── ac_raf_func_which_getservbyname_r.m4 ├── ac_tds_func_which_gethostbyaddr_r.m4 ├── ac_tds_func_which_getpwuid_r.m4 ├── ac_tds_func_which_localtime_r.m4 ├── acx_pthread.m4 ├── ax_cflags_gcc_option.m4 ├── check_openssl.m4 ├── gettimemilli.m4 ├── pushlibs.m4 ├── sprintf_i64_format.m4 └── type_socklen_t.m4 ├── misc ├── Makefile.am ├── appveyor.yml ├── bounce.c ├── check_symbols ├── check_symbols.txt ├── cmake_checks.c ├── coverage.sh ├── fixdoxyres ├── freetds_autobuild ├── full-test.sh ├── grabcov ├── online.pl ├── prepare_win32.sh ├── run_with_compiler.cmd ├── sql-server-activate-tcp-fixed-port.ps1 ├── sybase_tests ├── tds-makeenvs ├── test-auto.sh ├── test-dist.sh ├── test-other.sh ├── types.csv ├── unzipsfx.exe ├── write_PWD_from_env_vars.sh └── zip.exe ├── mkinstalldirs ├── phptests ├── nextres.php ├── null.php ├── rpc1.php ├── rpc2.php └── types.php ├── samples ├── .gitignore ├── Makefile.am ├── Makefile.bcp_test ├── README ├── bcp_test.cpp ├── debug.c ├── dyntest.c ├── isql.sybperl ├── mssql.php ├── odbc.ini ├── odbc_rpc.pl ├── odbcfunc.pl ├── odbctest.php ├── odbctest.pl ├── odbschema.pl ├── test.php ├── test.pl ├── unixodbc.freetds.driver.template.in ├── unixodbc.install.sh └── unixodbc.jdbc.datasource.template ├── src ├── .indent.pro ├── Makefile.am ├── apps │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── bsqldb.1 │ ├── bsqldb.c │ ├── bsqlodbc.c │ ├── datacopy.c │ ├── defncopy.c │ ├── fisql │ │ ├── .gitignore │ │ ├── Makefile.am │ │ ├── edit.c │ │ ├── edit.h │ │ ├── fisql.c │ │ ├── handlers.c │ │ ├── handlers.h │ │ ├── interrupt.c │ │ ├── interrupt.h │ │ ├── terminal.c │ │ └── terminal.h │ ├── freebcp.c │ ├── freebcp.h │ ├── osql │ └── tsql.c ├── ctlib │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── blk.c │ ├── cs.c │ ├── ct.c │ ├── ctlib.def │ ├── ctutil.c │ ├── unittests │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── Makefile.am │ │ ├── array_bind.c │ │ ├── blk_in.c │ │ ├── blk_in.h │ │ ├── blk_in2.c │ │ ├── blk_out.c │ │ ├── cancel.c │ │ ├── common.c │ │ ├── common.h │ │ ├── connect_fail.c │ │ ├── cs_config.c │ │ ├── cs_diag.c │ │ ├── ct_cursor.c │ │ ├── ct_cursors.c │ │ ├── ct_diagall.c │ │ ├── ct_diagclient.c │ │ ├── ct_diagserver.c │ │ ├── ct_dynamic.c │ │ ├── ct_options.c │ │ ├── datafmt.c │ │ ├── get_send_data.c │ │ ├── lang_ct_param.c │ │ ├── rpc_ct_param.c │ │ ├── rpc_ct_setparam.c │ │ ├── rpc_fail.c │ │ ├── t0001.c │ │ ├── t0002.c │ │ ├── t0003.c │ │ ├── t0004.c │ │ ├── t0005.c │ │ ├── t0006.c │ │ ├── t0007.c │ │ ├── t0008.c │ │ └── t0009.c │ └── winmain.c ├── dblib │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── bcp.c │ ├── buffering.h │ ├── dblib.c │ ├── dblib.def │ ├── dbopen.c │ ├── dbpivot.c │ ├── dbutil.c │ ├── error_table.h │ ├── rpc.c │ ├── unittests │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── Makefile.am │ │ ├── README │ │ ├── bcp.c │ │ ├── bcp.h │ │ ├── bcp.sql │ │ ├── cancel.c │ │ ├── cancel.sql │ │ ├── common.c │ │ ├── common.h │ │ ├── data.bin │ │ ├── dbmorecmds.c │ │ ├── dbmorecmds.sql │ │ ├── done_handling.c │ │ ├── done_handling.sql │ │ ├── hang.c │ │ ├── null.c │ │ ├── null2.c │ │ ├── numeric.c │ │ ├── numeric.sql │ │ ├── numeric_2.sql │ │ ├── pending.c │ │ ├── pending.sql │ │ ├── rpc.c │ │ ├── rpc.sql │ │ ├── setnull.c │ │ ├── spid.c │ │ ├── spid.sql │ │ ├── t0001.c │ │ ├── t0001.sql │ │ ├── t0002.c │ │ ├── t0002.sql │ │ ├── t0003.c │ │ ├── t0003.sql │ │ ├── t0004.c │ │ ├── t0004.sql │ │ ├── t0005.c │ │ ├── t0005.sql │ │ ├── t0006.c │ │ ├── t0006.sql │ │ ├── t0007.c │ │ ├── t0007.sql │ │ ├── t0008.c │ │ ├── t0009.c │ │ ├── t0009.sql │ │ ├── t0011.c │ │ ├── t0011.sql │ │ ├── t0012.c │ │ ├── t0012.sql │ │ ├── t0013.c │ │ ├── t0013.sql │ │ ├── t0014.c │ │ ├── t0014.sql │ │ ├── t0015.c │ │ ├── t0015.sql │ │ ├── t0016.c │ │ ├── t0016.in │ │ ├── t0016.sql │ │ ├── t0016_1.in │ │ ├── t0016_1.sql │ │ ├── t0016_10.in │ │ ├── t0016_10.sql │ │ ├── t0016_11.in │ │ ├── t0016_11.sql │ │ ├── t0016_2.in │ │ ├── t0016_2.sql │ │ ├── t0016_3.in │ │ ├── t0016_3.sql │ │ ├── t0016_4.in │ │ ├── t0016_4.sql │ │ ├── t0016_5.in │ │ ├── t0016_5.sql │ │ ├── t0016_6.in │ │ ├── t0016_6.sql │ │ ├── t0016_7.in │ │ ├── t0016_7.sql │ │ ├── t0016_8.in │ │ ├── t0016_8.sql │ │ ├── t0016_9.in │ │ ├── t0016_9.sql │ │ ├── t0017.c │ │ ├── t0017.in │ │ ├── t0017.in.be │ │ ├── t0017.sql │ │ ├── t0018.c │ │ ├── t0018.sql │ │ ├── t0019.c │ │ ├── t0020.c │ │ ├── t0020.sql │ │ ├── t0021.c │ │ ├── t0022.c │ │ ├── t0022.sql │ │ ├── t0023.c │ │ ├── t0023.sql │ │ ├── text_buffer.c │ │ ├── text_buffer.sql │ │ ├── thread.c │ │ ├── timeout.c │ │ └── timeout.sql │ ├── winmain.c │ └── xact.c ├── odbc │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── bcp.c │ ├── checkexport.sh │ ├── connectparams.c │ ├── convert_tds2sql.c │ ├── descriptor.c │ ├── error.c │ ├── native.c │ ├── odbc.c │ ├── odbc.def │ ├── odbc_checks.c │ ├── odbc_data.c │ ├── odbc_export.pl │ ├── odbc_util.c │ ├── odbc_w.def │ ├── prepare_query.c │ ├── resource.h │ ├── setup.rc │ ├── sql2tds.c │ ├── sqlwchar.c │ ├── sqlwparams.h │ ├── unittests │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── Makefile.am │ │ ├── array.c │ │ ├── array_error.c │ │ ├── array_out.c │ │ ├── attributes.c │ │ ├── attributes.in │ │ ├── base.c │ │ ├── bcp.c │ │ ├── binary_test.c │ │ ├── blob1.c │ │ ├── c2string.c │ │ ├── cancel.c │ │ ├── closestmt.c │ │ ├── common.c │ │ ├── common.h │ │ ├── compute.c │ │ ├── connect.c │ │ ├── connect2.c │ │ ├── const_params.c │ │ ├── convert_error.c │ │ ├── copydesc.c │ │ ├── cursor1.c │ │ ├── cursor2.c │ │ ├── cursor3.c │ │ ├── cursor4.c │ │ ├── cursor5.c │ │ ├── cursor6.c │ │ ├── cursor7.c │ │ ├── data.c │ │ ├── data.in │ │ ├── date.c │ │ ├── descrec.c │ │ ├── describecol.c │ │ ├── describecol.in │ │ ├── describecol2.c │ │ ├── earlybind.c │ │ ├── error.c │ │ ├── freeclose.c │ │ ├── funccall.c │ │ ├── genparams.c │ │ ├── getdata.c │ │ ├── hidden.c │ │ ├── insert_speed.c │ │ ├── lang_error.c │ │ ├── long_error.c │ │ ├── mars1.c │ │ ├── moreandcount.c │ │ ├── norowset.c │ │ ├── oldpwd.c │ │ ├── paramcore.c │ │ ├── params.c │ │ ├── parser.c │ │ ├── parser.h │ │ ├── peter.c │ │ ├── prepare_results.c │ │ ├── prepare_warn.c │ │ ├── prepclose.c │ │ ├── preperror.c │ │ ├── print.c │ │ ├── putdata.c │ │ ├── raiserror.c │ │ ├── rebindpar.c │ │ ├── rownumber.c │ │ ├── rowset.c │ │ ├── rpc.c │ │ ├── scroll.c │ │ ├── stats.c │ │ ├── t0001.c │ │ ├── t0002.c │ │ ├── t0003.c │ │ ├── t0004.c │ │ ├── tables.c │ │ ├── test64.c │ │ ├── testodbc.c │ │ ├── timeout.c │ │ ├── timeout2.c │ │ ├── timeout3.c │ │ ├── timeout4.c │ │ ├── transaction.c │ │ ├── transaction2.c │ │ ├── type.c │ │ ├── typeinfo.c │ │ ├── utf8.c │ │ ├── utf8_2.c │ │ ├── warning.c │ │ └── wchar.c │ ├── version.rc.in │ ├── winlogin.c │ ├── winmain.c │ └── winsetup.c ├── pool │ ├── .gitignore │ ├── BUGS │ ├── Makefile.am │ ├── README │ ├── TODO │ ├── config.c │ ├── main.c │ ├── member.c │ ├── pool.conf │ ├── pool.h │ ├── stream.c │ ├── user.c │ └── util.c ├── replacements │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── asprintf.c │ ├── basename.c │ ├── daemon.c │ ├── getaddrinfo.c │ ├── getopt.c │ ├── getpassarg.c │ ├── gettimeofday.c │ ├── iconv.c │ ├── poll.c │ ├── ptw32_MCS_lock.c │ ├── readpassphrase.c │ ├── sleep.c │ ├── socketpair.c │ ├── strlcat.c │ ├── strlcpy.c │ ├── strsep.c │ ├── strtok_r.c │ ├── tds_cond.c │ ├── unittests │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── Makefile.am │ │ ├── condition.c │ │ ├── mutex1.c │ │ ├── passarg.c │ │ ├── strings.c │ │ └── strtok_r.c │ ├── vasprintf.c │ └── win_mutex.c ├── server │ ├── .gitignore │ ├── Makefile.am │ ├── login.c │ ├── query.c │ ├── server.c │ └── unittest.c └── tds │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── alternative_character_sets.h │ ├── bulk.c │ ├── challenge.c │ ├── character_sets.h │ ├── config.c │ ├── convert.c │ ├── data.c │ ├── des.c │ ├── dlist.c │ ├── encodings.pl │ ├── example │ ├── token1.c │ └── token2.c │ ├── getmac.c │ ├── gssapi.c │ ├── hmac_md5.c │ ├── iconv.c │ ├── locale.c │ ├── log.c │ ├── login.c │ ├── md4.c │ ├── md5.c │ ├── mem.c │ ├── net.c │ ├── num_limits.pl │ ├── numeric.c │ ├── packet.c │ ├── query.c │ ├── random.c │ ├── read.c │ ├── sec_negotiate.c │ ├── sec_negotiate_gnutls.h │ ├── sec_negotiate_openssl.h │ ├── sspi.c │ ├── stream.c │ ├── tds_checks.c │ ├── tds_willconvert.pl │ ├── tdsstring.c │ ├── threadsafe.c │ ├── tls.c │ ├── token.c │ ├── types.pl │ ├── unittests │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── challenge.c │ ├── charconv.c │ ├── collations.c │ ├── common.c │ ├── common.h │ ├── convert.c │ ├── corrupt.c │ ├── dataread.c │ ├── dynamic1.c │ ├── flags.c │ ├── iconv_fread.c │ ├── nulls.c │ ├── numeric.c │ ├── readconf.c │ ├── readconf.in │ ├── t0001.c │ ├── t0002.c │ ├── t0003.c │ ├── t0004.c │ ├── t0005.c │ ├── t0006.c │ ├── t0007.c │ ├── t0008.c │ ├── toodynamic.c │ ├── utf8.c │ ├── utf8_1.c │ ├── utf8_2.c │ └── utf8_3.c │ ├── util.c │ ├── vstrbuild.c │ └── write.c ├── tds.dox ├── vms ├── Makefile.am ├── README.vms ├── config_h.vms ├── configure.com ├── descrip_mms.template ├── edit.c ├── getpass.c ├── libodbc.opt ├── odbc_driver_axp.opt ├── vargdefs.h ├── vmsarg_command_bcp.cld ├── vmsarg_command_defncopy.cld ├── vmsarg_command_isql.cld ├── vmsarg_mapping_bcp.c ├── vmsarg_mapping_defncopy.c ├── vmsarg_mapping_isql.c └── vmsarg_parse.c └── win32 ├── .gitignore ├── Makefile.am ├── freetds.nsh.in ├── freetds.nsi ├── freetds └── sysconfdir.h ├── initnet.c └── installfreetds.bat /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # Tab indentation (no size specified) 12 | [*.c] 13 | indent_style = tab 14 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | include/freetds/version.h.in ident 2 | doc/htdoc/faq.html ident 3 | doc/README.releasing ident 4 | NEWS ident 5 | README ident 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .build_options 2 | .gitignore 3 | *.orig 4 | push 5 | update 6 | commit 7 | t 8 | cscope.files 9 | cscope.out 10 | *Makefile.in 11 | build/ 12 | doc/mdoc.gen 13 | config.log 14 | config.cache 15 | config.status 16 | config.sub 17 | config.guess 18 | configure 19 | libtool 20 | ltmain.sh 21 | ltconfig 22 | ltcf-c.sh 23 | aclocal.m4 24 | autom4te.cache 25 | depcomp 26 | so_locations 27 | freetds.spec 28 | PWD 29 | doxyfile 30 | test-dist.log 31 | compile 32 | install-sh 33 | *.o 34 | *.lo 35 | *.la 36 | .deps/ 37 | .libs/ 38 | Makefile 39 | *~ 40 | include/freetds/sysconfdir.h 41 | include/freetds/version.h 42 | test-driver 43 | *.log 44 | *.trs 45 | *.out 46 | *.gcno 47 | *.gcda 48 | missing 49 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | 2 | Believed Fixed 3 | -------------- 4 | 1. code to send COL_NAME and COL_INFO tokens are not in the server stuff. 5 | 6 | Needs Fixing 7 | ------------ 8 | 1. Fix formatting of dbprhead/dbprrow...its a little off 9 | (Anybody care?) 10 | 2. dbwritetext() and friends do not work under TDS 7.0 11 | 3. There is a bug with the order of returns from ct_results() such that rows 12 | affected doesn't show up in sqsh. 13 | 4. ct-lib placeholders do not work with TDS 7.0+. To fix 14 | this requires either an SQL parser or API modification, 15 | because the library has to determine the SQL datatype 16 | of the placeholder variable. 17 | 5. ML Mar 21 2009: "freebcp error HINT -b doesnt work", freebcp -n broken. 18 | 6. ML 2 Aug 2012 "SQL Anywhere SQLColumns". Rewrite SQLColumns query 19 | in terms of INFORMATION_SCHEMA to get consistent results. 20 | -------------------------------------------------------------------------------- /INSTALL.GIT: -------------------------------------------------------------------------------- 1 | Building FreeTDS from git 2 | James Cameron 3 | 4 | The git repository is maintained on GitHub. Follow these steps: 5 | 6 | 1) satisfy build dependencies, ensure that the following packages are 7 | installed: 8 | 9 | automake (GNU Automake, generates Makefile.in from Makefile.am) 10 | autoconf (GNU Autoconf, generates configure from configure.ac) 11 | libtool (GNU Libtool, library creation support scripts) 12 | make (GNU or BSD Make.) 13 | gcc (GNU Compiler Collection, for C code compilation) 14 | perl (Perl, used to generate some files) 15 | 16 | Autotool versions that work: 17 | $ (autoconf --version; automake --version; libtool --version) |grep GNU 18 | autoconf (GNU Autoconf) 2.60 19 | automake (GNU automake) 1.9.6 20 | ltmain.sh (GNU libtool) 1.5.18 (1.1220.2.245 2005/05/16 08:55:27) 21 | 22 | The above are used to generate the distributions. 23 | You may get away with older versions, as far back as 2.53 for autoconf. 24 | 25 | 2) execute autogen.sh to run automake, autoconf and configure, 26 | 27 | ./autogen.sh 28 | 29 | Any switches provided to autogen.sh will be passed to the configure script. 30 | 31 | 3) compile the source using make, 32 | 33 | make 34 | 35 | 5) switch to a user that can write to the target installation 36 | directory, usually root, 37 | 38 | su root 39 | 40 | 4) install the package, 41 | 42 | make install 43 | 44 | -------------------------------------------------------------------------------- /PWD.in: -------------------------------------------------------------------------------- 1 | # $Id: PWD.in,v 1.1 2002-09-12 15:24:20 castellano Exp $ 2 | # 3 | # This file was taken from DBD::Sybase :-) It is used by 'make check' to test 4 | # the installation 5 | # 6 | # UID: the username of a user to connect with 7 | # PWD: the password for that user 8 | # SRV: the symbolic server name from the freetds.conf (or interfaces) file. 9 | # Note: if you use a hostname/IP here instead, freetds will attempt to 10 | # connect using the compiletime default port (4000 for TDS 5.0, 1433 for 11 | # 4.2 or 7.0) which is usually not right. 12 | # DB: Database in which to create tables used in the tests. For those new to 13 | # Sybase or MS SQL server, there may be many database per server. tempdb 14 | # is a good default choice if unsure. 15 | # 16 | UID=guest 17 | PWD=sybase 18 | SRV=JDBC 19 | DB=tempdb 20 | -------------------------------------------------------------------------------- /README.Windows: -------------------------------------------------------------------------------- 1 | README for FreeTDS 2 | 3 | This readme provide specific informations for Windows environment. 4 | Please read README file for generic intro. 5 | 6 | FROM SCRATCH 7 | ------------ 8 | 9 | FreeTDS compile with ANSI strings. 10 | 11 | Every library have a proper directory where you can include every C file you find 12 | inside (not recursively) 13 | - replacements here there is an exception, do not include ptw32_MCS_lock.c file 14 | - tds 15 | - dblib 16 | - ctlib 17 | - odbc 18 | All libraries depends on replacements one (except replacements obviously), 19 | dblib, ctlib and odbc depends on tds. 20 | You should add ws2_32.lib to dependencies. 21 | 22 | replacements and TDS library are designed to be static libraries. 23 | 24 | You have to define UNIXODBC macro (for ODBC stuff). 25 | 26 | Also you need to include win32 and include directory (in this order!) 27 | 28 | These instructions should suffice in order to set up any project file you need. 29 | 30 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Run this to generate all the initial makefiles, etc. 3 | 4 | # $Id: autogen.sh,v 1.10 2011-03-22 17:54:04 jklowden Exp $ 5 | 6 | # From automake.info: 7 | # 8 | # Many packages come with a script called `bootstrap.sh' or 9 | # `autogen.sh', that will just call `aclocal', `libtoolize', `gettextize' 10 | # or `autopoint', `autoconf', `autoheader', and `automake' in the right 11 | # order. Actually this is precisely what `autoreconf' can do for you. 12 | # If your package has such a `bootstrap.sh' or `autogen.sh' script, 13 | # consider using `autoreconf'. That should simplify its logic a lot 14 | # (less things to maintain, yum!), it's even likely you will not need the 15 | # script anymore, and more to the point you will not call `aclocal' 16 | # directly anymore. 17 | 18 | srcdir=`dirname $0` 19 | PKG_NAME="FreeTDS." 20 | 21 | # If autoreconf encounters an error, it might be because this is the 22 | # very first time it was run, meaning that some files e.g. config.sub 23 | # are missing. We retry with --install (and perhaps we should 24 | # try --force, too). 25 | # 26 | # Revision 1.6 was the last one not to use autoreconf. If you can't get 27 | # this (simpler) one to work, you might try that one. 28 | 29 | ( cd $srcdir 30 | echo running `which autoreconf` in `pwd`: 31 | autoreconf || autoreconf --install 32 | ) || exit 33 | 34 | #conf_flags="--enable-maintainer-mode --enable-compile-warnings" #--enable-iso-c 35 | 36 | if test x$NOCONFIGURE = x; then 37 | echo Running $srcdir/configure $conf_flags "$@" '...' \ 38 | | tr ' ' \\n \ 39 | | sed 's/^-/ &/' 40 | $srcdir/configure $conf_flags "$@" \ 41 | && echo Now type \`make\' to compile $PKG_NAME 42 | else 43 | echo Skipping configure process. 44 | fi 45 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | freebcp.1 2 | html 3 | tsql.1 4 | bsqldb.1 5 | defncopy.1 6 | datacopy.1 7 | osql.1 8 | fisql.1 9 | libtds 10 | reference 11 | userguide.dsl 12 | userguide 13 | put 14 | doc 15 | ctlib.api.sgml 16 | dblib.api.sgml 17 | doxy.log 18 | odbc.api.sgml 19 | bsqlodbc.1 20 | t 21 | ctlib.api.body 22 | dblib.api.body 23 | odbc.api.body 24 | freetds.conf.5 25 | userguide_desc.sgml 26 | -------------------------------------------------------------------------------- /doc/README.releasing: -------------------------------------------------------------------------------- 1 | It's pretty simple, basically: 2 | 3 | 0) Form a branch in git: 4 | 5 | $ git tag branch-0_xx 6 | $ git branch Branch-0_xx 7 | $ git push origin branch-0_xx Branch-0_xx 8 | 9 | Use the form Branch-0_xx, where xx is the release number. 10 | 11 | 1) Change the version number in configure.ac and UG. 12 | 2) Update web pages regarding purpose and status of rc. 13 | 3) Put out a release candidates until everyone's happy. 14 | jkl has a "make dist" script on /etc/nightly.freetds that works well. 15 | 4) ftp tarball to 16 | ftp://login.ibiblio.org/pub/linux/ALPHA/freetds/current 17 | 5) ftp user guide to www.freetds.org/userguide/. 18 | repeat 3-4 as necessary. 19 | 6) Log into ibiblio. Trim rc# from tarball. Update web site. 20 | 7) Create rpm with 'rpmbuild -ta freetds-0.61.tar.gz', post these as well. 21 | 22 | Announcements to: 23 | 24 | freshmeat.net 25 | comp.os.linux.announce 26 | comp.databases.sybase 27 | comp.databases.ms-sqlserver 28 | linuxpr.com 29 | 30 | 31 | We received this bit of advice on the mailing list on 32 | Wed Oct 15 14:51:06 EDT 2003. 33 | 34 | Please, please, *please* follow the common rules of good release 35 | engineering (in descending order of importance - two orders of magnitude 36 | less important per step ;-) 37 | 38 | (A) (Priority 100) A release is STATIC. You NEVER EVER change the 39 | contents of a release after the fact, such as replacing the 40 | freetds-0.61.tgz archive with a DIFFERENT ARCHIVE containing 41 | freetds-0.61.2. This breaks everybody that has a system in place 42 | for using the tarballs - and I know of at least eight public open 43 | source systems that do this, as well as a bunch of proprietary systems. 44 | 45 | (B) (Priority 1) Release engineering needs to include procedures to 46 | make sure that the documentation in the release is up to date. 47 | FreeTDS 0.61.2 refers to itself as FreeTDS 0.61.1. 48 | 49 | (C) (Priority 0.01) It'd be nice if the archive name followed the normal 50 | convention for naming - .tar.gz for tar and gzip, rather than .tgz. 51 | 52 | -- 53 | $Id: 8e21c2ac6a48109d575c92c6fdb022485a894c65 $ 54 | -------------------------------------------------------------------------------- /doc/bcp.txt: -------------------------------------------------------------------------------- 1 | Bulk Copy 2 | --------- 3 | 4 | 5 | 6 | BCP Data Format 7 | 8 | +---------+-----+-----+---------------+----------+-------------+------------+ 9 | | | non | row | | | | size of | 10 | | size | var | num | fixed columns | row size | var columns | adjustment | 11 | | | cols| | | | | table | 12 | +---------+-----+-----+---------------+----------+-------------+------------+ 13 | +---------+------------+ 14 | | end of | offsets | 15 | | data | to varlen | 16 | | pointer | data | 17 | +---------+------------+ 18 | -------------------------------------------------------------------------------- /doc/developer: -------------------------------------------------------------------------------- 1 | So you've got GIT commit access? Basically here is the low down on how we do 2 | things. 3 | 4 | If it's a simple patch and doesn't affect anything outside of that module, 5 | check it in. No post to the list is necessary (appreciated not 6 | necessary), but do make judicious use of commit messages. 7 | 8 | If the change is going to break the libtds API, post your intentions to 9 | the list before hand for discussion. 10 | 11 | Large changes that do not break the interface, can be checked in (if we 12 | are not in feature freeze) but please post a summary to the list of what 13 | you did and why so the other developers know. 14 | 15 | The GIT commit comments should reflect *why* you changed things. i.e. 16 | 17 | "Fixed convert bug in tsql.c" 18 | 19 | -------------------------------------------------------------------------------- /doc/grep_sample_code: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl -w 2 | 3 | # A simple, not very flexible bit of Perl to extract the sample code 4 | # from the User Guide. 5 | 6 | while(<>) { 7 | last if /chapter id="programming"/; 8 | } 9 | 10 | while(<>) { 11 | if (///; 20 | 21 | s/.+$//; 22 | s//g; 26 | 27 | print; 28 | } 29 | 30 | __DATA__ 31 | $Id: grep_sample_code,v 1.1 2007-12-10 05:13:11 jklowden Exp $ 32 | 33 | -------------------------------------------------------------------------------- /doc/htdoc/freetds.css: -------------------------------------------------------------------------------- 1 | /* $Id: freetds.css,v 1.1 2011-04-01 03:37:18 jklowden Exp $ */ 2 | 3 | body {bgcolor = #F9F9F9} 4 | 5 | #Navigation li { 6 | list-style-type: none; 7 | padding: 0.25em; 8 | float: left; 9 | display: inline 10 | } 11 | 12 | hr { clear: left; } 13 | 14 | kbd.input { font-weight: bold; } -------------------------------------------------------------------------------- /doc/htdoc/freetdslogo3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/htdoc/freetdslogo3.gif -------------------------------------------------------------------------------- /doc/images/callouts/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/1.gif -------------------------------------------------------------------------------- /doc/images/callouts/10.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/10.gif -------------------------------------------------------------------------------- /doc/images/callouts/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/2.gif -------------------------------------------------------------------------------- /doc/images/callouts/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/3.gif -------------------------------------------------------------------------------- /doc/images/callouts/4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/4.gif -------------------------------------------------------------------------------- /doc/images/callouts/5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/5.gif -------------------------------------------------------------------------------- /doc/images/callouts/6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/6.gif -------------------------------------------------------------------------------- /doc/images/callouts/7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/7.gif -------------------------------------------------------------------------------- /doc/images/callouts/8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/8.gif -------------------------------------------------------------------------------- /doc/images/callouts/9.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/callouts/9.gif -------------------------------------------------------------------------------- /doc/images/caution.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/caution.gif -------------------------------------------------------------------------------- /doc/images/important.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/important.gif -------------------------------------------------------------------------------- /doc/images/note.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/note.gif -------------------------------------------------------------------------------- /doc/images/tip.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/tip.gif -------------------------------------------------------------------------------- /doc/images/warning.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/doc/images/warning.gif -------------------------------------------------------------------------------- /doc/userguide.css: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: userguide.css,v 1.1 2005-10-03 02:52:29 jklowden Exp $ 3 | */ 4 | 5 | /* Set the screen background to gray */ 6 | .SCREEN { 7 | background-color: #F0F0F0; 8 | } 9 | 10 | /* Render user input as boldface */ 11 | .USERINPUT { 12 | font-weight: bold; 13 | } 14 | 15 | /* Make filenames green (why not?) */ 16 | .FILENAME { 17 | color: #007a00; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /freetds.conf: -------------------------------------------------------------------------------- 1 | # $Id: freetds.conf,v 1.12 2007-12-25 06:02:36 jklowden Exp $ 2 | # 3 | # This file is installed by FreeTDS if no file by the same 4 | # name is found in the installation directory. 5 | # 6 | # For information about the layout of this file and its settings, 7 | # see the freetds.conf manpage "man freetds.conf". 8 | 9 | # Global settings are overridden by those in a database 10 | # server specific section 11 | [global] 12 | # TDS protocol version 13 | tds version = auto 14 | 15 | # Whether to write a TDSDUMP file for diagnostic purposes 16 | # (setting this to /tmp is insecure on a multi-user system) 17 | ; dump file = /tmp/freetds.log 18 | ; debug flags = 0xffff 19 | 20 | # Command and connection timeouts 21 | ; timeout = 10 22 | ; connect timeout = 10 23 | 24 | # If you get out-of-memory errors, it may mean that your client 25 | # is trying to allocate a huge buffer for a TEXT field. 26 | # Try setting 'text size' to a more reasonable limit 27 | text size = 64512 28 | 29 | # A typical Sybase server 30 | [egServer50] 31 | host = symachine.domain.com 32 | port = 5000 33 | tds version = 5.0 34 | 35 | # A typical Microsoft server 36 | [egServer70] 37 | host = ntmachine.domain.com 38 | port = 1433 39 | tds version = 7.0 40 | -------------------------------------------------------------------------------- /include/.gitignore: -------------------------------------------------------------------------------- 1 | config.h 2 | stamp-h.in 3 | config.h.in 4 | stamp-h 5 | stamp-h1 6 | tds_sysdep_public.h 7 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = 1.5.3 2 | 3 | SUBDIRS = freetds 4 | 5 | include_HEADERS = bkpublic.h \ 6 | cspublic.h cstypes.h ctpublic.h \ 7 | sqldb.h sqlfront.h \ 8 | sybdb.h sybfront.h \ 9 | syberror.h odbcss.h 10 | 11 | nodist_include_HEADERS = tds_sysdep_public.h 12 | 13 | noinst_HEADERS = ctlib.h \ 14 | dblib.h \ 15 | md4.h md5.h des.h hmac_md5.h \ 16 | replacements.h \ 17 | replacements/poll.h \ 18 | replacements/readpassphrase.h 19 | 20 | DISTCLEANFILES = tds_sysdep_public.h 21 | 22 | -------------------------------------------------------------------------------- /include/des.h: -------------------------------------------------------------------------------- 1 | #ifndef DES_H 2 | #define DES_H 3 | 4 | #ifdef HAVE_NETTLE 5 | #include 6 | 7 | typedef struct des_ctx DES_KEY; 8 | #endif 9 | 10 | #include 11 | 12 | typedef unsigned char des_cblock[8]; 13 | 14 | #ifndef HAVE_NETTLE 15 | typedef struct des_key 16 | { 17 | unsigned char kn[16][8]; 18 | TDS_UINT sp[8][64]; 19 | unsigned char iperm[16][16][8]; 20 | unsigned char fperm[16][16][8]; 21 | } DES_KEY; 22 | 23 | int tds_des_set_key(DES_KEY * dkey, const des_cblock user_key, int len); 24 | void tds_des_encrypt(DES_KEY * key, des_cblock block); 25 | #endif 26 | 27 | void tds_des_set_odd_parity(des_cblock key); 28 | int tds_des_ecb_encrypt(const void *plaintext, int len, DES_KEY * akey, des_cblock output); 29 | 30 | #include 31 | 32 | #ifdef HAVE_NETTLE 33 | static inline void tds_des_encrypt(DES_KEY * key, des_cblock block) 34 | { 35 | nettle_des_encrypt(key, sizeof(des_cblock), block, block); 36 | } 37 | 38 | static inline int tds_des_set_key(DES_KEY * dkey, const des_cblock user_key, int len) 39 | { 40 | return nettle_des_set_key(dkey, user_key); 41 | } 42 | #endif 43 | 44 | #endif /* !DES_H */ 45 | -------------------------------------------------------------------------------- /include/freetds/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_HEADERS = iconv.h string.h convert.h bytes.h \ 3 | thread.h proto.h tds.h odbc.h version.h server.h \ 4 | configs.h enum_cap.h sysdep_private.h stream.h \ 5 | data.h pushvis.h popvis.h time.h tls.h bool.h \ 6 | checks.h dlist.h dlist.tmpl.h 7 | 8 | DISTCLEANFILES = sysconfdir.h 9 | 10 | sysconfdir.h: Makefile 11 | echo '#define FREETDS_SYSCONFDIR "$(sysconfdir)"' >$@ 12 | 13 | all-am: sysconfdir.h 14 | -------------------------------------------------------------------------------- /include/freetds/bool.h: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 2015 Frediano Ziglio 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef freetds_bool_h_ 21 | #define freetds_bool_h_ 22 | 23 | #ifndef __cplusplus 24 | 25 | #ifdef HAVE_STDBOOL_H 26 | 27 | #include 28 | 29 | #else 30 | 31 | #undef true 32 | #undef false 33 | #undef bool 34 | #define bool int 35 | #define true 1 36 | #define false 0 37 | 38 | #endif 39 | 40 | #endif 41 | 42 | #endif /* freetds_bool_h_ */ 43 | -------------------------------------------------------------------------------- /include/freetds/configs.h: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998-1999 Brian Bruns 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _tds_configs_h_ 21 | #define _tds_configs_h_ 22 | 23 | /* $Id: tds_configs.h,v 1.21 2005-07-08 08:22:53 freddy77 Exp $ */ 24 | 25 | #include 26 | 27 | #ifndef _tds_h_ 28 | #error tds.h must be included before tds_configs.h 29 | #endif 30 | 31 | #ifdef __cplusplus 32 | extern "C" 33 | { 34 | #if 0 35 | } 36 | #endif 37 | #endif 38 | 39 | #define FREETDS_SYSCONFFILE FREETDS_SYSCONFDIR TDS_SDIR_SEPARATOR "freetds.conf" 40 | #define FREETDS_POOLCONFFILE FREETDS_SYSCONFDIR TDS_SDIR_SEPARATOR "pool.conf" 41 | #define FREETDS_LOCALECONFFILE FREETDS_SYSCONFDIR TDS_SDIR_SEPARATOR "locales.conf" 42 | 43 | #ifdef __cplusplus 44 | #if 0 45 | { 46 | #endif 47 | } 48 | #endif 49 | 50 | #endif /* _tds_configs_h_ */ 51 | -------------------------------------------------------------------------------- /include/freetds/dlist.h: -------------------------------------------------------------------------------- 1 | /* Dlist - dynamic list 2 | * Copyright (C) 2016 Frediano Ziglio 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | */ 19 | 20 | #ifndef TDS_DLIST_H 21 | #define TDS_DLIST_H 22 | 23 | typedef struct dlist_ring { 24 | struct dlist_ring *next; 25 | struct dlist_ring *prev; 26 | } dlist_ring; 27 | 28 | #if ENABLE_EXTRA_CHECKS 29 | void dlist_ring_check(dlist_ring *ring); 30 | #endif 31 | 32 | #define DLIST_FIELDS(name) \ 33 | dlist_ring name 34 | 35 | #define DLIST_FOREACH(prefix, list, p) \ 36 | for (p = prefix ## _ ## first(list); p != NULL; p = prefix ## _ ## next(list, p)) 37 | 38 | #endif /* TDS_DLIST_H */ 39 | -------------------------------------------------------------------------------- /include/freetds/popvis.h: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__) 2 | #pragma GCC visibility pop 3 | #endif 4 | -------------------------------------------------------------------------------- /include/freetds/pushvis.h: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__) 2 | #pragma GCC visibility push(hidden) 3 | #endif 4 | -------------------------------------------------------------------------------- /include/freetds/time.h: -------------------------------------------------------------------------------- 1 | #if TIME_WITH_SYS_TIME 2 | # include 3 | # include 4 | #else 5 | # if HAVE_SYS_TIME_H 6 | # include 7 | # else 8 | # include 9 | # endif 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /include/freetds/version.h.in: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998-1999 Brian Bruns 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _tdsversion_h_ 21 | #define _tdsversion_h_ 22 | 23 | /* $Id: 9640daf619734147e3b5ff6a1dad56ad305ffa51 $ */ 24 | 25 | #define TDS_VERSION_NO "@PACKAGE@ v@VERSION@" 26 | 27 | #define TDS_VERSION_MAJOR @MAJOR@ 28 | #define TDS_VERSION_MINOR @MINOR@ 29 | #define TDS_VERSION_SUBVERSION @SUBVERSION@ 30 | #define TDS_VERSION_BUILD_NUMBER @BUILD_NUMBER@ 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/hmac_md5.h: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 2008 Frediano Ziglio 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _hmac_md5_h_ 21 | #define _hmac_md5_h_ 22 | 23 | #include 24 | void hmac_md5(const unsigned char key[16], 25 | const unsigned char* data, size_t data_len, 26 | unsigned char* digest); 27 | #include 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/md4.h: -------------------------------------------------------------------------------- 1 | #ifndef MD4_H 2 | #define MD4_H 3 | 4 | #ifndef HAVE_NETTLE 5 | 6 | #include 7 | 8 | struct MD4Context 9 | { 10 | TDS_UINT buf[4]; 11 | TDS_UINT8 bytes; 12 | unsigned char in[64]; 13 | }; 14 | 15 | void MD4Init(struct MD4Context *context); 16 | void MD4Update(struct MD4Context *context, unsigned char const *buf, size_t len); 17 | void MD4Final(struct MD4Context *context, unsigned char *digest); 18 | 19 | typedef struct MD4Context MD4_CTX; 20 | 21 | #include 22 | 23 | #else 24 | 25 | #include 26 | 27 | typedef struct md4_ctx MD4_CTX; 28 | 29 | static inline void MD4Init(MD4_CTX *ctx) 30 | { 31 | nettle_md4_init(ctx); 32 | } 33 | 34 | static inline void MD4Update(MD4_CTX *ctx, unsigned char const *buf, size_t len) 35 | { 36 | nettle_md4_update(ctx, len, buf); 37 | } 38 | 39 | static inline void MD4Final(MD4_CTX *ctx, unsigned char *digest) 40 | { 41 | nettle_md4_digest(ctx, 16, digest); 42 | } 43 | 44 | 45 | #endif 46 | 47 | #endif /* !MD4_H */ 48 | -------------------------------------------------------------------------------- /include/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5_H 2 | #define MD5_H 3 | 4 | #ifndef HAVE_NETTLE 5 | 6 | #include 7 | 8 | struct MD5Context { 9 | TDS_UINT buf[4]; 10 | TDS_UINT8 bytes; 11 | unsigned char in[64]; 12 | }; 13 | 14 | void MD5Init(struct MD5Context *context); 15 | void MD5Update(struct MD5Context *context, unsigned char const *buf, size_t len); 16 | void MD5Final(struct MD5Context *context, unsigned char *digest); 17 | 18 | /* 19 | * This is needed to make RSAREF happy on some MS-DOS compilers. 20 | */ 21 | typedef struct MD5Context MD5_CTX; 22 | 23 | #include 24 | 25 | #else 26 | 27 | #include 28 | 29 | typedef struct md5_ctx MD5_CTX; 30 | 31 | static inline void MD5Init(MD5_CTX *ctx) 32 | { 33 | nettle_md5_init(ctx); 34 | } 35 | 36 | static inline void MD5Update(MD5_CTX *ctx, unsigned char const *buf, size_t len) 37 | { 38 | nettle_md5_update(ctx, len, buf); 39 | } 40 | 41 | static inline void MD5Final(MD5_CTX *ctx, unsigned char *digest) 42 | { 43 | nettle_md5_digest(ctx, 16, digest); 44 | } 45 | 46 | #endif 47 | 48 | #endif /* !MD5_H */ 49 | -------------------------------------------------------------------------------- /include/syberror.h: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998-1999 Brian Bruns 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _syberror_h_ 21 | #define _syberror_h_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #if 0 27 | } 28 | #endif 29 | #endif 30 | 31 | static const char rcsid_syberror_h[] = "$Id: syberror.h,v 1.4 2004-10-28 12:42:12 freddy77 Exp $"; 32 | static const void *const no_unused_syberror_h_warn[] = { rcsid_syberror_h, no_unused_syberror_h_warn }; 33 | 34 | /* severity levels, gleaned from google */ 35 | #define EXINFO 1 36 | #define EXUSER 2 37 | #define EXNONFATAL 3 38 | #define EXCONVERSION 4 39 | #define EXSERVER 5 40 | #define EXTIME 6 41 | #define EXPROGRAM 7 42 | #define EXRESOURCE 8 43 | #define EXCOMM 9 44 | #define EXFATAL 10 45 | #define EXCONSISTENCY 11 46 | 47 | #ifdef __cplusplus 48 | #if 0 49 | { 50 | #endif 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/sybfront.h: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998-1999 Brian Bruns 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef SYBFRONT_h 21 | #define SYBFRONT_h 22 | 23 | #include "sybdb.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #if 0 29 | } 30 | #endif 31 | #endif 32 | 33 | static const char rcsid_sybfront_h[] = "$Id: sybfront.h,v 1.3 2004-10-28 12:42:12 freddy77 Exp $"; 34 | static const void *const no_unused_sybfront_h_warn[] = { rcsid_sybfront_h, no_unused_sybfront_h_warn }; 35 | 36 | 37 | 38 | #ifdef __cplusplus 39 | #if 0 40 | { 41 | #endif 42 | } 43 | #endif 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /locales.conf: -------------------------------------------------------------------------------- 1 | [default] 2 | date format = %b %e %Y %I:%M:%S:%z%p 3 | 4 | [en_US] 5 | date format = %b %e %Y %I:%M:%S:%z%p 6 | language = us_english 7 | charset = iso_1 8 | 9 | [es_ES] 10 | date format = %b %d %Y %I:%M%p 11 | language = spanish 12 | charset = iso_1 13 | 14 | [pt_BR] 15 | date format = %d/%m/%Y %H:%M 16 | language = Portuguese 17 | charset = iso_1 18 | 19 | [it_IT] 20 | date format = %d/%m/%Y %H:%M 21 | language = Italiano 22 | charset = iso_1 23 | 24 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | libtool.m4 2 | ltoptions.m4 3 | ltsugar.m4 4 | ltversion.m4 5 | lt~obsolete.m4 6 | -------------------------------------------------------------------------------- /m4/ac_have_inaddr_none.m4: -------------------------------------------------------------------------------- 1 | dnl $Id: ac_have_inaddr_none.m4,v 1.3 2006-03-29 16:24:37 freddy77 Exp $ 2 | AC_DEFUN([AC_HAVE_INADDR_NONE], [ 3 | AC_CACHE_CHECK([whether INADDR_NONE is defined], 4 | ac_cv_have_inaddr_none, 5 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 6 | [/* our includes */ 7 | #ifdef HAVE_SYS_TYPES_H 8 | #include 9 | #endif 10 | #ifdef HAVE_SYS_SOCKET_H 11 | #include 12 | #endif 13 | #ifdef HAVE_NETINET_IN_H 14 | #include 15 | #endif 16 | #ifdef HAVE_ARPA_INET_H 17 | #include 18 | #endif 19 | /* end includes */], 20 | [unsigned long foo = INADDR_NONE; /* our test code */])], 21 | ac_cv_have_inaddr_none=yes, 22 | ac_cv_have_inaddr_none=no) 23 | 24 | ]) 25 | if test $ac_cv_have_inaddr_none != yes; then 26 | AC_DEFINE(INADDR_NONE, 0xffffffff, 27 | [Define to value of INADDR_NONE if not provided by your system header files.]) 28 | fi 29 | ] 30 | ) 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /m4/ac_have_malloc_options.m4: -------------------------------------------------------------------------------- 1 | dnl $Id: ac_have_malloc_options.m4,v 1.3 2006-03-29 16:24:37 freddy77 Exp $ 2 | AC_DEFUN([AC_HAVE_MALLOC_OPTIONS], 3 | [AC_CACHE_CHECK([whether malloc_options variable is present], 4 | ac_cv_have_malloc_options, 5 | [AC_LINK_IFELSE([AC_LANG_PROGRAM([ 6 | #include 7 | ],[ 8 | extern char *malloc_options; 9 | malloc_options = "AJR"; 10 | ])], 11 | ac_cv_have_malloc_options=yes, 12 | ac_cv_have_malloc_options=no)]) 13 | if test $ac_cv_have_malloc_options = yes; then 14 | AC_DEFINE(HAVE_MALLOC_OPTIONS, 1, [Define to 1 if your system provides the malloc_options variable.]) 15 | fi]) 16 | 17 | -------------------------------------------------------------------------------- /m4/ac_nullzero.m4: -------------------------------------------------------------------------------- 1 | # TDS_NULL_IS_ZERO ([ACTION-IF-TRUE], [ACTION-IF-FALSE]) 2 | # ------------------------------------------------------------------------- 3 | AC_DEFUN([TDS_NULL_IS_ZERO], 4 | [AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tds_cv_null_is_zero, 5 | [ 6 | tds_cv_null_is_zero=no 7 | # compile a test program. 8 | AC_RUN_IFELSE( 9 | [AC_LANG_SOURCE([[#include 10 | #include 11 | #include 12 | #ifdef HAVE_STDDEF_H 13 | #include 14 | #endif 15 | int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2)); 16 | return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])], 17 | [tds_cv_null_is_zero=yes], 18 | [], 19 | [# try to guess the endianness by grepping values into an object file 20 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 21 | [[#include 22 | struct test { char begin[16]; void *ptrs[4]; char end[16]; } xxx[] = { 23 | { "abcdefghijklmnop", { NULL, NULL, NULL, NULL }, "qrstuvwxyzabcdef" }, 24 | { "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96\x97", { NULL, NULL, NULL, NULL }, "\x98\x99\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\x81\x82\x83\x84\x85\x86" } 25 | };]], 26 | [[]])], 27 | [if cat -v conftest.$ac_objext|grep 'abcdefghijklmnop\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\(\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\)*qrstuvwxyzabcdef'>/dev/null ; then 28 | tds_cv_null_is_zero=yes 29 | fi])])]) 30 | case $tds_cv_null_is_zero in 31 | yes) 32 | m4_default([$1], 33 | [AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1, 34 | [Define to 1 if memset(0) sets pointers to NULL.])]) 35 | ;; 36 | no) 37 | $2 38 | ;; 39 | esac 40 | ])# TDS_NULL_IS_ZERO 41 | 42 | -------------------------------------------------------------------------------- /m4/ac_tds_func_which_localtime_r.m4: -------------------------------------------------------------------------------- 1 | dnl $Id: ac_tds_func_which_localtime_r.m4,v 1.3 2006-03-29 16:24:37 freddy77 Exp $ 2 | AC_DEFUN([AC_tds_FUNC_WHICH_LOCALTIME_R], 3 | [AC_CACHE_CHECK(for which type of localtime_r, ac_cv_func_which_localtime_r, [ 4 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ 5 | #include 6 | #include 7 | ], [ 8 | struct tm mytm; 9 | time_t t; 10 | int y = localtime_r(&t, &mytm)->tm_year; 11 | ])],ac_cv_func_which_localtime_r=struct, 12 | ac_cv_func_which_localtime_r=int) 13 | ]) 14 | 15 | if test $ac_cv_func_which_localtime_r = struct; then 16 | AC_DEFINE(HAVE_FUNC_LOCALTIME_R_TM, 1, [Define to 1 if your localtime_r return a struct tm*.]) 17 | else 18 | AC_DEFINE(HAVE_FUNC_LOCALTIME_R_INT, 1, [Define to 1 if your localtime_r return a int.]) 19 | fi 20 | ]) 21 | 22 | -------------------------------------------------------------------------------- /m4/check_openssl.m4: -------------------------------------------------------------------------------- 1 | dnl $Id: check_openssl.m4,v 1.2 2006-03-27 07:22:54 jklowden Exp $ 2 | # OpenSSL check 3 | 4 | AC_DEFUN([CHECK_OPENSSL], 5 | [AC_MSG_CHECKING(if openssl is wanted) 6 | AC_ARG_WITH(openssl, AS_HELP_STRING([--with-openssl], [--with-openssl=DIR build with OpenSSL (license NOT compatible cf. User Guide)])) 7 | if test "$with_openssl" != "no"; then 8 | AC_MSG_RESULT(yes) 9 | found_ssl=no 10 | for dir in $withval /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr; do 11 | ssldir="$dir" 12 | if test -f "$dir/include/openssl/ssl.h"; then 13 | found_ssl="yes" 14 | CFLAGS="$CFLAGS -I$ssldir/include" 15 | break 16 | fi 17 | done 18 | if test x$found_ssl != xyes; then 19 | AC_MSG_ERROR(Cannot find OpenSSL libraries) 20 | else 21 | echo "OpenSSL found in $ssldir" 22 | NETWORK_LIBS="$NETWORK_LIBS -lssl -lcrypto" 23 | LDFLAGS="$LDFLAGS -L$ssldir/lib" 24 | HAVE_OPENSSL=yes 25 | AC_DEFINE(HAVE_OPENSSL, 1, [Define if you have the OpenSSL.]) 26 | fi 27 | AC_SUBST(HAVE_OPENSSL) 28 | else 29 | AC_MSG_RESULT(no) 30 | fi 31 | ]) 32 | -------------------------------------------------------------------------------- /m4/pushlibs.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([ACX_PUSH_LIBS], 2 | [m4_pushdef([SAVELIBS],[LIBS_]__line__)dnl 3 | SAVELIBS="$LIBS" 4 | LIBS=[$1]]) 5 | 6 | AC_DEFUN([ACX_POP_LIBS], 7 | [LIBS="$SAVELIBS" 8 | unset SAVELIBS dnl 9 | m4_popdef([SAVELIBS])dnl 10 | ]) 11 | 12 | -------------------------------------------------------------------------------- /m4/type_socklen_t.m4: -------------------------------------------------------------------------------- 1 | dnl $Id: type_socklen_t.m4,v 1.3 2006-03-29 16:24:37 freddy77 Exp $ 2 | ## 3 | # This macro came from internet, appear in lftp, rsync and others. 4 | ## 5 | AC_DEFUN([TYPE_SOCKLEN_T], 6 | [ 7 | AC_CHECK_TYPE([socklen_t], ,[ 8 | AC_MSG_CHECKING([for socklen_t equivalent]) 9 | AC_CACHE_VAL([xml_cv_socklen_t_equiv], 10 | [ 11 | # Systems have either "struct sockaddr *" or 12 | # "void *" as the second argument to getpeername 13 | xml_cv_socklen_t_equiv= 14 | for arg2 in "struct sockaddr" void; do 15 | for t in int size_t unsigned long "unsigned long"; do 16 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ 17 | #ifdef HAVE_SYS_TYPES_H 18 | # include 19 | #endif 20 | #ifdef HAVE_WINSOCK2_H 21 | # include 22 | # include 23 | int PASCAL getpeername (SOCKET, $arg2 *, $t *); 24 | #elif defined(HAVE_SYS_SOCKET_H) 25 | # include 26 | int getpeername (int, $arg2 *, $t *); 27 | #endif 28 | 29 | ],[ 30 | $t len; 31 | getpeername(0,0,&len); 32 | ])],[ 33 | xml_cv_socklen_t_equiv="$t" 34 | break 35 | ]) 36 | done 37 | done 38 | 39 | if test "x$xml_cv_socklen_t_equiv" = x; then 40 | AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) 41 | fi 42 | ]) 43 | AC_MSG_RESULT($xml_cv_socklen_t_equiv) 44 | AC_DEFINE_UNQUOTED(socklen_t, $xml_cv_socklen_t_equiv, 45 | [type to use in place of socklen_t if not defined])], 46 | [#include 47 | #ifdef HAVE_SYS_SOCKET_H 48 | # include 49 | #endif 50 | #ifdef HAVE_WINSOCK2_H 51 | # include 52 | # include 53 | #endif]) 54 | ]) 55 | 56 | -------------------------------------------------------------------------------- /misc/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = cmake_checks.c 2 | -------------------------------------------------------------------------------- /misc/cmake_checks.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | #if defined(CHECK_ASPRINTF) 8 | char *p = NULL; int len = asprintf(&p, "%d", 123)"); 9 | #elif defined(CHECK_VASPRINTF) 10 | va_list va; char *p = NULL; int len = vasprintf(&p, "%d", va); 11 | #elif defined(CHECK_SNPRINTF) 12 | char buf[128]; int len = snprintf(buf, 128, "%d", 123); 13 | #elif defined(CHECK__SNPRINTF) 14 | char buf[128]; int len = _snprintf(buf, 128, "%d", 123); 15 | #elif defined(CHECK_VSNPRINTF) 16 | va_list va; char buf[128]; int len = vsnprintf(buf, 128, "%d", va); 17 | #elif defined(CHECK__VSNPRINTF) 18 | va_list va; char buf[128]; int len = _vsnprintf(buf, 128, "%d", va); 19 | #elif defined(CHECK__VSCPRINTF) 20 | va_list va; int len = _vscprintf("%d", va); 21 | #else 22 | #error "Check function not specified correctly" 23 | #endif 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /misc/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # build coverage output 4 | # require lcov installed 5 | 6 | set -e 7 | set -o pipefail 8 | 9 | trap 'echo Error at line $LINENO' ERR 10 | 11 | STARTDIR="$(pwd -P)" 12 | 13 | # first parameter are gcov prefix 14 | COV= 15 | if [ "$1" != "" ]; then 16 | cd "$1" 17 | COV="$(pwd -P)" 18 | cd - > /dev/null 19 | fi 20 | 21 | # second is file output for info files, instead of coverage directory 22 | OUT="$2" 23 | 24 | # go to main distro dir 25 | DIR=`dirname $0` 26 | cd "$DIR/.." 27 | DIR="$(pwd -P)" 28 | cd - > /dev/null 29 | 30 | if [ "$COV" = "" ]; then 31 | COV="$DIR" 32 | fi 33 | 34 | # cleanup 35 | cd "$COV" 36 | rm -rf covtmp coverage 37 | mkdir covtmp 38 | mkdir coverage 39 | 40 | # move required files in covtmp 41 | SRC="$(find "$COV$HOME" -name src -type d)" || true 42 | if [ -d "$SRC" ]; then 43 | cd "$SRC/.." 44 | mkdir -p include 45 | find include/ src/ \( -name \*.\[ch\] -o -name \*.gc\* \) | tar cf - -T - | (cd $COV/covtmp && exec tar xf -) 46 | cd "$DIR" 47 | find include/ src/ \( -name \*.\[ch\] -o -name \*.gcno \) | tar cf - -T - | (cd $COV/covtmp && exec tar xf -) 48 | else 49 | cd "$DIR" 50 | find include/ src/ \( -name \*.\[ch\] -o -name \*.gc\* \) | tar cf - -T - | (cd $COV/covtmp && exec tar xf -) 51 | fi 52 | 53 | # generate coverage 54 | cd $COV/covtmp 55 | geninfo . -o out0.info -t 'Test' 56 | perl -ne '$skip = 1 if (m(^SF:/usr/include/)); print if(!$skip); $skip = 0 if (/^end_of_record$/);' < out0.info > out1.info 57 | perl -pe "s,^SF:$COV/covtmp/,SF:/home/user/freetds/," < out1.info > out.info 58 | if [ "$OUT" != "" ]; then 59 | cd "$STARTDIR" 60 | cp $COV/covtmp/out.info "$OUT" 61 | else 62 | # save temporary directory 63 | cd .. 64 | tar zcvf $HOME/coverage-$(date +%Y%m%d%H%M).tgz covtmp 65 | cd covtmp 66 | 67 | genhtml out.info -t 'FreeTDS coverage' -o ../coverage -p "$COV/covtmp" 68 | fi 69 | 70 | echo Success !! 71 | -------------------------------------------------------------------------------- /misc/fixdoxyres: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -n 2 | 3 | BEGIN { chomp($pwd = `pwd`) } 4 | s,$pwd/?,,; 5 | push @all, $_; 6 | 7 | END { 8 | $all = join('', @all); 9 | @all = split(/^(?=\S)/m, $all); 10 | @prev = grep { ! m,^[a-z0-9_./]+:\d+:,s } @all; 11 | @all = map { $_ =~ s/([^:]+):(\d+):/sprintf('%s:%08d:', $1, $2)/e; $_ } grep { m,^[a-z0-9_./]+:\d+:,s } @all; 12 | $_ = join('', @prev, map { $_ =~ s/([^:]+):(\d+):/sprintf('%s:%d:', $1, $2)/e; $_ } sort @all); 13 | 14 | # output html 15 | print ' 16 | 17 | 18 | Doxygen errors and warnings 19 | 20 |
';
21 | 	s,&,&,; s,<,<,g; s,>,>,; s,",",g;
22 | 	print;
23 | 	print '
'; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /misc/full-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # run a test watching for errors and logging all 4 | 5 | log () { 6 | echo "@!@!@!@!@!@!@!@!@!@!@!@!@!@!@!@- $1 -@!@!@!@!@!@!@!@!@!@!@!@!@!@!@!@" 7 | } 8 | 9 | cd "`dirname $0`/.." 10 | DIR="`pwd -P`" 11 | cd - > /dev/null 12 | 13 | FILE=`echo "$1" | sed "s,^\\./,$PWD/,"` 14 | 15 | # execute with valgrind 16 | RES=1 17 | if test -f "$HOME/bin/vg_test"; then 18 | log "START $1" 19 | log "TEST 1" 20 | log "VALGRIND 1" 21 | "$DIR/misc/grabcov" -o "$FILE.cov_info" -- classifier --timeout=600 --num-fd=3 "$HOME/bin/vg_test" "$@" 22 | RES=$? 23 | log "RESULT $RES" 24 | log "FILE $FILE" 25 | log "END $1" 26 | fi 27 | 28 | # try to execute normally 29 | if test $RES != 0 -a $RES != 77; then 30 | log "START $1" 31 | log "TEST 1" 32 | "$DIR/misc/grabcov" -o "$FILE.cov_info" -- classifier --timeout=600 "$@" 33 | RES=$? 34 | log "RESULT $RES" 35 | 36 | # log test executed to retrieve lately by main script 37 | log "FILE $FILE" 38 | log "END $1" 39 | fi 40 | 41 | # return always success, test verified later 42 | exit 0 43 | 44 | -------------------------------------------------------------------------------- /misc/grabcov: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | error() { 4 | echo "$@" >&2 5 | exit 1 6 | } 7 | 8 | handle_exit() { 9 | set +e 10 | rm -rf "$GCOV_PREFIX" 11 | } 12 | 13 | set -e 14 | 15 | unset out res dir arg 16 | 17 | cd "`dirname $0`/.." 18 | dir="`pwd -P`" 19 | cd - > /dev/null 20 | 21 | # parse arguments 22 | out= 23 | while test $# -gt 0; do 24 | arg="$1" 25 | case "$arg" in 26 | -o) 27 | shift 28 | out="$1" 29 | ;; 30 | --) 31 | shift 32 | break 33 | ;; 34 | -*) 35 | error "Invalid option $arg" 36 | ;; 37 | *) 38 | break 39 | ;; 40 | esac 41 | shift 42 | done 43 | 44 | test "$1" != "" || error "You must specify a command" 45 | test "$out" != "" || error "Output file not specified" 46 | 47 | export GCOV_PREFIX="$dir/cov_dir.$$" 48 | mkdir $GCOV_PREFIX 49 | trap handle_exit EXIT 50 | set +e 51 | "$@" 52 | res=$? 53 | 54 | if test -d "$GCOV_PREFIX"; then 55 | if $dir/misc/coverage.sh "$GCOV_PREFIX" "$out" > /dev/null 2>&1 ; then 56 | gzip -9 "$out" 2> /dev/null 57 | else 58 | rm -f "$out" 59 | fi 60 | fi 61 | 62 | exit $res 63 | -------------------------------------------------------------------------------- /misc/sql-server-activate-tcp-fixed-port.ps1: -------------------------------------------------------------------------------- 1 | # Configure SQL server so it accepts TCP connections. 2 | # 3 | # This Windows PowerShell script is used on the Appveyor hosted CI plaform when 4 | # running the FreeTDS test suite but could be useful to automate the task in 5 | # other scenarios. 6 | # 7 | # See 8 | # http://www.appveyor.com/docs/services-databases#enabling-tcp-ip-named-pipes-and-setting-instance-alias 9 | # https://gist.githubusercontent.com/FeodorFitsner/d971c5a98782d211640d/raw/sql-server-ip-and-alias.ps1 10 | # http://geekswithblogs.net/TedStatham/archive/2014/06/13/setting-the-ports-for-a-named-sql-server-instance-using.aspx 11 | 12 | [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null 13 | [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null 14 | 15 | $serverName = $env:COMPUTERNAME 16 | $instanceName = $env:INSTANCENAME 17 | $smo = 'Microsoft.SqlServer.Management.Smo.' 18 | $wmi = new-object ($smo + 'Wmi.ManagedComputer') 19 | 20 | # Enable TCP/IP 21 | $uri = "ManagedComputer[@Name='$serverName']/ServerInstance[@Name='$instanceName']/ServerProtocol[@Name='Tcp']" 22 | $Tcp = $wmi.GetSmoObject($uri) 23 | $Tcp.IsEnabled = $true 24 | foreach ($ipAddress in $Tcp.IPAddresses) 25 | { 26 | $ipAddress.IPAddressProperties["TcpDynamicPorts"].Value = "" 27 | $ipAddress.IPAddressProperties["TcpPort"].Value = "1433" 28 | } 29 | $Tcp.alter() 30 | 31 | # Service needs to be restarted 32 | # Restart service 33 | Restart-Service "MSSQL`$$instanceName" 34 | -------------------------------------------------------------------------------- /misc/sybase_tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # $Id: sybase_tests,v 1.6 2010-07-27 07:19:18 freddy77 Exp $ 4 | # these commands build dblib and ctlib tests using Sybase libraries 5 | 6 | errore() { 7 | echo $* >&2 8 | exit 1 9 | } 10 | 11 | test -x configure || errore "configure not found, go to main directory" 12 | test -d "$SYBASE" || errore "SYBASE environment not defined" 13 | MAINDIR="`pwd`" 14 | cd "$SYBASE" 15 | OCSDIR=`echo OCS-*` 16 | cd "$MAINDIR" 17 | test -d "$SYBASE/$OCSDIR" || errore "OCS directory not found" 18 | 19 | if test "$LD_RUN_PATH" != ""; then 20 | export LD_RUN_PATH="$SYBASE/$OCSDIR/lib:$LD_RUN_PATH" 21 | else 22 | export LD_RUN_PATH="$SYBASE/$OCSDIR/lib" 23 | fi 24 | 25 | # build 26 | trap 'echo Error at line $LINENO' ERR 27 | set -e 28 | make 29 | 30 | # rebuild tests 31 | for dir in src/dblib/unittests src/ctlib/unittests; do 32 | cd $dir 33 | export LD_RUN_PATH="$SYBASE/$OCSDIR/lib" 34 | if test ! -r Makefile.no_sybase -o Makefile -nt Makefile.no_sybase; then 35 | rm -f Makefile.no_sybase 36 | echo '#include ' > sqlfront.h 37 | echo '#include ' > sqldb.h 38 | perl -pi.no_sybase -e "\$_ =~ s{ -I\\\$\\(top_(build|src)dir\\)/include}{ -I$SYBASE/$OCSDIR/include -I\\\$(top_builddir)/include} if (/^(DEFAULT_INCLUDES|AM_CPPFLAGS)\s*=/); 39 | \$_ =~ s{../libsybdb.la}{-lsybdb -lsybunic} if (/^LIBS\s*=/); 40 | \$_ =~ s{../libct.la}{-lsybct -lsybcs -lsybblk} if (/^LIBS\s*=/); 41 | \$_ =~ s{-L../.libs -R \\\$\\(abs_builddir\\)/../.libs}{-L$SYBASE/$OCSDIR/lib} if (/^AM_LDFLAGS\s*=/); 42 | " Makefile 43 | touch Makefile.no_sybase 44 | rm -f *.o *.exe 45 | make clean 46 | fi 47 | make clean 48 | TESTS_ENVIRONMENT="$MAINDIR/misc/tds-makeenvs" make check 49 | cd ../../.. 50 | done 51 | 52 | -------------------------------------------------------------------------------- /misc/tds-makeenvs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # this script helps to compile tests without running them 3 | 4 | # allow to specify which command to prepend to tests 5 | if test "$TDS_MAKEENVS_CMD" = ""; then 6 | TDS_MAKEENVS_CMD=true 7 | fi 8 | 9 | # old style autoconf, just override TESTS_ENVIRONMENT with true to avoid 10 | # doing tests but just compile 11 | if test "$1" != "/bin/sh" -a "$1" != "/bin/bash"; then 12 | $TDS_MAKEENVS_CMD "$@" 13 | exit $? 14 | fi 15 | 16 | # new style, there is a test driver between 17 | # put the "true" comand in the right position (after "--") 18 | # old shells does not support additional arrays so use arguments one 19 | # basically we construct the new array at the end of original one 20 | for arg 21 | do 22 | case "$arg" in 23 | --) 24 | set a "$@" "$arg" $TDS_MAKEENVS_CMD 25 | ;; 26 | *) 27 | set a "$@" "$arg" 28 | ;; 29 | esac 30 | # remove "a" 31 | shift 32 | # remove original argument, so at the end all original 33 | # arguments are removed 34 | shift 35 | done 36 | 37 | exec "$@" 38 | -------------------------------------------------------------------------------- /misc/unzipsfx.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/misc/unzipsfx.exe -------------------------------------------------------------------------------- /misc/write_PWD_from_env_vars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cat <<__EOF__ > PWD 4 | UID=${TDSPWDUID} 5 | PWD=${TDSPWDPWD} 6 | SRV=${TDSPWDSRV} 7 | DB=${TDSPWDDB} 8 | __EOF__ 9 | -------------------------------------------------------------------------------- /misc/zip.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/misc/zip.exe -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Public domain 6 | 7 | # $Id: mkinstalldirs,v 1.1 2001-10-12 23:28:53 brianb Exp $ 8 | 9 | errstatus=0 10 | 11 | for file 12 | do 13 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 14 | shift 15 | 16 | pathcomp= 17 | for d 18 | do 19 | pathcomp="$pathcomp$d" 20 | case "$pathcomp" in 21 | -* ) pathcomp=./$pathcomp ;; 22 | esac 23 | 24 | if test ! -d "$pathcomp"; then 25 | echo "mkdir $pathcomp" 1>&2 26 | 27 | mkdir "$pathcomp" || lasterr=$? 28 | 29 | if test ! -d "$pathcomp"; then 30 | errstatus=$lasterr 31 | fi 32 | fi 33 | 34 | pathcomp="$pathcomp/" 35 | done 36 | done 37 | 38 | exit $errstatus 39 | 40 | # mkinstalldirs ends here 41 | -------------------------------------------------------------------------------- /phptests/nextres.php: -------------------------------------------------------------------------------- 1 | 1 15 | BEGIN 16 | FETCH NEXT FROM Search 17 | SET @limit = @limit -1 18 | END 19 | CLOSE Search 20 | DEALLOCATE Search 21 | EOSQL; 22 | 23 | $num_rows = 0; 24 | $res = mssql_query($sql) or die("query"); 25 | $row = mssql_fetch_assoc($res); 26 | while ($row) { 27 | ++$num_rows; 28 | // print_r($row); 29 | echo "got a row, name is $row[name]\n"; 30 | $row = mssql_fetch_assoc($res); 31 | if (!$row) { 32 | if (mssql_next_result($res)) { 33 | $row = mssql_fetch_assoc($res); 34 | } 35 | } 36 | } 37 | 38 | if ($num_rows < 2) { 39 | echo "Expected more than a row\n"; 40 | exit(1); 41 | } 42 | exit(0); 43 | ?> 44 | -------------------------------------------------------------------------------- /phptests/null.php: -------------------------------------------------------------------------------- 1 | $s\n"; 37 | if ($s != $expected) 38 | { 39 | echo "error!\n"; 40 | $result = 1; 41 | } 42 | } 43 | 44 | test("SELECT top 1 * FROM #MyTable WHERE n = 1 -- ''", "(Empty String)"); 45 | 46 | test("SELECT top 1 * FROM #MyTable WHERE n = 2 -- NULL", "(NULL)"); 47 | 48 | test("SELECT top 1 * FROM #MyTable WHERE n = 3 -- ' '", "' '"); 49 | 50 | test("SELECT top 1 * FROM #MyTable WHERE n = 4 -- 'a'", "'a'"); 51 | 52 | exit($result); 53 | ?> 54 | -------------------------------------------------------------------------------- /phptests/rpc1.php: -------------------------------------------------------------------------------- 1 | 64 | -------------------------------------------------------------------------------- /phptests/types.php: -------------------------------------------------------------------------------- 1 | 'smallint-5', 27 | 'i' => 'int-10', 28 | 'ti' => 'tinyint-3', 29 | 'c' => 'char-123', 30 | 'vc' => 'varchar-125' 31 | ); 32 | 33 | $err = ''; 34 | $ok = 0; 35 | for($i=1;$i<=odbc_num_fields($result);$i++) { 36 | $name = odbc_field_name($result,$i); 37 | $type = odbc_field_type($result,$i); 38 | $len = odbc_field_len($result,$i); 39 | echo "column $name type $type len $len\n"; 40 | $type = strtolower($type); 41 | if ($all[$name] != "$type-$len") 42 | $err .= "Invalid column $name\n"; 43 | else 44 | ++$ok; 45 | } 46 | 47 | if ($ok != 5) 48 | $err .= "Expected 5 columns\n"; 49 | 50 | if ($err) { 51 | echo "$err"; 52 | exit(1); 53 | } 54 | echo "all columns seems ok\n"; 55 | 56 | odbc_exec($conn, "IF OBJECT_ID('php_types') IS NOT NULL DROP TABLE php_types") or die(odbc_errormsg()); 57 | 58 | exit(0); 59 | ?> 60 | -------------------------------------------------------------------------------- /samples/.gitignore: -------------------------------------------------------------------------------- 1 | unixodbc.freetds.driver.template 2 | -------------------------------------------------------------------------------- /samples/Makefile.am: -------------------------------------------------------------------------------- 1 | # version $Id: Makefile.am,v 1.3 2006-09-13 11:56:37 freddy77 Exp $ 2 | 3 | noinst_SCRIPTS = unixodbc.freetds.driver.template 4 | 5 | EXTRA_DIST = README debug.c dyntest.c odbc.ini odbctest.php \ 6 | odbctest.pl test.php test.pl \ 7 | unixodbc.freetds.driver.template.in \ 8 | unixodbc.install.sh \ 9 | unixodbc.jdbc.datasource.template 10 | 11 | SUFFIXES = .in 12 | 13 | edit = sed \ 14 | -e 's,@datadir\@,$(pkgdatadir),g' \ 15 | -e 's,@libdir\@,$(libdir),g' \ 16 | -e 's,@prefix\@,$(prefix),g' 17 | 18 | unixodbc.freetds.driver.template: unixodbc.freetds.driver.template.in 19 | 20 | CLEANFILES = unixodbc.freetds.driver.template 21 | 22 | .in: 23 | rm -f $@ $@.tmp 24 | $(edit) $< >$@.tmp 25 | mv $@.tmp $@ 26 | -------------------------------------------------------------------------------- /samples/Makefile.bcp_test: -------------------------------------------------------------------------------- 1 | # This file is not part of Makefile.am because the source code is C++, 2 | # and FreeTDS requires only a C compiler. 3 | # 4 | 5 | DBLIB_H = /usr/local 6 | DBLIB_L = ../build/src/dblib/.libs 7 | FLAGS = -D MSDBLIB -fmessage-length=$$(stty -a | awk '/^speed/ {print $$6}') 8 | INC = -I $(DBLIB_H)/include 9 | LIB = -L $(DBLIB_L) -Wl,-R$(DBLIB_L) -lsybdb 10 | 11 | bcp_test: bcp_test.cpp 12 | $(CXX) -o $@ bcp_test.cpp -g -O0 $(FLAGS) $(INC) $(LIB) 13 | -------------------------------------------------------------------------------- /samples/README: -------------------------------------------------------------------------------- 1 | The dblib and ctlib test programs in this directory are old. Please refer to the src/dblib/unittests and src/ctlib/unittests for better examples. 2 | 3 | -------------------------------------------------------------------------------- /samples/debug.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998-1999 Brian Bruns 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | static char software_version[] = "$Id: debug.c,v 1.2 2001-10-13 00:02:54 brianb Exp $"; 33 | static void *no_unused_var_warn[] = {software_version, 34 | no_unused_var_warn}; 35 | 36 | 37 | extern errno; 38 | 39 | get_incoming (int fd) 40 | { 41 | 42 | FILE *out; 43 | int len, i, offs=0; 44 | unsigned char buf[BUFSIZ]; 45 | 46 | 47 | 48 | out = fopen("client.out","w"); 49 | 50 | while ((len = read(fd, buf, BUFSIZ)) > 0) { 51 | fprintf (out,"len is %d\n",len); 52 | for (i=0;i=' ' && buf[i]<'z') 55 | fprintf(out," %c",buf[i]); 56 | fprintf(out,"\n"); 57 | } 58 | fflush(out); 59 | } 60 | close(fd); 61 | fclose(out); 62 | } 63 | -------------------------------------------------------------------------------- /samples/isql.sybperl: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/sybperl 2 | # $Id: isql.sybperl,v 1.1 2003-03-27 07:42:49 jklowden Exp $ 3 | # Contributed by Michael Peppler on 26 March 2003 4 | 5 | require 'sybperl.pl'; 6 | require 'getopts.pl'; 7 | 8 | &Getopts('P:U:'); 9 | 10 | &dblogin($opt_U, $opt_P); 11 | 12 | select(STDOUT); $| = 1; # set unbuffered 13 | 14 | $count = 1; 15 | print "$count> "; 16 | 17 | while(<>) 18 | { 19 | /^exit|^quit/ && exit(0); 20 | /^go/ && do { 21 | &exec; 22 | $count = 1; 23 | print "$count> "; 24 | next; 25 | }; 26 | 27 | &dbcmd($_); 28 | ++$count; 29 | print "$count> "; 30 | } 31 | 32 | sub exec 33 | { 34 | local($ret, $numcol, $i); 35 | local(@dat, %width); 36 | 37 | &dbsqlexec; 38 | while(($ret = &dbresults) != $NO_MORE_RESULTS) 39 | { 40 | $numcol = &dbnumcols; 41 | for($i = 1; $i <= $numcol; ++$i) 42 | { 43 | $width{$i} = &dbcollen(0, $i); 44 | printf("%-$width{$i}.$width{$i}s ", &dbcolname(0, $i)); 45 | } 46 | print "\n\n"; 47 | while(@dat = &dbnextrow) 48 | { 49 | for($i = 1; $i <= $numcol; ++$i) 50 | { 51 | printf("%$width{$i}.$width{$i}s ", $dat[$i-1]); 52 | } 53 | print "\n"; 54 | } 55 | while(@dat = &dbretdata) 56 | { 57 | print "@dat\n"; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /samples/mssql.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | MS SQL Query 4 | 5 | 6 | 7 | 8 | 9 | 0) { 18 | $query=stripslashes($_REQUEST["sqlquery"]); 19 | } 20 | 21 | 22 | $mslink=mssql_connect("$dbserver" , "$dbuser" , "$dbpass" ) or 23 | die("Could not connect to $dbserver: " . mssql_get_last_message()); 24 | 25 | $msdb=mssql_select_db($dbname,$mslink) or 26 | die("Could not select $dbname: " . mssql_get_last_message()); 27 | 28 | $result=mssql_query($query) or 29 | die("Could not $query: " . mssql_get_last_message()); 30 | 31 | $numRows = mssql_num_rows($result); 32 | $numfields = mssql_num_fields($result); 33 | $today=date("D M j G:i:s T Y"); 34 | 35 | echo << 37 | $today 38 |

39 |

40 | 41 | 42 |
43 |

44 | 45 | 46 | EOF; 47 | for ($i=0; $i<$numfields; $i++) { 48 | echo ""; 49 | } 50 | echo "\n"; 51 | while($row = mssql_fetch_row($result)) 52 | { 53 | echo ""; 54 | foreach ($row as $fieldvalue) 55 | { 56 | echo ""; 57 | } 58 | echo "\n"; 59 | } 60 | mssql_close($mslink); 61 | ?> 62 |
" . mssql_field_name($result,$i) . "
$fieldvalue
63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /samples/odbc.ini: -------------------------------------------------------------------------------- 1 | ; 2 | ; odbc.ini 3 | ; 4 | [ODBC Data Sources] 5 | JDBC = Sybase JDBC Server 6 | 7 | [JDBC] 8 | Driver = /usr/local/lib/libtdsodbc.so 9 | Description = Sybase JDBC Server 10 | Trace = No 11 | Servername = JDBC 12 | Database = pubs2 13 | UID = guest 14 | 15 | [Default] 16 | Driver = /usr/local/lib/libtdsodbc.so 17 | -------------------------------------------------------------------------------- /samples/odbctest.php: -------------------------------------------------------------------------------- 1 | 25 | -------------------------------------------------------------------------------- /samples/odbctest.pl: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/perl 2 | # $Id: odbctest.pl,v 1.2 2005-04-04 22:05:33 jklowden Exp $ 3 | 4 | use DBI; 5 | 6 | my ($dsn, $user, $pass, $sql) = @ARGV; 7 | 8 | $dsn = "dbi:ODBC:JDBC" unless $dsn; 9 | $user = 'guest' unless $user; 10 | $pass = 'sybase' unless $pass; 11 | 12 | $sql ="select \@\@servername" unless $sql; 13 | 14 | my $dbh = DBI->connect($dsn, $user, $pass, {PrintError => 1}); 15 | 16 | die "Unable for connect to server $DBI::errstr" 17 | unless $dbh; 18 | 19 | my $rc; 20 | 21 | my $sth = $dbh->prepare($sql); 22 | if($sth->execute) { 23 | while(@dat = $sth->fetchrow) { 24 | print "@dat\n"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/test.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | \n"; 14 | } 15 | ?> 16 | 17 | 18 | -------------------------------------------------------------------------------- /samples/test.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | use DBI; 4 | 5 | my ($servername, $username, $password) = @ARGV; 6 | 7 | $servername = 'JDBC' unless $servername; 8 | $username = 'guest' unless $username; 9 | $password = 'sybase' unless $password; 10 | 11 | my $dbh = DBI->connect("dbi:Sybase:server=$servername", $username, $password, {PrintError => 0}); 12 | 13 | die "Unable for connect to server $DBI::errstr" 14 | unless $dbh; 15 | 16 | my $rc; 17 | my $sth; 18 | 19 | if (@ARGV > 3) { 20 | $query = $ARGV[3]; 21 | } else { 22 | $query = "select \@\@version"; 23 | } 24 | 25 | $sth = $dbh->prepare($query); 26 | print $sth->{"ChopBlanks"} = 0; 27 | 28 | if($sth->execute) { 29 | while(@dat = $sth->fetchrow) { 30 | print "@dat\n"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /samples/unixodbc.freetds.driver.template.in: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: unixodbc.freetds.driver.template.in,v 1.2 2006-09-13 11:56:37 freddy77 Exp $ 3 | # 4 | # FreeTDS - Library of routines accessing Sybase and Microsoft databases 5 | # Copyright (C) 1998-1999 Brian Bruns 6 | # 7 | # This library is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU Library General Public 9 | # License as published by the Free Software Foundation; either 10 | # version 2 of the License, or (at your option) any later version. 11 | # 12 | # This library is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Library General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Library General Public 18 | # License along with this library; if not, write to the 19 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | # Boston, MA 02111-1307, USA. 21 | # 22 | [FreeTDS] 23 | Description = FreeTDS unixODBC Driver 24 | Driver = @libdir@/libtdsodbc.so 25 | Setup = @libdir@/libtdsodbc.so 26 | -------------------------------------------------------------------------------- /samples/unixodbc.install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # $Id: unixodbc.install.sh,v 1.1 2002-10-09 17:05:44 castellano Exp $ 4 | # 5 | # FreeTDS - Library of routines accessing Sybase and Microsoft databases 6 | # Copyright (C) 1998-1999 Brian Bruns 7 | # 8 | # This library is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU Library General Public 10 | # License as published by the Free Software Foundation; either 11 | # version 2 of the License, or (at your option) any later version. 12 | # 13 | # This library is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # Library General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Library General Public 19 | # License along with this library; if not, write to the 20 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | # Boston, MA 02111-1307, USA. 22 | 23 | # 24 | # Run this script as root to install FreeTDS unixODBC drivers and datasources. 25 | # 26 | # You will most likely want to edit unixodbc.jdbc.datasource.template 27 | # to add your own dataserver instead of the public Sybase dataserver. 28 | # 29 | # For more information about these template files, please see 30 | # http://www.unixodbc.org/doc/FreeTDS.html 31 | # 32 | 33 | # Install driver. 34 | odbcinst -i -d -f unixodbc.freetds.driver.template 35 | # Install system datasource. 36 | odbcinst -i -s -l -f unixodbc.jdbc.datasource.template 37 | -------------------------------------------------------------------------------- /samples/unixodbc.jdbc.datasource.template: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: unixodbc.jdbc.datasource.template,v 1.1 2002-10-09 17:05:44 castellano Exp $ 3 | # 4 | # FreeTDS - Library of routines accessing Sybase and Microsoft databases 5 | # Copyright (C) 1998-1999 Brian Bruns 6 | # 7 | # This library is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU Library General Public 9 | # License as published by the Free Software Foundation; either 10 | # version 2 of the License, or (at your option) any later version. 11 | # 12 | # This library is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Library General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Library General Public 18 | # License along with this library; if not, write to the 19 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | # Boston, MA 02111-1307, USA. 21 | # 22 | [JDBC] 23 | Driver = FreeTDS 24 | Description = Sybase JDBC Server 25 | Trace = No 26 | Servername = JDBC 27 | Database = pubs2 28 | UID = guest 29 | -------------------------------------------------------------------------------- /src/.indent.pro: -------------------------------------------------------------------------------- 1 | -bad 2 | -bap 3 | -nbbb 4 | -bbo 5 | -nbc 6 | -br 7 | -c33 8 | 9 | -ncdb 10 | -cdw 11 | -ce 12 | 13 | -cli0 14 | -cs 15 | 16 | -d0 17 | -di1 18 | 19 | -nfc1 20 | 21 | -i8 22 | -ts8 23 | 24 | -l132 25 | 26 | -lp 27 | 28 | -npcs 29 | -nprs 30 | -psl 31 | -sc 32 | -nsob 33 | 34 | -ut 35 | 36 | -nv 37 | 38 | -saf 39 | -sai 40 | -saw 41 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = replacements tds ctlib dblib 2 | DIST_SUBDIRS = $(SUBDIRS) 3 | 4 | if ODBC 5 | SUBDIRS += odbc 6 | else 7 | DIST_SUBDIRS += odbc 8 | endif 9 | 10 | if INCPOOL 11 | SUBDIRS += server pool 12 | else !INCPOOL 13 | if INCSERVER 14 | SUBDIRS += server 15 | endif 16 | endif 17 | 18 | if INCAPPS 19 | SUBDIRS += apps 20 | endif 21 | -------------------------------------------------------------------------------- /src/apps/.gitignore: -------------------------------------------------------------------------------- 1 | tsql 2 | freebcp 3 | bsqldb 4 | defncopy 5 | datacopy 6 | bsqlodbc 7 | 8 | -------------------------------------------------------------------------------- /src/apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(libs ${lib_NETWORK} ${lib_BASE}) 2 | 3 | foreach(target freebcp bsqldb defncopy datacopy) 4 | add_executable(${target} ${target}.c) 5 | target_link_libraries(${target} sybdb replacements ${libs}) 6 | endforeach(target) 7 | 8 | 9 | add_executable(tsql tsql.c) 10 | target_link_libraries(tsql tds replacements ${lib_READLINE} ${libs}) 11 | 12 | if(WIN32) 13 | set(libs odbc32 ${lib_NETWORK} ${lib_BASE}) 14 | endif(WIN32) 15 | 16 | add_executable(bsqlodbc bsqlodbc.c) 17 | target_link_libraries(bsqlodbc tdsodbc replacements ${libs}) 18 | -------------------------------------------------------------------------------- /src/apps/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am,v 1.31 2011-06-08 09:25:51 freddy77 Exp $ 2 | 3 | AM_CPPFLAGS = -I$(top_srcdir)/include 4 | 5 | SUBDIRS = fisql 6 | 7 | DIST_SUBDIRS = $(SUBDIRS) 8 | 9 | bin_PROGRAMS = tsql freebcp bsqldb defncopy datacopy 10 | # build bsqlodbc only if the ODBC library was to be built 11 | if ODBC 12 | bin_PROGRAMS += bsqlodbc 13 | endif 14 | 15 | 16 | dist_bin_SCRIPTS = osql 17 | 18 | freebcp_LDADD = ../dblib/libsybdb.la ../replacements/libreplacements.la $(LTLIBICONV) 19 | freebcp_SOURCES = freebcp.c freebcp.h 20 | 21 | tsql_LDADD = ../tds/libtds.la \ 22 | ../replacements/libreplacements.la \ 23 | $(LTLIBICONV) $(FREETDS_LIBGCC) $(READLINE_LIBS) 24 | 25 | bsqldb_LDADD = ../dblib/libsybdb.la \ 26 | ../replacements/libreplacements.la \ 27 | $(LTLIBICONV) 28 | 29 | if ODBC 30 | bsqlodbc_CPPFLAGS = $(ODBC_INC) $(AM_CPPFLAGS) 31 | bsqlodbc_LDADD = $(ODBCLIB) $(ODBCNODMLIBAPP) \ 32 | ../replacements/libreplacements.la $(LTLIBICONV) 33 | endif 34 | 35 | defncopy_LDADD = ../dblib/libsybdb.la \ 36 | ../replacements/libreplacements.la \ 37 | $(LTLIBICONV) 38 | 39 | datacopy_SOURCES= datacopy.c 40 | datacopy_LDADD = ../dblib/libsybdb.la \ 41 | ../replacements/libreplacements.la \ 42 | $(LTLIBICONV) 43 | 44 | EXTRA_DIST = CMakeLists.txt 45 | -------------------------------------------------------------------------------- /src/apps/fisql/.gitignore: -------------------------------------------------------------------------------- 1 | fisql 2 | -------------------------------------------------------------------------------- /src/apps/fisql/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am,v 1.5 2011-06-08 09:25:52 freddy77 Exp $ 2 | 3 | AM_CPPFLAGS = -I$(top_srcdir)/include 4 | 5 | if !MINGW32 6 | bin_PROGRAMS = fisql 7 | 8 | fisql_SOURCES = fisql.c \ 9 | terminal.h terminal.c \ 10 | edit.h edit.c \ 11 | handlers.h handlers.c \ 12 | interrupt.h interrupt.c 13 | 14 | 15 | fisql_LDADD = ../../dblib/libsybdb.la \ 16 | ../../replacements/libreplacements.la \ 17 | $(LTLIBICONV) $(READLINE_LIBS) 18 | endif 19 | -------------------------------------------------------------------------------- /src/apps/fisql/edit.c: -------------------------------------------------------------------------------- 1 | /* Free ISQL - An isql for DB-Library (C) 2007 Nicholas S. Castellano 2 | * 3 | * This program is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Library General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public 14 | * License along with this library; if not, write to the 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | * Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "edit.h" 28 | #include "terminal.h" 29 | 30 | int 31 | edit(const char *editor, const char *arg) 32 | { 33 | int pid; 34 | 35 | retry_fork: 36 | pid = fork(); 37 | switch (pid) { 38 | case -1: 39 | if (errno == EAGAIN) { 40 | sleep(5); 41 | goto retry_fork; 42 | } 43 | perror("fisql"); 44 | reset_term(); 45 | dbexit(); 46 | exit(EXIT_FAILURE); 47 | break; 48 | case 0: 49 | execlp(editor, editor, arg, (char *) 0); 50 | fprintf(stderr, "Unable to invoke the '%s' editor.\n", editor); 51 | exit(EXIT_FAILURE); 52 | break; 53 | default: 54 | waitpid(pid, (int *) 0, 0); 55 | break; 56 | } 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /src/apps/fisql/edit.h: -------------------------------------------------------------------------------- 1 | /* Free ISQL - An isql for DB-Library (C) 2007 Nicholas S. Castellano 2 | * 3 | * This program is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Library General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public 14 | * License along with this library; if not, write to the 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | * Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | /* $Id: edit.h,v 1.3 2007-01-20 06:32:27 castellano Exp $ */ 20 | int edit(const char *editor, const char *arg); 21 | -------------------------------------------------------------------------------- /src/apps/fisql/handlers.h: -------------------------------------------------------------------------------- 1 | /* Free ISQL - An isql for DB-Library (C) 2007 Nicholas S. Castellano 2 | * 3 | * This program is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Library General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public 14 | * License along with this library; if not, write to the 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | * Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | /* $Id: handlers.h,v 1.4 2007-01-20 06:32:27 castellano Exp $ */ 20 | extern int global_errorlevel; 21 | 22 | int err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr); 23 | 24 | int msg_handler(DBPROCESS * dbproc, DBINT msgno, int msgstate, 25 | int severity, char *msgtext, char *srvname, char *procname, int line); 26 | -------------------------------------------------------------------------------- /src/apps/fisql/interrupt.c: -------------------------------------------------------------------------------- 1 | /* Free ISQL - An isql for DB-Library (C) 2007 Nicholas S. Castellano 2 | * 3 | * This program is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Library General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public 14 | * License along with this library; if not, write to the 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | * Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "interrupt.h" 24 | 25 | sigjmp_buf restart; 26 | volatile int os_interrupt = 0; 27 | 28 | void 29 | inactive_interrupt_handler(int sig) 30 | { 31 | siglongjmp(restart, 1); 32 | } 33 | 34 | void 35 | active_interrupt_handler(int sig) 36 | { 37 | os_interrupt = sig; 38 | } 39 | 40 | void 41 | maybe_handle_active_interrupt(void) 42 | { 43 | int sig; 44 | 45 | if (os_interrupt) { 46 | sig = os_interrupt; 47 | os_interrupt = 0; 48 | inactive_interrupt_handler(sig); 49 | } 50 | } 51 | 52 | int 53 | active_interrupt_pending(DBPROCESS * dbproc) 54 | { 55 | if (os_interrupt) { 56 | return TRUE; 57 | } 58 | return FALSE; 59 | } 60 | 61 | int 62 | active_interrupt_servhandler(DBPROCESS * dbproc) 63 | { 64 | return INT_CANCEL; 65 | } 66 | -------------------------------------------------------------------------------- /src/apps/fisql/interrupt.h: -------------------------------------------------------------------------------- 1 | /* Free ISQL - An isql for DB-Library (C) 2007 Nicholas S. Castellano 2 | * 3 | * This program is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Library General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public 14 | * License along with this library; if not, write to the 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | * Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | /* $Id: interrupt.h,v 1.4 2007-01-20 06:32:27 castellano Exp $ */ 20 | extern sigjmp_buf restart; 21 | 22 | void inactive_interrupt_handler(int sig); 23 | void active_interrupt_handler(int sig); 24 | void maybe_handle_active_interrupt(void); 25 | int active_interrupt_pending(DBPROCESS * dbproc); 26 | int active_interrupt_servhandler(DBPROCESS * dbproc); 27 | -------------------------------------------------------------------------------- /src/apps/fisql/terminal.c: -------------------------------------------------------------------------------- 1 | /* Free ISQL - An isql for DB-Library (C) 2007 Nicholas S. Castellano 2 | * 3 | * This program is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Library General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public 14 | * License along with this library; if not, write to the 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | * Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "terminal.h" 23 | 24 | static struct termios term; 25 | static struct termios oterm; 26 | static int term_init = 0; 27 | 28 | int 29 | save_term() 30 | { 31 | int r; 32 | 33 | if (!isatty(fileno(stdin))) { 34 | return 1; 35 | } 36 | if (term_init) { 37 | return 0; 38 | } 39 | if ((r = tcgetattr(fileno(stdin), &oterm)) != 0) { 40 | return r; 41 | } 42 | term_init = 1; 43 | return 0; 44 | } 45 | 46 | int 47 | set_term_noecho() 48 | { 49 | int r; 50 | 51 | if (!isatty(fileno(stdin))) { 52 | return 1; 53 | } 54 | if ((r = save_term()) != 0) { 55 | return r; 56 | } 57 | if ((r = tcgetattr(fileno(stdin), &term)) != 0) { 58 | return r; 59 | } 60 | term.c_lflag &= ~(ICANON | ECHO); 61 | if ((r = tcsetattr(fileno(stdin), TCSANOW, &term)) != 0) { 62 | return r; 63 | } 64 | return 0; 65 | } 66 | 67 | int 68 | reset_term() 69 | { 70 | int r; 71 | 72 | if (!isatty(fileno(stdin))) { 73 | return 1; 74 | } 75 | if ((r = save_term()) != 0) { 76 | return r; 77 | } 78 | if ((r = tcsetattr(fileno(stdin), TCSANOW, &oterm)) != 0) { 79 | return r; 80 | } 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /src/apps/fisql/terminal.h: -------------------------------------------------------------------------------- 1 | /* Free ISQL - An isql for DB-Library (C) 2007 Nicholas S. Castellano 2 | * 3 | * This program is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Library General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public 14 | * License along with this library; if not, write to the 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | * Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | /* $Id: terminal.h,v 1.4 2007-01-20 06:32:27 castellano Exp $ */ 20 | int save_term(void); 21 | int set_term_noecho(void); 22 | int reset_term(void); 23 | -------------------------------------------------------------------------------- /src/apps/freebcp.h: -------------------------------------------------------------------------------- 1 | enum states 2 | { 3 | GET_NEXTARG, 4 | GET_MAXERRORS, 5 | GET_FORMATFILE, 6 | GET_ERRORFILE, 7 | GET_FIRSTROW, 8 | GET_LASTROW, 9 | GET_BATCHSIZE, 10 | GET_FIELDTERM, 11 | GET_ROWTERM, 12 | GET_USER, 13 | GET_PASS, 14 | GET_INTERFACESFILE, 15 | GET_SERVER, 16 | GET_DISPLAYCHARSET, 17 | GET_DATAFILECHARSET, 18 | GET_LANGUAGE, 19 | GET_PACKETSIZE, 20 | GET_CLIENTCHARSET, 21 | GET_TEXTSIZE, 22 | GET_SYBASEDIR, 23 | GET_FROMLABEL, 24 | GET_TOLABEL, 25 | GET_HINT 26 | }; 27 | 28 | typedef struct pd 29 | { 30 | char *dbobject; 31 | char dbdirection[10]; 32 | DBINT direction; 33 | char *hostfilename; 34 | char *formatfile; 35 | char *errorfile; 36 | char *interfacesfile; 37 | int firstrow; 38 | int lastrow; 39 | int batchsize; 40 | int maxerrors; 41 | int textsize; 42 | char *fieldterm; 43 | int fieldtermlen; 44 | char *rowterm; 45 | int rowtermlen; 46 | char *user; 47 | char *pass; 48 | char *server; 49 | char *dbname; 50 | char *hint; 51 | char *options; 52 | char *charset; 53 | int packetsize; 54 | int mflag; 55 | int fflag; 56 | int eflag; 57 | int Fflag; 58 | int Lflag; 59 | int bflag; 60 | int nflag; 61 | int cflag; 62 | int tflag; 63 | int rflag; 64 | int Uflag; 65 | int Iflag; 66 | int Sflag; 67 | int Pflag; 68 | int Tflag; 69 | int Aflag; 70 | int Eflag; 71 | char *inputfile; 72 | char *outputfile; 73 | } 74 | BCPPARAMDATA; 75 | -------------------------------------------------------------------------------- /src/ctlib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(unittests) 2 | 3 | set(static_lib_name ct) 4 | if(WIN32) 5 | add_definitions(-DDLL_EXPORT) 6 | set(win_SRCS winmain.c ctlib.def) 7 | set(static_lib_name libct) 8 | endif() 9 | 10 | add_library(ct SHARED 11 | ct.c cs.c blk.c ctutil.c 12 | ${win_SRCS} 13 | ) 14 | 15 | target_link_libraries(ct tds replacements ${lib_NETWORK} ${lib_BASE}) 16 | 17 | add_library(ct-static STATIC 18 | ct.c cs.c blk.c ctutil.c 19 | ) 20 | # See http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_make_my_shared_and_static_libraries_have_the_same_root_name.2C_but_different_suffixes.3F 21 | SET_TARGET_PROPERTIES(ct-static PROPERTIES OUTPUT_NAME ${static_lib_name}) 22 | SET_TARGET_PROPERTIES(ct PROPERTIES CLEAN_DIRECT_OUTPUT 1) 23 | SET_TARGET_PROPERTIES(ct-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) 24 | 25 | target_link_libraries(ct-static tds replacements ${lib_NETWORK} ${lib_BASE}) 26 | 27 | if(NOT WIN32) 28 | set_target_properties(ct PROPERTIES SOVERSION "4.0.0") 29 | endif() 30 | 31 | if(MINGW OR CYGWIN) 32 | set_target_properties(ct PROPERTIES LINK_FLAGS "--static") 33 | endif(MINGW OR CYGWIN) 34 | -------------------------------------------------------------------------------- /src/ctlib/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am,v 1.29 2011-06-08 09:25:53 freddy77 Exp $ 2 | SUBDIRS = . unittests 3 | AM_CPPFLAGS = -I$(top_srcdir)/include 4 | 5 | lib_LTLIBRARIES = libct.la 6 | libct_la_SOURCES= ct.c cs.c blk.c ctutil.c 7 | if MINGW32 8 | libct_la_SOURCES += winmain.c 9 | endif 10 | 11 | # version bumped for 0.64, I hope we'll bump it less in the future -- freddy77 12 | libct_la_LDFLAGS = -version-info 4:0:0 $(FREETDS_SYMBOLIC) 13 | if !MACOSX 14 | libct_la_LDFLAGS += -export-symbols-regex '^(cs_|ct_|blk_).*' 15 | endif 16 | 17 | libct_la_LIBADD = ../tds/libtds.la ../replacements/libreplacements.la $(LTLIBICONV) $(FREETDS_LIBGCC) 18 | 19 | EXTRA_DIST = ctlib.def CMakeLists.txt winmain.c 20 | 21 | -------------------------------------------------------------------------------- /src/ctlib/ctlib.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | blk_alloc 3 | blk_bind 4 | blk_colval 5 | blk_default 6 | blk_describe 7 | blk_done 8 | blk_drop 9 | blk_getrow 10 | blk_gettext 11 | blk_init 12 | blk_props 13 | blk_rowalloc 14 | blk_rowdrop 15 | blk_rowxfer 16 | blk_rowxfer_mult 17 | blk_sendrow 18 | blk_sendtext 19 | blk_srvinit 20 | blk_textxfer 21 | cs_calc 22 | cs_cmp 23 | cs_config 24 | cs_convert 25 | cs_conv_mult 26 | cs_ctx_alloc 27 | cs_ctx_drop 28 | cs_ctx_global 29 | cs_diag 30 | cs_dt_crack 31 | cs_dt_info 32 | cs_locale 33 | cs_loc_alloc 34 | cs_loc_drop 35 | cs_manage_convert 36 | cs_objects 37 | cs_prretcode 38 | cs_set_convert 39 | cs_setnull 40 | cs_strbuild 41 | cs_strcmp 42 | cs_time 43 | cs_will_convert 44 | ct_bind 45 | ct_callback 46 | ct_cancel 47 | ct_capability 48 | ct_close 49 | ct_cmd_alloc 50 | ct_cmd_drop 51 | ct_cmd_props 52 | ct_command 53 | ct_compute_info 54 | ct_con_alloc 55 | ct_con_drop 56 | ct_config 57 | ct_connect 58 | ct_con_props 59 | ct_cursor 60 | ct_data_info 61 | ct_describe 62 | ct_diag 63 | ct_dynamic 64 | ct_exit 65 | ct_fetch 66 | ct_get_data 67 | ct_init 68 | ct_options 69 | ct_param 70 | ct_poll 71 | ct_res_info 72 | ct_results 73 | ct_send 74 | ct_send_data 75 | ct_setparam 76 | -------------------------------------------------------------------------------- /src/ctlib/unittests/.gitignore: -------------------------------------------------------------------------------- 1 | t0001 2 | t0002 3 | t0003 4 | t0004 5 | t0005 6 | t0006 7 | t0007 8 | t0008 9 | t0009 10 | connect_fail 11 | tdsdump.out 12 | ct_options 13 | rpc_ct_setparam 14 | rpc_ct_param 15 | lang_ct_param 16 | get_send_data 17 | cs_diag 18 | array_bind 19 | ct_diagall 20 | ct_diagclient 21 | ct_diagserver 22 | cs_config 23 | cancel 24 | blk_in 25 | blk_out 26 | ct_cursor 27 | ct_cursors 28 | ct_dynamic 29 | blk_in2 30 | datafmt 31 | rpc_fail 32 | 33 | -------------------------------------------------------------------------------- /src/ctlib/unittests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(c_common STATIC common.c common.h) 2 | 3 | foreach(target t0001 t0002 t0003 t0004 4 | t0005 t0006 t0007 t0008 5 | t0009 connect_fail ct_options 6 | lang_ct_param array_bind cs_diag 7 | get_send_data rpc_ct_param rpc_ct_setparam 8 | ct_diagclient ct_diagserver ct_diagall 9 | cs_config cancel blk_in 10 | blk_out ct_cursor ct_cursors 11 | ct_dynamic blk_in2 datafmt) 12 | add_executable(c_${target} EXCLUDE_FROM_ALL ${target}.c) 13 | set_target_properties(c_${target} PROPERTIES OUTPUT_NAME ${target}) 14 | target_link_libraries(c_${target} c_common ct replacements ${lib_NETWORK} ${lib_BASE}) 15 | add_test(NAME c_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${target}) 16 | add_dependencies(check c_${target}) 17 | endforeach(target) 18 | -------------------------------------------------------------------------------- /src/ctlib/unittests/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef COMMON_h 3 | #define COMMON_h 4 | 5 | static char rcsid_common_h[] = "$Id: common.h,v 1.11 2008-07-06 16:44:24 jklowden Exp $"; 6 | static void *no_unused_common_h_warn[] = { rcsid_common_h, no_unused_common_h_warn }; 7 | 8 | extern char SERVER[512]; 9 | extern char DATABASE[512]; 10 | extern char USER[512]; 11 | extern char PASSWORD[512]; 12 | 13 | typedef struct 14 | { 15 | int initialized; 16 | char SERVER[512]; 17 | char DATABASE[512]; 18 | char USER[512]; 19 | char PASSWORD[512]; 20 | char fverbose; 21 | int maxlength; 22 | } COMMON_PWD; 23 | extern COMMON_PWD common_pwd; 24 | 25 | CS_RETCODE read_login_info(void); 26 | 27 | extern int cslibmsg_cb_invoked; 28 | extern int clientmsg_cb_invoked; 29 | extern int servermsg_cb_invoked; 30 | 31 | CS_RETCODE try_ctlogin(CS_CONTEXT ** ctx, CS_CONNECTION ** conn, CS_COMMAND ** cmd, int verbose); 32 | CS_RETCODE try_ctlogin_with_options(int argc, char **argv, CS_CONTEXT ** ctx, CS_CONNECTION ** conn, CS_COMMAND ** cmd, 33 | int verbose); 34 | 35 | CS_RETCODE try_ctlogout(CS_CONTEXT * ctx, CS_CONNECTION * conn, CS_COMMAND * cmd, int verbose); 36 | 37 | CS_RETCODE run_command(CS_COMMAND * cmd, const char *sql); 38 | CS_RETCODE cslibmsg_cb(CS_CONTEXT * connection, CS_CLIENTMSG * errmsg); 39 | CS_RETCODE clientmsg_cb(CS_CONTEXT * context, CS_CONNECTION * connection, CS_CLIENTMSG * errmsg); 40 | CS_RETCODE servermsg_cb(CS_CONTEXT * context, CS_CONNECTION * connection, CS_SERVERMSG * srvmsg); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/ctlib/unittests/connect_fail.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include "common.h" 6 | 7 | static char software_version[] = "$Id: connect_fail.c,v 1.5 2011-05-16 08:51:40 freddy77 Exp $"; 8 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 9 | 10 | int 11 | main(int argc, char **argv) 12 | { 13 | CS_CONTEXT *ctx; 14 | CS_CONNECTION *conn; 15 | int ret = 1; 16 | 17 | read_login_info(); 18 | 19 | if (cs_ctx_alloc(CS_VERSION_100, &ctx) != CS_SUCCEED) { 20 | fprintf(stderr, "Context Alloc failed!\n"); 21 | return ret; 22 | } 23 | if (ct_init(ctx, CS_VERSION_100) != CS_SUCCEED) { 24 | fprintf(stderr, "Library Init failed!\n"); 25 | return ret; 26 | } 27 | if (ct_con_alloc(ctx, &conn) != CS_SUCCEED) { 28 | fprintf(stderr, "Connect Alloc failed!\n"); 29 | return ret; 30 | } 31 | if (ct_con_props(conn, CS_SET, CS_USERNAME, (CS_VOID*) "sa", CS_NULLTERM, NULL) != CS_SUCCEED) { 32 | fprintf(stderr, "ct_con_props() SET USERNAME failed!\n"); 33 | return ret; 34 | } 35 | if (ct_con_props(conn, CS_SET, CS_PASSWORD, (CS_VOID*) "invalid", CS_NULLTERM, NULL) != CS_SUCCEED) { 36 | fprintf(stderr, "ct_con_props() SET PASSWORD failed!\n"); 37 | return ret; 38 | } 39 | if (ct_connect(conn, SERVER, CS_NULLTERM) != CS_FAIL) { 40 | fprintf(stderr, "Connection succeeded??\n"); 41 | return ret; 42 | } 43 | 44 | if (ct_cancel(conn, NULL, CS_CANCEL_ALL) != CS_SUCCEED) { 45 | fprintf(stderr, "ct_cancel() failed!\n"); 46 | return ret; 47 | } 48 | if (ct_close(conn, CS_UNUSED) != CS_SUCCEED) { 49 | fprintf(stderr, "ct_close() failed!\n"); 50 | return ret; 51 | } 52 | if (ct_con_drop(conn) != CS_SUCCEED) { 53 | fprintf(stderr, "ct_con_drop() failed!\n"); 54 | return ret; 55 | } 56 | if (ct_exit(ctx, CS_UNUSED) != CS_SUCCEED) { 57 | fprintf(stderr, "ct_exit() failed!\n"); 58 | return ret; 59 | } 60 | if (cs_ctx_drop(ctx) != CS_SUCCEED) { 61 | fprintf(stderr, "cs_ctx_drop() failed!\n"); 62 | return ret; 63 | } 64 | 65 | fprintf(stdout, "Test succeeded\n"); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /src/ctlib/unittests/t0001.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include "common.h" 6 | 7 | static char software_version[] = "$Id: t0001.c,v 1.7 2011-05-16 08:51:40 freddy77 Exp $"; 8 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 9 | 10 | int 11 | main(int argc, char **argv) 12 | { 13 | CS_CONTEXT *ctx; 14 | CS_CONNECTION *conn; 15 | CS_COMMAND *cmd; 16 | CS_RETCODE ret; 17 | int verbose = 0; 18 | 19 | fprintf(stdout, "%s: Testing login, logout\n", __FILE__); 20 | if (verbose) { 21 | fprintf(stdout, "Trying login\n"); 22 | } 23 | ret = try_ctlogin(&ctx, &conn, &cmd, verbose); 24 | if (ret != CS_SUCCEED) { 25 | fprintf(stderr, "Login failed\n"); 26 | return 1; 27 | } 28 | 29 | if (verbose) { 30 | fprintf(stdout, "Trying logout\n"); 31 | } 32 | ret = try_ctlogout(ctx, conn, cmd, verbose); 33 | if (ret != CS_SUCCEED) { 34 | fprintf(stderr, "Logout failed\n"); 35 | return 2; 36 | } 37 | 38 | if (verbose) { 39 | fprintf(stdout, "Test succeeded\n"); 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /src/ctlib/unittests/t0005.c: -------------------------------------------------------------------------------- 1 | /* try login and logout multiple times in a row */ 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include "common.h" 8 | 9 | int 10 | main(int argc, char **argv) 11 | { 12 | CS_CONTEXT *ctx; 13 | CS_CONNECTION *conn; 14 | CS_COMMAND *cmd; 15 | CS_RETCODE ret; 16 | int verbose = 0; 17 | int i; 18 | 19 | printf("%s: Testing login, logout\n", __FILE__); 20 | 21 | for (i =0; i < 100; ++i) { 22 | 23 | if (verbose) 24 | printf("Trying login\n"); 25 | 26 | ret = try_ctlogin(&ctx, &conn, &cmd, verbose); 27 | if (ret != CS_SUCCEED) { 28 | fprintf(stderr, "Login failed\n"); 29 | return 1; 30 | } 31 | 32 | if (verbose) 33 | printf("Trying logout\n"); 34 | 35 | ret = try_ctlogout(ctx, conn, cmd, verbose); 36 | if (ret != CS_SUCCEED) { 37 | fprintf(stderr, "Logout failed\n"); 38 | return 2; 39 | } 40 | } 41 | 42 | if (verbose) 43 | printf("Test succeeded\n"); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /src/ctlib/winmain.c: -------------------------------------------------------------------------------- 1 | #include "../../win32/initnet.c" 2 | -------------------------------------------------------------------------------- /src/dblib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(unittests) 2 | 3 | if(WIN32) 4 | add_definitions(-DDLL_EXPORT) 5 | set(win_SRCS winmain.c dblib.def dbopen.c) 6 | endif() 7 | 8 | # TODO add dbopen.c if necessary 9 | add_library(sybdb SHARED 10 | dblib.c dbutil.c rpc.c bcp.c xact.c dbpivot.c buffering.h 11 | ${win_SRCS} 12 | ) 13 | target_link_libraries(sybdb tds replacements ${lib_NETWORK} ${lib_BASE}) 14 | 15 | add_library(db-lib STATIC 16 | dblib.c dbutil.c rpc.c bcp.c xact.c dbpivot.c buffering.h 17 | ) 18 | target_link_libraries(db-lib tds replacements ${lib_NETWORK} ${lib_BASE}) 19 | 20 | if(NOT WIN32) 21 | set_target_properties(sybdb PROPERTIES SOVERSION "5.0.0") 22 | endif() 23 | 24 | if(MINGW OR CYGWIN) 25 | set_target_properties(sybdb PROPERTIES LINK_FLAGS "--static") 26 | endif(MINGW OR CYGWIN) 27 | -------------------------------------------------------------------------------- /src/dblib/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am,v 1.39 2011-12-05 02:26:31 jklowden Exp $ 2 | SUBDIRS = . unittests 3 | AM_CPPFLAGS = -I$(top_srcdir)/include 4 | 5 | lib_LTLIBRARIES = libsybdb.la 6 | libsybdb_la_SOURCES= dblib.c dbutil.c rpc.c bcp.c xact.c dbpivot.c 7 | if SYBASE_COMPAT 8 | libsybdb_la_SOURCES += dbopen.c 9 | endif 10 | if MINGW32 11 | libsybdb_la_SOURCES += winmain.c 12 | endif 13 | EXTRA_DIST = dbopen.c buffering.h CMakeLists.txt winmain.c dblib.def 14 | # bumped for dbanydatecrack 15 | libsybdb_la_LDFLAGS= -version-info 6:0:1 $(FREETDS_SYMBOLIC) 16 | if !MACOSX 17 | libsybdb_la_LDFLAGS += -export-symbols-regex '^(db|bcp_|tdsdump_open|tdsdbopen|.*_xact|close_commit|open_commit|.?asprintf).*' 18 | endif 19 | libsybdb_la_LIBADD= ../tds/libtds.la ../replacements/libreplacements.la $(LTLIBICONV) $(FREETDS_LIBGCC) 20 | 21 | -------------------------------------------------------------------------------- /src/dblib/dbopen.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998-1999 Brian Bruns 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #ifdef dbopen 27 | #undef dbopen 28 | #endif 29 | 30 | /** 31 | * Normally not used. 32 | * The function is linked in only if the --enable-sybase-compat configure option is used. 33 | * Cf. sybdb.h dbopen() macros, and dbdatecrack(). 34 | */ 35 | DBPROCESS * 36 | dbopen(LOGINREC * login, const char *server) 37 | { 38 | return tdsdbopen(login, server, dblib_msdblib); 39 | } 40 | -------------------------------------------------------------------------------- /src/dblib/unittests/.gitignore: -------------------------------------------------------------------------------- 1 | t0001 2 | t0002 3 | t0003 4 | t0004 5 | t0005 6 | t0006 7 | t0007 8 | t0008 9 | t0009 10 | t0011 11 | t0012 12 | t0013 13 | t0013.out 14 | t0014 15 | t0014.out 16 | t0015 17 | t0016 18 | t0016.out 19 | t0017 20 | t0018 21 | t0019 22 | t0020 23 | t0021 24 | t0022 25 | tdsdump.out 26 | t0023 27 | t0016.err 28 | t0017.err 29 | t0017.out 30 | rpc 31 | dbmorecmds 32 | bcp 33 | thread 34 | text_buffer 35 | done_handling 36 | timeout 37 | hang 38 | null 39 | null2 40 | setnull 41 | numeric 42 | pending 43 | cancel 44 | spid 45 | -------------------------------------------------------------------------------- /src/dblib/unittests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(d_common STATIC common.c common.h) 2 | 3 | foreach(target t0001 t0002 t0003 t0004 t0005 t0006 t0007 t0008 t0009 4 | t0011 t0012 t0013 t0014 t0015 t0016 t0017 t0018 t0019 t0020 5 | t0021 t0022 t0023 rpc dbmorecmds bcp thread text_buffer 6 | done_handling timeout hang null null2 setnull numeric pending 7 | cancel) 8 | add_executable(d_${target} EXCLUDE_FROM_ALL ${target}.c) 9 | set_target_properties(d_${target} PROPERTIES OUTPUT_NAME ${target}) 10 | target_link_libraries(d_${target} d_common sybdb replacements ${lib_NETWORK} ${lib_BASE}) 11 | add_test(NAME d_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${target}) 12 | add_dependencies(check d_${target}) 13 | endforeach(target) 14 | -------------------------------------------------------------------------------- /src/dblib/unittests/README: -------------------------------------------------------------------------------- 1 | The programs in this directory test the db-lib routines. Tests 2 | that db-lib passes print "dblib okay for t000X.c" as the last line 3 | of output and exit with a status of 0. If the test does not print 4 | that message for the last line of output it means that db-lib failed 5 | that test. 6 | 7 | Some of the tests are designed to dump core if an error is detected. 8 | This is to assist with post-mortem debugging of the dblib routines. 9 | 10 | Run all tests with 'make check'. The test programs read the 11 | 'PWD' file in the root of the source tree to determine which 12 | server to run the tests on and which account to login as. 13 | 14 | You will want to modify PWD accordingly. 15 | 16 | All unit tests are expected to pass on all servers and all 17 | operating systems. -------------------------------------------------------------------------------- /src/dblib/unittests/cancel.sql: -------------------------------------------------------------------------------- 1 | select * from I_dont_exists_table 2 | go 3 | select 1 as one 4 | go 5 | -------------------------------------------------------------------------------- /src/dblib/unittests/data.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/src/dblib/unittests/data.bin -------------------------------------------------------------------------------- /src/dblib/unittests/dbmorecmds.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0024 (i int not null, s char(10) not null) 2 | go 3 | insert into #dblib0024 values (0, 'row 000') 4 | go 5 | insert into #dblib0024 values (1, 'row 001') 6 | go 7 | insert into #dblib0024 values (2, 'row 002') 8 | go 9 | insert into #dblib0024 values (3, 'row 003') 10 | go 11 | insert into #dblib0024 values (4, 'row 004') 12 | go 13 | insert into #dblib0024 values (5, 'row 005') 14 | go 15 | insert into #dblib0024 values (6, 'row 006') 16 | go 17 | insert into #dblib0024 values (7, 'row 007') 18 | go 19 | insert into #dblib0024 values (8, 'row 008') 20 | go 21 | insert into #dblib0024 values (9, 'row 009') 22 | go 23 | select count(*) from #dblib0024 -- order by i 24 | go 25 | select count(*) from sysusers 26 | select name from sysobjects compute count(name) 27 | go 28 | -------------------------------------------------------------------------------- /src/dblib/unittests/done_handling.sql: -------------------------------------------------------------------------------- 1 | create table #dummy (s char(10)) 2 | go 3 | insert into #dummy values('xxx') 4 | go 5 | if object_id('done_test') is not NULL drop proc done_test 6 | go 7 | create proc done_test @a varchar(10) output 8 | as 9 | select * from #dummy 10 | go 11 | if object_id('done_test2') is not NULL drop proc done_test2 12 | go 13 | create proc done_test2 14 | as 15 | select * from #dummy where s = 'aaa' 16 | select * from #dummy 17 | go 18 | select * from #dummy /* normal row */ 19 | go 20 | set nocount on 21 | go 22 | select * from #dummy /* normal row with no count */ 23 | go 24 | set nocount off 25 | go 26 | select * from #dummy where 0=1 /* normal row without rows */ 27 | go 28 | select dklghdlgkh from #dummy /* error query */ 29 | go 30 | /* stored procedure call with output parameters */ 31 | declare @s varchar(10) exec done_test @s output 32 | go 33 | exec done_test2 34 | go 35 | drop proc done_test 36 | go 37 | drop proc done_test2 38 | go 39 | -------------------------------------------------------------------------------- /src/dblib/unittests/numeric.sql: -------------------------------------------------------------------------------- 1 | IF OBJECT_ID('testDecimal') IS NOT NULL DROP PROC testDecimal 2 | go 3 | CREATE PROCEDURE testDecimal 4 | @idecimal NUMERIC(20,10) 5 | AS 6 | BEGIN 7 | SELECT CAST(@idecimal*2 AS NUMERIC(20,10)) 8 | END 9 | go 10 | IF OBJECT_ID('testDecimal') IS NOT NULL DROP PROC testDecimal 11 | go 12 | 13 | -------------------------------------------------------------------------------- /src/dblib/unittests/numeric_2.sql: -------------------------------------------------------------------------------- 1 | IF OBJECT_ID('testDecimal') IS NOT NULL DROP PROC testDecimal 2 | go 3 | CREATE PROCEDURE testDecimal 4 | @idecimal NUMERIC(20,10) 5 | AS 6 | BEGIN 7 | SELECT CAST(246 AS INTEGER) 8 | END 9 | go 10 | IF OBJECT_ID('testDecimal') IS NOT NULL DROP PROC testDecimal 11 | go 12 | 13 | -------------------------------------------------------------------------------- /src/dblib/unittests/pending.sql: -------------------------------------------------------------------------------- 1 | declare @a int 2 | select @a = 123 3 | begin transaction 4 | go 5 | /* The following statement should success */ 6 | select 634 as number 7 | go 8 | commit 9 | go 10 | 11 | -------------------------------------------------------------------------------- /src/dblib/unittests/spid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Purpose: Retrieve the connection SPID. 3 | * Functions: dbspid 4 | */ 5 | 6 | #include "common.h" 7 | 8 | int 9 | main(int argc, char **argv) 10 | { 11 | LOGINREC *login; 12 | DBPROCESS *dbproc; 13 | DBINT expected_spid, actual_spid; 14 | RETCODE erc; 15 | 16 | set_malloc_options(); 17 | 18 | read_login_info(argc, argv); 19 | 20 | printf("Starting %s\n", argv[0]); 21 | 22 | dbinit(); 23 | 24 | dberrhandle(syb_err_handler); 25 | dbmsghandle(syb_msg_handler); 26 | 27 | printf("About to logon as \"%s\"\n", USER); 28 | 29 | login = dblogin(); 30 | DBSETLPWD(login, PASSWORD); 31 | DBSETLUSER(login, USER); 32 | DBSETLAPP(login, "spid"); 33 | 34 | printf("About to open \"%s\"\n", SERVER); 35 | 36 | dbproc = dbopen(login, SERVER); 37 | if (!dbproc) { 38 | fprintf(stderr, "Unable to connect to %s\n", SERVER); 39 | return 1; 40 | } 41 | dbloginfree(login); 42 | 43 | printf("Using database \"%s\"\n", DATABASE); 44 | if (strlen(DATABASE)) { 45 | erc = dbuse(dbproc, DATABASE); 46 | assert(erc == SUCCEED); 47 | } 48 | 49 | #ifdef DBQUOTEDIDENT 50 | printf("QUOTED_IDENTIFIER is %s\n", (dbisopt(dbproc, DBQUOTEDIDENT, NULL))? "ON":"OFF"); 51 | #endif 52 | sql_cmd(dbproc); 53 | dbsqlexec(dbproc); 54 | 55 | if (dbresults(dbproc) != SUCCEED) { 56 | fprintf(stderr, "error: expected a result set, none returned.\n"); 57 | return 1; 58 | } 59 | 60 | if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & expected_spid)) { 61 | fprintf(stderr, "Had problem with bind\n"); 62 | return 1; 63 | } 64 | if (REG_ROW != dbnextrow(dbproc)) { 65 | fprintf(stderr, "Failed. Expected a row\n"); 66 | return 1; 67 | } 68 | assert(expected_spid > 0); 69 | 70 | actual_spid = dbspid(dbproc); 71 | if (expected_spid != actual_spid) { 72 | fprintf(stderr, "Failed. Expected spid to be %d, was %d\n", expected_spid, actual_spid); 73 | return 1; 74 | } 75 | 76 | if (dbnextrow(dbproc) != NO_MORE_ROWS) { 77 | fprintf(stderr, "Was expecting no more rows\n"); 78 | return 1; 79 | } 80 | 81 | dbclose(dbproc); 82 | 83 | dbexit(); 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /src/dblib/unittests/spid.sql: -------------------------------------------------------------------------------- 1 | select @@SPID 2 | go 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0007.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0007 (i int not null, s char(12) not null) 2 | go 3 | insert into #dblib0007 values (1, 'row 0000001') 4 | go 5 | insert into #dblib0007 values (2, 'row 0000002') 6 | go 7 | insert into #dblib0007 values (3, 'row 0000003') 8 | go 9 | insert into #dblib0007 values (4, 'row 0000004') 10 | go 11 | insert into #dblib0007 values (5, 'row 0000005') 12 | go 13 | insert into #dblib0007 values (6, 'row 0000006') 14 | go 15 | insert into #dblib0007 values (7, 'row 0000007') 16 | go 17 | insert into #dblib0007 values (8, 'row 0000008') 18 | go 19 | insert into #dblib0007 values (9, 'row 0000009') 20 | go 21 | select * from #dblib0007 where i<=5 order by i 22 | go 23 | /* 24 | * Second select, should fail: expected_error = 20019 25 | */ 26 | select * from #dblib0007 where i>=5 order by i 27 | go 28 | /* 29 | * Third select for binary bindings 30 | */ 31 | select i, s, i from #dblib0007 x where x.i<=5 order by x.i 32 | go 33 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0009.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0009 (i int not null, s char(10) not null) 2 | go 3 | insert into #dblib0009 values (1, 'abcdef') 4 | go 5 | insert into #dblib0009 values (2, 'abc') 6 | go 7 | select * from #dblib0009 order by i 8 | go 9 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0011.sql: -------------------------------------------------------------------------------- 1 | drop table #dblib0011 2 | go 3 | create table #dblib0011 (i int not null, c1 char(200) not null, c2 char(200) null, vc varchar(200) null) 4 | go 5 | insert into #dblib0011 values (1, 'This is a really long column to ensure that the next row ends properly.','This is a really long column to ensure that the next row ends properly.','This is a really long column to ensure that the next row ends properly.') 6 | go 7 | insert into #dblib0011 values (2, 'Short column','Short column','Short column') 8 | go 9 | insert into #dblib0011 values (3, 'Short column',NULL,NULL) 10 | go 11 | select * from #dblib0011 order by i 12 | go 13 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0012.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0012 (dt datetime not null) 2 | go 3 | insert into #dblib0012 values ('Feb 27 2001 10:24:35:056AM') 4 | go 5 | insert into #dblib0012 values ('Dec 25 1898 07:30:00:567PM') 6 | go 7 | SELECT dt FROM #dblib0012 8 | go 9 | SELECT CAST('1898-12-25 16:00:00.567 -08:00' AS DATETIMEOFFSET) 10 | go 11 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0013.sql: -------------------------------------------------------------------------------- 1 | if object_id('freetds_dblib_t0013') is not null drop table freetds_dblib_t0013 2 | go 3 | create table freetds_dblib_t0013 (i int not null, PigTure image not null) 4 | go 5 | insert into freetds_dblib_t0013 values (1, '') 6 | go 7 | SELECT PigTure FROM freetds_dblib_t0013 WHERE i = 1 8 | go 9 | select i, PigTure from freetds_dblib_t0013 order by i 10 | go 11 | SET TEXTSIZE 2147483647 12 | go 13 | SELECT PigTure FROM freetds_dblib_t0013 WHERE i = 1 14 | go 15 | drop table freetds_dblib_t0013 16 | go 17 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0014.sql: -------------------------------------------------------------------------------- 1 | if object_id('dblib0014') is not null drop table dblib0014 2 | go 3 | create table dblib0014 (i int not null, PigTure image not null) 4 | go 5 | insert into dblib0014 values (0, '') 6 | go 7 | insert into dblib0014 values (1, '') 8 | go 9 | insert into dblib0014 values (2, '') 10 | go 11 | SELECT PigTure FROM dblib0014 WHERE i = 0 12 | go 13 | SELECT PigTure FROM dblib0014 WHERE i = 1 14 | go 15 | SELECT PigTure FROM dblib0014 WHERE i = 2 16 | go 17 | select * from dblib0014 order by i 18 | go 19 | drop table dblib0014 20 | go 21 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016.in: -------------------------------------------------------------------------------- 1 | 1 2 123.45 This is a varchar 255 field 2001-09-11 09:13:13.663 group1 2 | 4 5 56789.12 This is another varchar 255 field 2000-02-29 13:01:01.000 group2 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (f1 int not null, s1 int null, f2 numeric(10,2) null, f3 varchar(255) not null, f4 datetime null, [group] varchar(20)) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | 10 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_1.in: -------------------------------------------------------------------------------- 1 | 1 攢ðŋ 47C9B7E7-7AD6-4EE5-B29B-D81569251E8B 2 | 4 ciao2 82E8E9A8-61D3-424E-9AB5-AFD38CC41E36 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_1.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (f1 int not null, str nvarchar(5), uuid uniqueidentifier) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | 10 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_10.sql: -------------------------------------------------------------------------------- 1 | set textsize 65536 2 | create table #dblib0016 (id int not null, data image) 3 | go 4 | select * from #dblib0016 where 0=1 5 | go 6 | select * from #dblib0016 where 0=1 7 | go 8 | drop table #dblib0016 9 | go 10 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_11.in: -------------------------------------------------------------------------------- 1 | 1 00 2 | 2 a b 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_11.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (id int not null, var uniqueidentifier null, c1 char(20) not null, v1 varchar(20) not null, c2 char(20) null, v2 varchar(20) null, b1 binary(20) null, vb1 varbinary(20) null, img image null, txt text null) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_2.in: -------------------------------------------------------------------------------- 1 | 1 This is a text 255 field varchar 1 2 | 4 This is another text 255 field. I'm trying to get a quite long string. This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! This is the first bcp text test! varcharX 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_2.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (f1 int not null, f2 text, f3 varchar(20) ) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | 10 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_3.in: -------------------------------------------------------------------------------- 1 | 1 Just a char 01020304 2 | 2 Other test 89abcdef 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_3.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (f1 int not null, f2 char(20) not null, f3 binary(4) not null) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | 10 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_4.in: -------------------------------------------------------------------------------- 1 | 1 Just a char 01020304 2 | 2 Other test 89abcdef 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_4.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (f1 int not null, f2 char(20) null, f3 binary(4) null) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | 10 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_5.in: -------------------------------------------------------------------------------- 1 | 1 test very very very long varchar 1 test very very very long varchar 2 test very very very long varchar 3 test very very very long varchar 4 test very very very long varchar 5 test very very very long varchar 6 test very very very long varchar 7 test very very very long varchar 8 test very very very long varchar 9 test very very very long varchar 10 test very very very long varchar 11 test very very very long varchar 12 test very very very long varchar 13 test very very very long varchar 14 test very very very long varchar 15 test very very very long varchar 16 test very very very long varchar 17 test very very very long varchar 18 test very very very long varchar 19 test very very very long varchar 20 2 | 3 test very very very long varchar 1 test very very very long varchar 2 test very very very long varchar 3 test very very very long varchar 4 test very very very long varchar 5 test very very very long varchar 6 test very very very long varchar 7 x x x x x x x x x x x x x 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_5.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (f0 int not null, f1 varchar(60) not null, f2 varchar(60) not null, f3 varchar(60) not null, f4 varchar(60) not null, f5 varchar(60) not null, f6 varchar(60) not null, f7 varchar(60) not null, f8 varchar(60) not null, f9 varchar(60) not null, f10 varchar(60) not null, f11 varchar(60) not null, f12 varchar(60) not null, f13 varchar(60) not null, f14 varchar(60) not null, f15 varchar(60) not null, f16 varchar(60) not null, f17 varchar(60) not null, f18 varchar(60) not null, f19 varchar(60) not null, f20 varchar(60) not null) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_6.in: -------------------------------------------------------------------------------- 1 | 2014-04-15 20:23:45.123 2 | 2038-11-27 04:12:32.876 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_6.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (f0 datetime2(3) not null) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_7.in: -------------------------------------------------------------------------------- 1 | 1 0 1234 1 0 2 | 0 1 7654 0 1 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_7.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (b1 bit, b2 bit, i1 int not null, b3 bit, b4 bit) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_8.in: -------------------------------------------------------------------------------- 1 | 1 0 1 0 2 | 0 1 1 0 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_8.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0016 (b1 bit, b2 bit, b3 bit, b4 bit) 2 | go 3 | select * from #dblib0016 where 0=1 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | drop table #dblib0016 8 | go 9 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_9.in: -------------------------------------------------------------------------------- 1 | 1 0 1 0 1 0 1 0 123456 1 2 | 0 1 1 0 0 1 1 0 8765432 1 3 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0016_9.sql: -------------------------------------------------------------------------------- 1 | -- check if bit are all collased together, the layout will be 2 | -- 8 bits (b1-b8), i1, 1 bit (b9) -> 6 bytes 3 | create table #dblib0016 (b1 bit, b2 bit, b3 bit, b4 bit, b5 bit, b6 bit, b7 bit, b8 bit, i1 int not null, b9 bit) 4 | go 5 | select * from #dblib0016 where 0=1 6 | go 7 | select * from #dblib0016 where 0=1 8 | go 9 | drop table #dblib0016 10 | go 11 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0017.in: -------------------------------------------------------------------------------- 1 | "3DEprova di testo questo testo dovrebbe andare a finire in un campo text -------------------------------------------------------------------------------- /src/dblib/unittests/t0017.in.be: -------------------------------------------------------------------------------- 1 | D3"Eprova di testo questo testo dovrebbe andare a finire in un campo text -------------------------------------------------------------------------------- /src/dblib/unittests/t0017.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0017 (c1 int null, c2 text) 2 | go 3 | insert into #dblib0017(c1,c2) values(1144201745,'prova di testo questo testo dovrebbe andare a finire in un campo text') 4 | go 5 | select * from #dblib0017 where 0=1 6 | go 7 | delete from #dblib0017 8 | go 9 | select * from #dblib0017 where 0=1 10 | go 11 | SET NOCOUNT ON DECLARE @n INT SELECT @n = COUNT(*) FROM #dblib0017 WHERE c1=1144201745 AND c2 LIKE 'prova di testo questo testo dovrebbe andare a finire in un campo text' IF @n <> 1 SELECT 0 12 | go 13 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0020.sql: -------------------------------------------------------------------------------- 1 | /* request an invalid column from a non-existent table */ 2 | select dsjfkl dsjf 3 | go 4 | select db_name() 5 | go 6 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0021.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Purpose: Test dbsafestr() 3 | * Functions: dbsafestr 4 | */ 5 | 6 | #include "common.h" 7 | 8 | static char software_version[] = "$Id: t0021.c,v 1.15 2009-03-19 13:11:41 freddy77 Exp $"; 9 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 10 | 11 | #ifndef DBNTWIN32 12 | 13 | int failed = 0; 14 | 15 | /* unsafestr must contain one quote of each type */ 16 | const char *unsafestr = "This is a string with ' and \" in it."; 17 | 18 | /* safestr must be at least strlen(unsafestr) + 3 */ 19 | char safestr[100]; 20 | 21 | int 22 | main(int argc, char **argv) 23 | { 24 | int len; 25 | RETCODE ret; 26 | 27 | set_malloc_options(); 28 | 29 | fprintf(stdout, "Starting %s\n", argv[0]); 30 | 31 | /* Fortify_EnterScope(); */ 32 | dbinit(); 33 | 34 | 35 | len = strlen(unsafestr); 36 | ret = dbsafestr(NULL, unsafestr, -1, safestr, len, DBSINGLE); 37 | if (ret != FAIL) 38 | failed++; 39 | fprintf(stdout, "short buffer, single\n%s\n", safestr); 40 | /* plus one for termination and one for the quote */ 41 | ret = dbsafestr(NULL, unsafestr, -1, safestr, len + 2, DBSINGLE); 42 | if (ret != SUCCEED) 43 | failed++; 44 | if (strlen(safestr) != len + 1) 45 | failed++; 46 | fprintf(stdout, "single quote\n%s\n", safestr); 47 | ret = dbsafestr(NULL, unsafestr, -1, safestr, len + 2, DBDOUBLE); 48 | if (ret != SUCCEED) 49 | failed++; 50 | if (strlen(safestr) != len + 1) 51 | failed++; 52 | fprintf(stdout, "double quote\n%s\n", safestr); 53 | ret = dbsafestr(NULL, unsafestr, -1, safestr, len + 3, DBBOTH); 54 | if (ret != SUCCEED) 55 | failed++; 56 | if (strlen(safestr) != len + 2) 57 | failed++; 58 | fprintf(stdout, "both quotes\n%s\n", safestr); 59 | 60 | dbexit(); 61 | 62 | fprintf(stdout, "%s %s\n", __FILE__, (failed ? "failed!" : "OK")); 63 | return failed ? 1 : 0; 64 | } 65 | #else 66 | int main(void) 67 | { 68 | fprintf(stderr, "Not supported by MS DBLib\n"); 69 | return 0; 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0022.sql: -------------------------------------------------------------------------------- 1 | if object_id('t0022') is not null drop proc t0022 2 | go 3 | create proc t0022 (@b int out) as 4 | begin 5 | select @b = 42 6 | return 66 7 | end 8 | go 9 | declare @b int 10 | exec t0022 @b = @b output 11 | go 12 | drop proc t0022 13 | go 14 | if object_id('t0022a') is not null drop proc t0022a 15 | go 16 | create proc t0022a (@b int) as 17 | return @b 18 | go 19 | exec t0022a 17 20 | exec t0022a 1024 21 | go 22 | drop proc t0022a 23 | go 24 | -------------------------------------------------------------------------------- /src/dblib/unittests/t0023.sql: -------------------------------------------------------------------------------- 1 | create table #dblib0023 (col1 int not null, col2 char(1) not null, col3 datetime not null) 2 | go 3 | insert into #dblib0023 values (1, 'A', 'Jan 1 2002 10:00:00AM') 4 | go 5 | insert into #dblib0023 values (2, 'A', 'Jan 2 2002 10:00:00AM') 6 | go 7 | insert into #dblib0023 values (3, 'A', 'Jan 3 2002 10:00:00AM') 8 | go 9 | insert into #dblib0023 values (8, 'B', 'Jan 4 2002 10:00:00AM') 10 | go 11 | insert into #dblib0023 values (9, 'B', 'Jan 5 2002 10:00:00AM') 12 | go 13 | select col1, col2, col3 from #dblib0023 order by col2 compute sum(col1) by col2 compute max(col3) 14 | go 15 | -------------------------------------------------------------------------------- /src/dblib/unittests/text_buffer.sql: -------------------------------------------------------------------------------- 1 | create table #dblib (i int not null, s text) 2 | go 3 | insert into #dblib values (1, 'ABCDEF') 4 | go 5 | insert into #dblib values (2, 'abc') 6 | go 7 | select * from #dblib order by i 8 | go 9 | -------------------------------------------------------------------------------- /src/dblib/unittests/timeout.sql: -------------------------------------------------------------------------------- 1 | select getdate() as 'begintime' waitfor delay '00:00:30' select getdate() as 'endtime' 2 | go 3 | -------------------------------------------------------------------------------- /src/dblib/winmain.c: -------------------------------------------------------------------------------- 1 | #include "../../win32/initnet.c" 2 | -------------------------------------------------------------------------------- /src/odbc/.gitignore: -------------------------------------------------------------------------------- 1 | odbc_export.h 2 | error_export.h 3 | version.rc 4 | setup.res 5 | -------------------------------------------------------------------------------- /src/odbc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(unittests) 2 | 3 | # TODO checks 4 | add_definitions(-DUNIXODBC -DHAVE_SQLGETPRIVATEPROFILESTRING -DDLL_EXPORT) 5 | 6 | if(PERL_FOUND AND NOT EXISTS "${CMAKE_SOURCE_DIR}/configure") 7 | add_custom_command(OUTPUT odbc_export.h 8 | COMMAND ${PERL_EXECUTABLE} odbc_export.pl odbc.c > odbc_export.h 9 | MAIN_DEPENDENCY odbc_export.pl 10 | DEPENDS odbc.c 11 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) 12 | add_custom_command(OUTPUT error_export.h 13 | COMMAND ${PERL_EXECUTABLE} odbc_export.pl error.c > error_export.h 14 | MAIN_DEPENDENCY odbc_export.pl 15 | DEPENDS error.c 16 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) 17 | endif(PERL_FOUND AND NOT EXISTS "${CMAKE_SOURCE_DIR}/configure") 18 | 19 | if(WIN32) 20 | set(win_SRCS winlogin.c winsetup.c winmain.c odbc_w.def setup.rc) 21 | endif() 22 | set(libs ${lib_ODBCINST}) 23 | 24 | add_library(tdsodbc SHARED 25 | odbc.c connectparams.c convert_tds2sql.c 26 | descriptor.c prepare_query.c odbc_util.c bcp.c 27 | native.c sql2tds.c error.c odbc_checks.c sqlwchar.c sqlwparams.h 28 | odbc_export.h error_export.h odbc_data.c ${win_SRCS} 29 | ) 30 | # TODO libiconv, odbcinstlib and other dynamics 31 | target_link_libraries(tdsodbc tds replacements ${libs} ${lib_NETWORK} ${lib_BASE}) 32 | 33 | if(MINGW OR CYGWIN) 34 | set_target_properties(tdsodbc PROPERTIES LINK_FLAGS "--static -Wl,--kill-at -Wl,--enable-stdcall-fixup") 35 | endif(MINGW OR CYGWIN) 36 | -------------------------------------------------------------------------------- /src/odbc/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am,v 1.52 2012-02-26 22:09:20 freddy77 Exp $ 2 | SUBDIRS = . unittests 3 | AM_CPPFLAGS = -I$(top_srcdir)/include $(ODBC_INC) 4 | 5 | lib_LTLIBRARIES = libtdsodbc.la 6 | ##EXTRA_LTLIBRARIES = libtdsodbc.la 7 | libtdsodbc_la_SOURCES = odbc.c connectparams.c convert_tds2sql.c \ 8 | descriptor.c prepare_query.c odbc_util.c bcp.c \ 9 | native.c sql2tds.c error.c odbc_checks.c sqlwchar.c sqlwparams.h \ 10 | odbc_export.h error_export.h odbc_data.c 11 | libtdsodbc_la_LIBADD = ../tds/libtds.la ../replacements/libreplacements.la $(ODBCINSTLIB) $(LTLIBICONV) $(FREETDS_LIBGCC) 12 | # -module is needed by Darwin (Mac OS X) 13 | libtdsodbc_la_LDFLAGS = $(FREETDS_SYMBOLIC) $(FREETDS_ODBC_MODULE) 14 | 15 | if MINGW32 16 | libtdsodbc_la_SOURCES += winlogin.c winsetup.c winmain.c 17 | endif 18 | 19 | if MINGW32 20 | libtdsodbc_la_LIBADD += setup.res 21 | libtdsodbc_la_LDFLAGS += -Wl,--kill-at -Wl,--enable-stdcall-fixup -Wl,-s -Wl,odbc_w.def -Wl,setup.res 22 | 23 | .rc.res: 24 | $(RC) -i $< --input-format=rc -o $@ -O coff 25 | else 26 | if !MACOSX 27 | libtdsodbc_la_LDFLAGS += -export-symbols-regex '^(SQL|ODBCINST).*' 28 | endif 29 | endif 30 | 31 | EXTRA_DIST = CMakeLists.txt winmain.c winlogin.c winsetup.c \ 32 | version.rc version.rc.in setup.rc resource.h \ 33 | odbc.def odbc_w.def 34 | CLEANFILES = setup.res 35 | 36 | ## Need blank statement to avoid compiling odbc.c 37 | odbc: $(EXTRA_LTLIBRARIES) 38 | @echo '' 39 | 40 | if HAVE_PERL_SOURCES 41 | BUILT_SOURCES = odbc_export.h error_export.h 42 | 43 | clean-local: 44 | cd $(srcdir) && rm -f $(BUILT_SOURCES) 45 | 46 | odbc_export.h: odbc_export.pl Makefile odbc.c 47 | perl $(srcdir)/odbc_export.pl $(srcdir)/odbc.c > $@.tmp 48 | mv $@.tmp $@ 49 | 50 | error_export.h: odbc_export.pl Makefile error.c 51 | perl $(srcdir)/odbc_export.pl $(srcdir)/error.c > $@.tmp 52 | mv $@.tmp $@ 53 | 54 | endif 55 | -------------------------------------------------------------------------------- /src/odbc/checkexport.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | EXP="nm .libs/libtdsodbc.so | grep ' T ' | sed 's,.* T ,,g'" 4 | 5 | echo Function not exported by VMS driver 6 | (eval "$EXP" | grep '^\(SQL\|ODBC\)'; cat ../../vms/odbc_driver_axp.opt | grep -v '^!' | grep 'SQL' | sed 's,.*SQL\(.*\)=PROCEDURE.*,SQL\1,g') | sort | uniq -u | grep -v ODBCINSTGetProperties 7 | 8 | echo Function not exported by odbc driver 9 | (eval "$EXP" | grep '^\(SQL\|ODBC\)'; cat odbc_w.def | grep -v '^;' | grep 'SQL' | sed 's,.*SQL,SQL,g' | perl -pe 's,\r,,g') | sort | uniq -u | grep -v ODBCINSTGetProperties 10 | 11 | echo Function not declared as implemented 12 | (eval "$EXP" | grep '^SQL' | grep -v '[a-z]W$' | perl -pe 'tr/a-z/A-Z/'; cat odbc.c | grep 'X(SQL_API_' | sed 's,.*SQL_API_SQL,SQL,g; s,).*,,g' | sort | uniq) | sort | uniq -u 13 | (eval "$EXP" | grep '^SQL' | grep -v '[a-z]W$' | perl -pe 'tr/a-z/A-Z/'; cat odbc.c | grep '_(SQL_API_' | sed 's,.*SQL_API_SQL,SQL,g; s,).*,,g' | sort | uniq) | sort | uniq -d 14 | 15 | echo 16 | echo "DBLIB" 17 | cd ../dblib 18 | EXP="nm .libs/libsybdb.so | grep ' T ' | sed 's,.* T ,,g'" 19 | (eval "$EXP"; cat dblib.def | perl -pe 's,\r,,g; s,^\s+,,; s,^\n,,s; s,^EXPORTS\n,,s') | sort | uniq -u 20 | 21 | 22 | echo 23 | echo "Ctlib" 24 | cd ../ctlib 25 | EXP="nm .libs/libct.so | grep ' T ' | sed 's,.* T ,,g'" 26 | (eval "$EXP"; cat ctlib.def | perl -pe 's,\r,,g; s,^\s+,,; s,^\n,,s; s,^EXPORTS\n,,s') | sort | uniq -u 27 | -------------------------------------------------------------------------------- /src/odbc/odbc.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | SQLAllocConnect 3 | SQLAllocEnv 4 | SQLAllocHandle 5 | SQLAllocStmt 6 | SQLBindCol 7 | SQLBindParam 8 | SQLBindParameter 9 | ; SQLBrowseConnect 10 | SQLCancel 11 | SQLCloseCursor 12 | SQLColAttribute 13 | SQLColAttributes 14 | SQLColumnPrivileges 15 | SQLColumns 16 | SQLConnect 17 | SQLCopyDesc 18 | SQLDescribeCol 19 | ; SQLDescribeParam 20 | SQLDisconnect 21 | SQLDriverConnect 22 | SQLEndTran 23 | SQLError 24 | SQLExecDirect 25 | SQLExecute 26 | SQLExtendedFetch 27 | SQLFetch 28 | SQLFetchScroll 29 | SQLForeignKeys 30 | SQLFreeConnect 31 | SQLFreeEnv 32 | SQLFreeHandle 33 | SQLFreeStmt 34 | SQLGetConnectAttr 35 | SQLGetConnectOption 36 | SQLGetCursorName 37 | SQLGetData 38 | SQLGetDescField 39 | SQLGetDescRec 40 | SQLGetDiagField 41 | SQLGetDiagRec 42 | SQLGetEnvAttr 43 | SQLGetFunctions 44 | SQLGetInfo 45 | SQLGetStmtAttr 46 | SQLGetStmtOption 47 | SQLGetTypeInfo 48 | SQLMoreResults 49 | SQLNativeSql 50 | SQLNumParams 51 | SQLNumResultCols 52 | SQLParamData 53 | SQLParamOptions 54 | SQLPrepare 55 | SQLPrimaryKeys 56 | SQLProcedureColumns 57 | SQLProcedures 58 | SQLPutData 59 | SQLRowCount 60 | SQLSetConnectAttr 61 | SQLSetConnectOption 62 | SQLSetCursorName 63 | SQLSetDescField 64 | SQLSetDescRec 65 | SQLSetEnvAttr 66 | SQLSetParam 67 | SQLSetPos 68 | SQLSetScrollOptions 69 | SQLSetStmtAttr 70 | SQLSetStmtOption 71 | SQLSpecialColumns 72 | SQLStatistics 73 | SQLTablePrivileges 74 | SQLTables 75 | SQLTransact 76 | ConfigDSN 77 | ConfigDriver 78 | ConfigTranslator 79 | bcp_initA = win_bcp_initA 80 | bcp_control = win_bcp_control 81 | bcp_colptr = win_bcp_colptr 82 | bcp_sendrow = win_bcp_sendrow 83 | bcp_batch = win_bcp_batch 84 | bcp_done = win_bcp_done 85 | bcp_bind = win_bcp_bind 86 | DllRegisterServer PRIVATE 87 | DllUnregisterServer PRIVATE 88 | SQLGetTypeInfoW = SQLGetTypeInfo 89 | 90 | -------------------------------------------------------------------------------- /src/odbc/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by setup.rc 4 | // 5 | #define IDD_LOGIN 102 6 | #define IDD_DSN 106 7 | #define IDC_PROTOCOL 1003 8 | #define IDC_ADDRESS 1004 9 | #define IDC_PORT 1005 10 | #define IDC_DATABASE 1011 11 | #define IDC_DSNNAME 1015 12 | #define IDC_HINT 1017 13 | #define IDC_LOGINSERVER 1020 14 | #define IDC_LOGINUID 1021 15 | #define IDC_LOGINPWD 1022 16 | #define IDC_LOGINDUMP 1023 17 | 18 | // Next default values for new objects 19 | // 20 | #ifdef APSTUDIO_INVOKED 21 | #ifndef APSTUDIO_READONLY_SYMBOLS 22 | #define _APS_NEXT_RESOURCE_VALUE 103 23 | #define _APS_NEXT_COMMAND_VALUE 40001 24 | #define _APS_NEXT_CONTROL_VALUE 1024 25 | #define _APS_NEXT_SYMED_VALUE 101 26 | #endif 27 | #endif 28 | -------------------------------------------------------------------------------- /src/odbc/sqlwparams.h: -------------------------------------------------------------------------------- 1 | #if 0 2 | # ODBC_FUNC(SQLTest, (P(SQLSMALLINT, x), PCHAR(y) WIDE)) 3 | #endif 4 | 5 | #undef WIDE 6 | #undef P 7 | #undef PCHAR 8 | #undef PCHARIN 9 | #undef PCHAROUT 10 | 11 | #ifdef ENABLE_ODBC_WIDE 12 | # define WIDE , int wide 13 | # define PCHAR(a) ODBC_CHAR* a 14 | #else 15 | # define WIDE 16 | # define PCHAR(a) SQLCHAR* a 17 | #endif 18 | 19 | #define P(a,b) a b 20 | #define PCHARIN(n,t) PCHAR(sz ## n), P(t, cb ## n) 21 | #define PCHAROUT(n,t) PCHAR(sz ## n), P(t, cb ## n ## Max), P(t FAR*, pcb ## n) 22 | 23 | #define ODBC_FUNC(name, params) \ 24 | static SQLRETURN _ ## name params 25 | 26 | -------------------------------------------------------------------------------- /src/odbc/unittests/.gitignore: -------------------------------------------------------------------------------- 1 | t0001 2 | t0002 3 | t0003 4 | t0004 5 | tdsdump.out 6 | connect 7 | print 8 | date 9 | norowset 10 | funccall 11 | lang_error 12 | tables 13 | binary_test 14 | moreandcount 15 | earlybind 16 | putdata 17 | params 18 | raiserror 19 | getdata 20 | type 21 | genparams 22 | transaction 23 | preperror 24 | odbc.ini 25 | odbcinst.ini 26 | prepare_results 27 | data 28 | testodbc 29 | error 30 | rebindpar 31 | convert_error 32 | typeinfo 33 | const_params 34 | compute 35 | insert_speed 36 | timeout 37 | array 38 | array_out 39 | cursor1 40 | cursor2 41 | scroll 42 | describecol 43 | copydesc 44 | msvc.mak 45 | prepclose 46 | warning 47 | paramcore 48 | rpc 49 | timeout2 50 | timeout3 51 | connect2 52 | timeout4 53 | freeclose 54 | cursor3 55 | cursor4 56 | cursor5 57 | cursor6 58 | cursor7 59 | attributes 60 | hidden 61 | blob1 62 | rowset 63 | cancel 64 | test64 65 | wchar 66 | transaction2 67 | utf8 68 | utf8_2 69 | stats 70 | descrec 71 | peter 72 | prepare_warn 73 | long_error 74 | mars1 75 | array_error 76 | describecol2 77 | closestmt 78 | oldpwd 79 | bcp 80 | -------------------------------------------------------------------------------- /src/odbc/unittests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(..) 2 | 3 | set(tests 4 | t0001 t0002 t0003 5 | t0004 connect print 6 | date norowset funccall 7 | lang_error tables 8 | binary_test moreandcount 9 | earlybind putdata params 10 | raiserror getdata 11 | transaction type genparams 12 | preperror prepare_results 13 | testodbc data error 14 | rebindpar rpc convert_error 15 | typeinfo const_params 16 | insert_speed compute 17 | timeout array array_out 18 | cursor1 scroll cursor2 19 | describecol copydesc 20 | prepclose warning 21 | paramcore timeout2 timeout3 22 | connect2 timeout4 freeclose 23 | cursor3 cursor4 cursor5 24 | attributes hidden blob1 25 | cancel wchar rowset transaction2 26 | cursor6 cursor7 utf8 utf8_2 27 | stats descrec peter test64 28 | prepare_warn long_error mars1 29 | array_error closestmt 30 | ) 31 | 32 | if(WIN32) 33 | set(libs odbc32 ${lib_ODBCINST}) 34 | else() 35 | set(libs tdsodbc ${lib_ODBCINST}) 36 | endif() 37 | 38 | add_library(o_common STATIC common.c common.h c2string.c parser.c parser.h) 39 | 40 | foreach(target ${tests}) 41 | add_executable(o_${target} EXCLUDE_FROM_ALL ${target}.c) 42 | set_target_properties(o_${target} PROPERTIES OUTPUT_NAME ${target}) 43 | target_link_libraries(o_${target} o_common replacements ${libs} ${lib_NETWORK} ${lib_BASE}) 44 | add_test(NAME o_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${target}) 45 | add_dependencies(check o_${target}) 46 | endforeach(target) 47 | -------------------------------------------------------------------------------- /src/odbc/unittests/array_error.c: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include "common.h" 3 | #include 4 | 5 | /* 6 | Test for a bug executing after a not successfully execute 7 | */ 8 | 9 | int 10 | main(int argc, char *argv[]) 11 | { 12 | SQLSMALLINT num_params; 13 | SQLLEN sql_nts = SQL_NTS; 14 | char string[20]; 15 | SQLINTEGER id; 16 | 17 | odbc_use_version3 = 1; 18 | odbc_connect(); 19 | 20 | odbc_command("create table #tester (id int not null primary key, name varchar(20) not null)"); 21 | odbc_command("insert into #tester(id, name) values(1, 'abc')"); 22 | odbc_command("insert into #tester(id, name) values(2, 'duck')"); 23 | 24 | odbc_reset_statement(); 25 | 26 | CHKPrepare(T("insert into #tester(id, name) values(?,?)"), SQL_NTS, "S"); 27 | 28 | CHKR(SQLNumParams, (odbc_stmt, &num_params), "S"); 29 | assert(num_params == 2); 30 | 31 | /* now this is going to fail as id is duplicated, causing statement to not be prepared */ 32 | id = 1; 33 | CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &id, 0, &sql_nts, "S"); 34 | strcpy(string, "test"); 35 | CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(string), 0, string, 0, &sql_nts, "S"); 36 | CHKExecute("E"); 37 | 38 | /* this should success */ 39 | id = 4; 40 | strcpy(string, "test2"); 41 | CHKExecute("S"); 42 | 43 | odbc_disconnect(); 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/odbc/unittests/attributes.in: -------------------------------------------------------------------------------- 1 | # some cursor attributes 2 | odbc 3 3 | reset 4 | 5 | attr SQL_ATTR_CURSOR_TYPE SQL_CURSOR_FORWARD_ONLY 6 | attr SQL_ATTR_CURSOR_SCROLLABLE SQL_NONSCROLLABLE 7 | attr SQL_ATTR_CONCURRENCY SQL_CONCUR_READ_ONLY 8 | attr SQL_ATTR_CURSOR_SENSITIVITY SQL_INSENSITIVE 9 | 10 | set SQL_ATTR_CURSOR_SENSITIVITY SQL_SENSITIVE 11 | 12 | attr SQL_ATTR_CURSOR_TYPE SQL_CURSOR_FORWARD_ONLY 13 | attr SQL_ATTR_CURSOR_SCROLLABLE SQL_NONSCROLLABLE 14 | attr SQL_ATTR_CONCURRENCY SQL_CONCUR_ROWVER 15 | attr SQL_ATTR_CURSOR_SENSITIVITY SQL_SENSITIVE 16 | -------------------------------------------------------------------------------- /src/odbc/unittests/base.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* TODO place comment here */ 4 | 5 | int 6 | main(int argc, char *argv[]) 7 | { 8 | /* TODO remove if not neeeded */ 9 | odbc_use_version3 = 1; 10 | odbc_connect(); 11 | 12 | /* TODO write your test */ 13 | 14 | odbc_disconnect(); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/odbc/unittests/closestmt.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* 4 | * This test attempt to test if closing a statement with prepared query 5 | * success if there are a pending query on the same connection from 6 | * another statement. 7 | */ 8 | 9 | #define SWAP_STMT(b) do { SQLHSTMT xyz = odbc_stmt; odbc_stmt = b; b = xyz; } while(0) 10 | 11 | int 12 | main(int argc, char *argv[]) 13 | { 14 | char sql[128]; 15 | int i; 16 | SQLHSTMT stmt; 17 | SQLINTEGER num; 18 | 19 | odbc_use_version3 = 1; 20 | odbc_connect(); 21 | 22 | /* create a table with some rows */ 23 | odbc_command("create table #tmp (i int, c varchar(100))"); 24 | odbc_command("insert into #tmp values(1, 'some data')"); 25 | for (i = 0; i < 8; ++i) { 26 | sprintf(sql, "insert into #tmp select i+%d, c from #tmp where i <= %d", 1 << i, 1 << i); 27 | odbc_command(sql); 28 | } 29 | 30 | /* execute a prepared query on the connection and get all rows */ 31 | CHKPrepare(T("select i from #tmp where i < ?"), SQL_NTS, "S"); 32 | 33 | num = 5; 34 | CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &num, 0, NULL, "S"); 35 | 36 | CHKExecute("S"); 37 | 38 | for (i = 1; i < 5; ++i) 39 | CHKFetch("S"); 40 | CHKFetch("No"); 41 | CHKMoreResults("No"); 42 | 43 | /* start getting some data from another statement */ 44 | CHKAllocStmt(&stmt, "S"); 45 | SWAP_STMT(stmt); 46 | 47 | CHKExecDirect(T("select * from #tmp"), SQL_NTS, "S"); 48 | 49 | /* close first statement with data pending on second */ 50 | SWAP_STMT(stmt); 51 | CHKFreeStmt(SQL_DROP, "S"); 52 | 53 | SWAP_STMT(stmt); 54 | odbc_disconnect(); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /src/odbc/unittests/convert_error.c: -------------------------------------------------------------------------------- 1 | /* 2 | * test SQLBindParameter with text and Sybase 3 | * test from Keith Woodard (bug #885122) 4 | */ 5 | #include "common.h" 6 | 7 | static char software_version[] = "$Id: convert_error.c,v 1.12 2011-07-12 10:16:59 freddy77 Exp $"; 8 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 9 | 10 | static int test_num = 0; 11 | 12 | static void 13 | Test(const char *bind1, SQLSMALLINT type1, const char *bind2, SQLSMALLINT type2) 14 | { 15 | char sql[512]; 16 | char *val = "test"; 17 | SQLLEN ind = 4; 18 | int id = 1; 19 | ODBC_BUF *odbc_buf = NULL; 20 | 21 | SQLFreeStmt(odbc_stmt, SQL_RESET_PARAMS); 22 | 23 | ++test_num; 24 | sprintf(sql, "insert into #test_output values (%s, %s)", bind1, bind2); 25 | 26 | CHKPrepare(T(sql), strlen(sql), "S"); 27 | if (bind1[0] == '?') 28 | CHKBindParameter(id++, SQL_PARAM_INPUT, SQL_C_LONG, type1, 3, 0, &test_num, 0, &ind, "S"); 29 | if (bind2[0] == '?') 30 | CHKBindParameter(id++, SQL_PARAM_INPUT, SQL_C_CHAR, type2, strlen(val) + 1, 0, (SQLCHAR *) val, 31 | 0, &ind, "S"); 32 | CHKExecute("S"); 33 | ODBC_FREE(); 34 | } 35 | 36 | int 37 | main(int argc, char **argv) 38 | { 39 | odbc_use_version3 = 1; 40 | odbc_connect(); 41 | 42 | odbc_command("create table #test_output (id int, msg text)"); 43 | 44 | Test("?", SQL_INTEGER, "?", SQL_LONGVARCHAR); 45 | Test("123", SQL_INTEGER, "?", SQL_LONGVARCHAR); 46 | Test("?", SQL_INTEGER, "'foo'", SQL_LONGVARCHAR); 47 | Test("?", SQL_INTEGER, "?", SQL_VARCHAR); 48 | 49 | /* 50 | * Sybase cannot pass this test without complicated query parsing. 51 | * Query with blob columns cannot be prepared so prepared query must 52 | * be emulated loosing column informations from server and Sybase do 53 | * not convert implicitly VARCHAR to INT 54 | */ 55 | if (odbc_db_is_microsoft()) 56 | Test("?", SQL_VARCHAR, "?", SQL_LONGVARCHAR); 57 | else 58 | ++test_num; 59 | 60 | odbc_disconnect(); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /src/odbc/unittests/copydesc.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* Test SQLCopyDesc and SQLAllocHandle(SQL_HANDLE_DESC) */ 4 | 5 | static char software_version[] = "$Id: copydesc.c,v 1.7 2010-07-05 09:20:32 freddy77 Exp $"; 6 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 7 | 8 | int 9 | main(int argc, char *argv[]) 10 | { 11 | SQLHDESC ard, ard2, ard3; 12 | SQLINTEGER id; 13 | SQLLEN ind1, ind2; 14 | char name[64]; 15 | 16 | odbc_connect(); 17 | 18 | CHKGetStmtAttr(SQL_ATTR_APP_ROW_DESC, &ard, 0, NULL, "S"); 19 | 20 | CHKBindCol(1, SQL_C_SLONG, &id, sizeof(SQLINTEGER), &ind1, "S"); 21 | CHKBindCol(2, SQL_C_CHAR, name, sizeof(name), &ind2, "S"); 22 | 23 | CHKAllocHandle(SQL_HANDLE_DESC, odbc_conn, &ard2, "S"); 24 | 25 | /* 26 | * this is an additional test to test additional allocation 27 | * As of 0.64 for a bug in SQLAllocDesc we only allow to allocate one 28 | */ 29 | CHKAllocHandle(SQL_HANDLE_DESC, odbc_conn, &ard3, "S"); 30 | 31 | CHKR(SQLCopyDesc, (ard, ard2), "S"); 32 | 33 | CHKFreeHandle(SQL_HANDLE_DESC, ard3, "S"); 34 | 35 | odbc_disconnect(); 36 | 37 | printf("Done.\n"); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/odbc/unittests/cursor2.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* 4 | * 1) Test cursor do not give error for statement that do not return rows 5 | * 2) Test cursor returns results on language RPCs 6 | */ 7 | 8 | static char software_version[] = "$Id: cursor2.c,v 1.12 2011-07-12 10:16:59 freddy77 Exp $"; 9 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 10 | 11 | int 12 | main(int argc, char *argv[]) 13 | { 14 | SQLTCHAR sqlstate[6]; 15 | SQLTCHAR msg[256]; 16 | 17 | odbc_connect(); 18 | odbc_check_cursor(); 19 | 20 | odbc_command("CREATE TABLE #cursor2_test (i INT)"); 21 | 22 | odbc_reset_statement(); 23 | CHKSetStmtAttr(SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) SQL_CURSOR_DYNAMIC, SQL_IS_INTEGER, "S"); 24 | 25 | /* this should not fail or return warnings */ 26 | odbc_command("DROP TABLE #cursor2_test"); 27 | 28 | CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, msg, ODBC_VECTOR_SIZE(msg), NULL, "No"); 29 | 30 | 31 | odbc_reset_statement(); 32 | odbc_command_with_result(odbc_stmt, "if object_id('sp_test') is not null drop proc sp_test"); 33 | odbc_command("create proc sp_test @name varchar(30) as select 0 as pippo select 1 as 'test', @name as 'nome'"); 34 | 35 | odbc_reset_statement(); 36 | CHKSetStmtAttr(SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) SQL_CURSOR_STATIC, SQL_IS_INTEGER, "S"); 37 | 38 | odbc_command(" exec sp_test 'ciao'"); 39 | 40 | CHKFetch("S"); 41 | 42 | odbc_reset_statement(); 43 | odbc_command("drop proc sp_test"); 44 | 45 | odbc_disconnect(); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /src/odbc/unittests/cursor4.c: -------------------------------------------------------------------------------- 1 | /* Test sp_cursorprepare / sp_cursorexecute usage to support SELECT FOR UPDATE 2 | * This test compiles and works fine with SQL Server Native Client, and uses 3 | * the sp_cursor* API Server Cursors ... 4 | */ 5 | 6 | #include "common.h" 7 | 8 | static void 9 | exec_direct(const char *stmt) 10 | { 11 | SQLHSTMT odbc_stmt = SQL_NULL_HSTMT; 12 | 13 | CHKAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_conn, (SQLHANDLE *) & odbc_stmt, "S"); 14 | odbc_command(stmt); 15 | CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_stmt, "S"); 16 | } 17 | 18 | int 19 | main(int argc, char **argv) 20 | { 21 | char buff[64]; 22 | SQLLEN ind; 23 | 24 | odbc_use_version3 = 1; 25 | odbc_connect(); 26 | 27 | odbc_check_cursor(); 28 | 29 | exec_direct("CREATE TABLE #t1 ( k INT, c VARCHAR(20))"); 30 | exec_direct("INSERT INTO #t1 VALUES (1, 'aaa')"); 31 | 32 | odbc_reset_statement(); 33 | 34 | CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_LOCK, SQL_IS_UINTEGER, "S"); 35 | 36 | CHKSetCursorName(T("c112"), SQL_NTS, "S"); 37 | 38 | CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, int2ptr(SQL_AUTOCOMMIT_OFF), 0, "S"); 39 | 40 | CHKPrepare(T("SELECT * FROM #t1 FOR UPDATE"), SQL_NTS, "S"); 41 | 42 | CHKExecute("S"); 43 | 44 | CHKFetch("S"); 45 | 46 | exec_direct("UPDATE #t1 SET c = 'xxx' WHERE CURRENT OF c112"); 47 | 48 | CHKCloseCursor("SI"); 49 | 50 | CHKEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_COMMIT, "S"); 51 | 52 | CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, int2ptr(SQL_AUTOCOMMIT_ON), 0, "S"); 53 | 54 | CHKExecDirect(T("SELECT c FROM #t1 WHERE k = 1"), SQL_NTS, "S"); 55 | 56 | CHKFetch("S"); 57 | 58 | CHKGetData(1, SQL_C_CHAR, buff, sizeof(buff), &ind, "S"); 59 | 60 | printf(">> New value after update = [%s] (should be [xxx]) \n", buff); 61 | 62 | CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_stmt, "S"); 63 | odbc_stmt = SQL_NULL_HSTMT; 64 | 65 | odbc_disconnect(); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /src/odbc/unittests/date.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | 4 | static char software_version[] = "$Id: date.c,v 1.14 2011-07-12 10:16:59 freddy77 Exp $"; 5 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 6 | 7 | static void 8 | DoTest(int n) 9 | { 10 | SQLCHAR output[256]; 11 | 12 | SQLSMALLINT colType; 13 | SQLULEN colSize; 14 | SQLSMALLINT colScale, colNullable; 15 | SQLLEN dataSize; 16 | 17 | TIMESTAMP_STRUCT ts; 18 | 19 | odbc_command("select convert(datetime, '2002-12-27 18:43:21')"); 20 | 21 | CHKFetch("SI"); 22 | CHKDescribeCol(1, (SQLTCHAR*)output, sizeof(output)/sizeof(SQLWCHAR), NULL, &colType, &colSize, &colScale, &colNullable, "S"); 23 | 24 | if (n == 0) { 25 | memset(&ts, 0, sizeof(ts)); 26 | CHKGetData(1, SQL_C_TIMESTAMP, &ts, sizeof(ts), &dataSize, "S"); 27 | sprintf((char *) output, "%04d-%02d-%02d %02d:%02d:%02d.000", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second); 28 | } else { 29 | CHKGetData(1, SQL_C_CHAR, output, sizeof(output), &dataSize, "S"); 30 | } 31 | 32 | printf("Date returned: %s\n", output); 33 | if (strcmp((char *) output, "2002-12-27 18:43:21.000") != 0) { 34 | fprintf(stderr, "Invalid returned date\n"); 35 | exit(1); 36 | } 37 | 38 | CHKFetch("No"); 39 | CHKCloseCursor("SI"); 40 | } 41 | 42 | int 43 | main(int argc, char *argv[]) 44 | { 45 | odbc_connect(); 46 | 47 | DoTest(0); 48 | DoTest(1); 49 | 50 | odbc_disconnect(); 51 | 52 | printf("Done.\n"); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /src/odbc/unittests/descrec.c: -------------------------------------------------------------------------------- 1 | /* test SQLGetDescRec */ 2 | #include "common.h" 3 | 4 | static char software_version[] = "$Id: descrec.c,v 1.3 2011-07-12 10:16:59 freddy77 Exp $"; 5 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 6 | 7 | int 8 | main(void) 9 | { 10 | SQLHDESC Descriptor; 11 | SQLINTEGER ind; 12 | SQLTCHAR name[128]; 13 | SQLSMALLINT si; 14 | 15 | odbc_use_version3 = 1; 16 | odbc_connect(); 17 | 18 | odbc_command("create table #tmp1 (i int)"); 19 | 20 | /* get IRD */ 21 | CHKGetStmtAttr(SQL_ATTR_IMP_ROW_DESC, &Descriptor, sizeof(Descriptor), &ind, "S"); 22 | 23 | CHKGetDescRec(-1, name, ODBC_VECTOR_SIZE(name), &si, NULL, NULL, NULL, NULL, NULL, NULL, "E"); 24 | /* TODO here should be NO_DATA cause we are requesting bookmark */ 25 | /* CHKGetDescRec(0, name, sizeof(name), &si, NULL, NULL, NULL, NULL, NULL, NULL, "No"); */ 26 | CHKGetDescRec(1, name, ODBC_VECTOR_SIZE(name), &si, NULL /*Type*/, NULL /*SubType*/, NULL /*Length*/, NULL/*Precision*/, 27 | NULL /*Scale*/, NULL /*Nullable*/, "No"); 28 | 29 | odbc_command("SELECT name FROM sysobjects"); 30 | 31 | CHKGetDescRec(1, name, ODBC_VECTOR_SIZE(name), &si, NULL /*Type*/, NULL /*SubType*/, NULL /*Length*/, NULL/*Precision*/, 32 | NULL /*Scale*/, NULL /*Nullable*/, "S"); 33 | 34 | odbc_disconnect(); 35 | ODBC_FREE(); 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/odbc/unittests/describecol2.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include 3 | 4 | /* 5 | * SQLDescribeCol test 6 | */ 7 | static int g_result = 0; 8 | 9 | static void 10 | do_check(int c, const char *test, int line) 11 | { 12 | if (c) 13 | return; 14 | 15 | fprintf(stderr, "Failed check %s at line %d\n", test, line); 16 | g_result = 1; 17 | } 18 | 19 | #define check(s) do_check(s, #s, __LINE__) 20 | 21 | int 22 | main(int argc, char *argv[]) 23 | { 24 | SQLSMALLINT len, type; 25 | SQLTCHAR name[128]; 26 | 27 | odbc_connect(); 28 | odbc_command("create table #dc (col_name int, name2 varchar(100))"); 29 | 30 | odbc_command("select * from #dc"); 31 | 32 | len = 0x1234; 33 | CHKDescribeCol(1, NULL, 0, &len, &type, NULL, NULL, NULL, "S"); 34 | check(len == 8); 35 | 36 | len = 0x1234; 37 | CHKDescribeCol(2, name, 0, &len, &type, NULL, NULL, NULL, "I"); 38 | check(len == 5); 39 | 40 | len = 0x1234; 41 | CHKDescribeCol(1, NULL, 2, &len, &type, NULL, NULL, NULL, "S"); 42 | check(len == 8); 43 | 44 | len = 0x1234; 45 | strcpy((char *) name, "xxx"); 46 | CHKDescribeCol(2, name, 3, &len, &type, NULL, NULL, NULL, "I"); 47 | check(len == 5 && strcmp(C(name), "na") == 0); 48 | 49 | len = 0x1234; 50 | strcpy((char *) name, "xxx"); 51 | CHKDescribeCol(1, name, 1, &len, &type, NULL, NULL, NULL, "I"); 52 | check(len == 8 && strcmp(C(name), "") == 0); 53 | 54 | len = 0x1234; 55 | strcpy((char *) name, "xxx"); 56 | CHKDescribeCol(2, name, 6, &len, &type, NULL, NULL, NULL, "S"); 57 | check(len == 5 && strcmp(C(name), "name2") == 0); 58 | 59 | odbc_disconnect(); 60 | 61 | if (g_result == 0) 62 | printf("Done.\n"); 63 | return g_result; 64 | } 65 | -------------------------------------------------------------------------------- /src/odbc/unittests/earlybind.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | static char software_version[] = "$Id: earlybind.c,v 1.5 2010-07-05 09:20:33 freddy77 Exp $"; 4 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 5 | 6 | int 7 | main(int argc, char *argv[]) 8 | { 9 | SQLINTEGER id; 10 | SQLLEN ind1, ind2; 11 | char name[64]; 12 | 13 | odbc_connect(); 14 | 15 | odbc_command("CREATE TABLE #test(id INT, name VARCHAR(100))"); 16 | odbc_command("INSERT INTO #test(id, name) VALUES(8, 'sysobjects')"); 17 | 18 | /* bind before select */ 19 | SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &id, sizeof(SQLINTEGER), &ind1); 20 | SQLBindCol(odbc_stmt, 2, SQL_C_CHAR, name, sizeof(name), &ind2); 21 | 22 | /* do select */ 23 | odbc_command("SELECT id, name FROM #test WHERE name = 'sysobjects' SELECT 123, 'foo'"); 24 | 25 | /* get results */ 26 | id = -1; 27 | memset(name, 0, sizeof(name)); 28 | SQLFetch(odbc_stmt); 29 | 30 | if (id == -1 || strcmp(name, "sysobjects") != 0) { 31 | fprintf(stderr, "wrong results\n"); 32 | return 1; 33 | } 34 | 35 | /* discard others data */ 36 | SQLFetch(odbc_stmt); 37 | 38 | SQLMoreResults(odbc_stmt); 39 | 40 | id = -1; 41 | memset(name, 0, sizeof(name)); 42 | SQLFetch(odbc_stmt); 43 | 44 | if (id != 123 || strcmp(name, "foo") != 0) { 45 | fprintf(stderr, "wrong results\n"); 46 | return 1; 47 | } 48 | 49 | /* discard others data */ 50 | SQLFetch(odbc_stmt); 51 | 52 | SQLMoreResults(odbc_stmt); 53 | 54 | /* other select */ 55 | odbc_command("SELECT 321, 'minni'"); 56 | 57 | /* get results */ 58 | id = -1; 59 | memset(name, 0, sizeof(name)); 60 | SQLFetch(odbc_stmt); 61 | 62 | if (id != 321 || strcmp(name, "minni") != 0) { 63 | fprintf(stderr, "wrong results\n"); 64 | return 1; 65 | } 66 | 67 | /* discard others data */ 68 | SQLFetch(odbc_stmt); 69 | 70 | SQLMoreResults(odbc_stmt); 71 | 72 | odbc_disconnect(); 73 | 74 | printf("Done.\n"); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /src/odbc/unittests/error.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* some tests on error reporting */ 4 | 5 | int 6 | main(int argc, char *argv[]) 7 | { 8 | SQLRETURN RetCode; 9 | HSTMT stmt; 10 | 11 | odbc_connect(); 12 | 13 | /* create a test table */ 14 | odbc_command("create table #tmp (i int)"); 15 | odbc_command("insert into #tmp values(3)"); 16 | odbc_command("insert into #tmp values(4)"); 17 | odbc_command("insert into #tmp values(5)"); 18 | odbc_command("insert into #tmp values(6)"); 19 | odbc_command("insert into #tmp values(7)"); 20 | 21 | /* issue our command */ 22 | RetCode = odbc_command2("select 100 / (i - 5) from #tmp order by i", "SE"); 23 | 24 | /* special case, early Sybase detect error early */ 25 | if (RetCode != SQL_ERROR) { 26 | 27 | /* TODO when multiple row fetch available test for error on some columns */ 28 | CHKFetch("S"); 29 | CHKFetch("S"); 30 | CHKFetch("E"); 31 | } 32 | 33 | odbc_read_error(); 34 | if (!strstr(odbc_err, "zero")) { 35 | fprintf(stderr, "Message invalid\n"); 36 | return 1; 37 | } 38 | 39 | SQLFetch(odbc_stmt); 40 | SQLFetch(odbc_stmt); 41 | SQLFetch(odbc_stmt); 42 | SQLMoreResults(odbc_stmt); 43 | 44 | CHKAllocStmt(&stmt, "S"); 45 | 46 | odbc_command("SELECT * FROM sysobjects"); 47 | 48 | odbc_stmt = stmt; 49 | 50 | /* a statement is already active so you get error... */ 51 | if (odbc_command2("SELECT * FROM sysobjects", "SE") == SQL_SUCCESS) { 52 | SQLMoreResults(odbc_stmt); 53 | /* ...or we are using MARS! */ 54 | odbc_command2("BEGIN TRANSACTION", "E"); 55 | } 56 | 57 | odbc_read_error(); 58 | 59 | odbc_disconnect(); 60 | 61 | printf("Done.\n"); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /src/odbc/unittests/hidden.c: -------------------------------------------------------------------------------- 1 | /* Testing result column numbers having hidden columns */ 2 | /* Test from Sebastien Flaesch */ 3 | 4 | #include "common.h" 5 | 6 | int 7 | main(int argc, char **argv) 8 | { 9 | SQLSMALLINT cnt = 0; 10 | int failed = 0; 11 | 12 | odbc_use_version3 = 1; 13 | odbc_connect(); 14 | 15 | odbc_command("CREATE TABLE #t1 ( k INT, c CHAR(10), vc VARCHAR(10) )"); 16 | odbc_command("CREATE TABLE #tmp1 (i NUMERIC(10,0) IDENTITY PRIMARY KEY, b VARCHAR(20) NULL, c INT NOT NULL)"); 17 | 18 | /* test hidden column with FOR BROWSE */ 19 | odbc_reset_statement(); 20 | 21 | odbc_command("SELECT c, b FROM #tmp1"); 22 | 23 | CHKNumResultCols(&cnt, "S"); 24 | 25 | if (cnt != 2) { 26 | fprintf(stderr, "Wrong number of columns in result set: %d\n", (int) cnt); 27 | failed = 1; 28 | } 29 | odbc_reset_statement(); 30 | 31 | /* test hidden column with cursors*/ 32 | odbc_check_cursor(); 33 | 34 | CHKSetStmtAttr(SQL_ATTR_CURSOR_SCROLLABLE, (SQLPOINTER) SQL_NONSCROLLABLE, SQL_IS_UINTEGER, "S"); 35 | CHKSetStmtAttr(SQL_ATTR_CURSOR_SENSITIVITY, (SQLPOINTER) SQL_SENSITIVE, SQL_IS_UINTEGER, "S"); 36 | 37 | CHKPrepare(T("SELECT * FROM #t1"), SQL_NTS, "S"); 38 | 39 | CHKExecute("S"); 40 | 41 | CHKNumResultCols(&cnt, "S"); 42 | 43 | if (cnt != 3) { 44 | fprintf(stderr, "Wrong number of columns in result set: %d\n", (int) cnt); 45 | failed = 1; 46 | } 47 | 48 | odbc_disconnect(); 49 | 50 | return failed ? 1: 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/odbc/unittests/lang_error.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* Test if SQLExecDirect return error if a error in row is returned */ 4 | 5 | static char software_version[] = "$Id: lang_error.c,v 1.6 2010-07-05 09:20:33 freddy77 Exp $"; 6 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 7 | 8 | int 9 | main(int argc, char *argv[]) 10 | { 11 | odbc_connect(); 12 | 13 | /* issue print statement and test message returned */ 14 | odbc_command2("SELECT DATEADD(dd,-100000,getdate())", "E"); 15 | 16 | odbc_disconnect(); 17 | 18 | printf("Done.\n"); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/odbc/unittests/norowset.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | static char software_version[] = "$Id: norowset.c,v 1.9 2010-07-05 09:20:33 freddy77 Exp $"; 4 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 5 | 6 | /* Test that a select following a store procedure execution return results */ 7 | 8 | int 9 | main(int argc, char *argv[]) 10 | { 11 | char output[256]; 12 | SQLLEN dataSize; 13 | 14 | odbc_connect(); 15 | 16 | odbc_command_with_result(odbc_stmt, "drop proc sp_norowset_test"); 17 | 18 | odbc_command("create proc sp_norowset_test as begin declare @i int end"); 19 | 20 | odbc_command("exec sp_norowset_test"); 21 | 22 | /* note, mssql 2005 seems to not return row for tempdb, use always master */ 23 | odbc_command("select name from master..sysobjects where name = 'sysobjects'"); 24 | CHKFetch("S"); 25 | 26 | CHKGetData(1, SQL_C_CHAR, output, sizeof(output), &dataSize, "S"); 27 | 28 | if (strcmp(output, "sysobjects") != 0) { 29 | printf("Unexpected result\n"); 30 | exit(1); 31 | } 32 | 33 | CHKFetch("No"); 34 | 35 | CHKMoreResults("No"); 36 | 37 | odbc_command("drop proc sp_norowset_test"); 38 | 39 | odbc_disconnect(); 40 | 41 | printf("Done.\n"); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/odbc/unittests/oldpwd.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* change password on server */ 4 | 5 | static void 6 | my_attrs(void) 7 | { 8 | SQLSetConnectAttr(odbc_conn, 1226 /*SQL_COPT_SS_OLDPWD */, (SQLPOINTER) odbc_password, SQL_NTS); 9 | strcpy(odbc_password, "testpwd$"); 10 | } 11 | 12 | int 13 | main(int argc, char *argv[]) 14 | { 15 | odbc_use_version3 = 1; 16 | odbc_set_conn_attr = my_attrs; 17 | odbc_connect(); 18 | 19 | odbc_disconnect(); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/odbc/unittests/paramcore.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* 4 | * Try to make core dump using SQLBindParameter 5 | */ 6 | 7 | static char software_version[] = "$Id: paramcore.c,v 1.9 2011-07-12 10:16:59 freddy77 Exp $"; 8 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 9 | 10 | #define SP_TEXT "{call sp_paramcore_test(?)}" 11 | #define OUTSTRING_LEN 20 12 | 13 | int 14 | main(int argc, char *argv[]) 15 | { 16 | SQLLEN cb = SQL_NTS; 17 | 18 | odbc_use_version3 = 1; 19 | 20 | odbc_connect(); 21 | 22 | odbc_command_with_result(odbc_stmt, "drop proc sp_paramcore_test"); 23 | odbc_command("create proc sp_paramcore_test @s varchar(100) output as select @s = '12345'"); 24 | 25 | /* here we pass a NULL buffer for input SQL_NTS */ 26 | CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, OUTSTRING_LEN, 0, NULL, OUTSTRING_LEN, &cb, "S"); 27 | 28 | cb = SQL_NTS; 29 | CHKExecDirect(T(SP_TEXT), SQL_NTS, "E"); 30 | odbc_reset_statement(); 31 | 32 | /* here we pass a NULL buffer for input */ 33 | CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_VARCHAR, 18, 0, NULL, OUTSTRING_LEN, &cb, "S"); 34 | 35 | cb = 1; 36 | CHKExecDirect(T(SP_TEXT), SQL_NTS, "E"); 37 | odbc_reset_statement(); 38 | 39 | odbc_command("drop proc sp_paramcore_test"); 40 | odbc_command("create proc sp_paramcore_test @s numeric(10,2) output as select @s = 12345.6"); 41 | odbc_reset_statement(); 42 | 43 | #if 0 /* this fails even on native platforms */ 44 | /* here we pass a NULL buffer for output */ 45 | cb = sizeof(SQL_NUMERIC_STRUCT); 46 | SQLBindParameter(odbc_stmt, 1, SQL_PARAM_OUTPUT, SQL_C_NUMERIC, SQL_NUMERIC, 18, 0, NULL, OUTSTRING_LEN, &cb); 47 | odbc_read_error(); 48 | 49 | cb = 1; 50 | odbc_command_with_result(odbc_stmt, SP_TEXT); 51 | odbc_read_error(); 52 | odbc_reset_statement(); 53 | #endif 54 | 55 | odbc_command("drop proc sp_paramcore_test"); 56 | 57 | odbc_disconnect(); 58 | 59 | printf("Done successfully!\n"); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /src/odbc/unittests/parser.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern unsigned int odbc_line_num; 4 | 5 | void odbc_fatal(const char *msg, ...); 6 | 7 | const char *odbc_get_tok(char **p); 8 | const char *odbc_get_str(char **p); 9 | 10 | void odbc_set_bool(const char *name, int value); 11 | void odbc_init_bools(void); 12 | void odbc_clear_bools(void); 13 | 14 | void odbc_init_parser(FILE *f); 15 | const char *odbc_get_cmd_line(char **p, int *cond); 16 | 17 | #include 18 | -------------------------------------------------------------------------------- /src/odbc/unittests/peter.c: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include "common.h" 3 | #include 4 | 5 | /* 6 | Test SQLNumResultCols after SQLFreeStmt 7 | This test on Sybase should not raise an error 8 | */ 9 | 10 | static char software_version[] = "$Id: peter.c,v 1.2 2011-07-12 10:16:59 freddy77 Exp $"; 11 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 12 | 13 | int 14 | main(int argc, char *argv[]) 15 | { 16 | SQLSMALLINT num_params, cols; 17 | SQLLEN count; 18 | SQLINTEGER id; 19 | 20 | odbc_use_version3 = 1; 21 | odbc_connect(); 22 | 23 | odbc_command("create table #tester (id int not null, name varchar(20) not null)"); 24 | odbc_command("insert into #tester(id, name) values(1, 'abc')"); 25 | odbc_command("insert into #tester(id, name) values(2, 'duck')"); 26 | 27 | CHKPrepare(T("SELECT * FROM #tester WHERE id = ?"), SQL_NTS, "S"); 28 | 29 | CHKR(SQLNumParams, (odbc_stmt, &num_params), "S"); 30 | assert(num_params == 1); 31 | 32 | id = 1; 33 | CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &id, sizeof(id), NULL, "S"); 34 | 35 | CHKExecute("S"); 36 | 37 | CHKR(SQLFreeStmt, (odbc_stmt, SQL_RESET_PARAMS), "S"); 38 | 39 | CHKRowCount(&count, "S"); 40 | 41 | CHKNumResultCols(&cols, "S"); 42 | assert(cols == 2); 43 | 44 | odbc_disconnect(); 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/odbc/unittests/prepare_warn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author : sf@4js.com 3 | * FreeTDS version : 0.91RC2 (20110429) 4 | * Platform : Linux 32b (Debian Lenny) 5 | * Fetching when there is a NULL value in table gives invalid cursor state error. 6 | * Is this because of Warning SQLSTATE 01003? 7 | */ 8 | 9 | #include "common.h" 10 | 11 | int 12 | main(int argc, char **argv) 13 | { 14 | #define ARRAY_SIZE 10 15 | SQLCHAR v_dec[ARRAY_SIZE][21]; 16 | SQLLEN v_ind[ARRAY_SIZE]; 17 | SQLULEN nrows; 18 | 19 | odbc_use_version3 = 1; 20 | odbc_connect(); 21 | odbc_check_cursor(); 22 | 23 | odbc_command("IF OBJECT_ID('mytab1') IS NOT NULL DROP TABLE mytab1"); 24 | odbc_command("CREATE TABLE mytab1 ( k INT, d DECIMAL(10,2))"); 25 | odbc_command("INSERT INTO mytab1 VALUES ( 201, 111.11 )"); 26 | /*SQLExecDirect(m_hstmt, (SQLCHAR *) "insert into mytab1 values ( 202, 222.22 )", SQL_NTS); */ 27 | odbc_command("INSERT INTO mytab1 VALUES ( 202, null )"); 28 | 29 | odbc_reset_statement(); 30 | 31 | CHKSetStmtAttr(SQL_ATTR_CURSOR_SCROLLABLE, (SQLPOINTER) SQL_NONSCROLLABLE, SQL_IS_UINTEGER, "S"); 32 | CHKSetStmtAttr(SQL_ATTR_CURSOR_SENSITIVITY, (SQLPOINTER) SQL_SENSITIVE, SQL_IS_UINTEGER, "S"); 33 | 34 | CHKSetStmtAttr(SQL_ATTR_ROW_BIND_TYPE, (SQLPOINTER) SQL_BIND_BY_COLUMN, SQL_IS_UINTEGER, "S"); 35 | CHKSetStmtAttr(SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER) ARRAY_SIZE, SQL_IS_UINTEGER, "S"); 36 | CHKSetStmtAttr(SQL_ATTR_ROWS_FETCHED_PTR, (SQLPOINTER) & (nrows), SQL_IS_UINTEGER, "S"); 37 | 38 | CHKPrepare(T("SELECT SUM(d) FROM mytab1"), SQL_NTS, "S"); 39 | 40 | CHKExecute("I"); 41 | 42 | #if 0 43 | CHKMoreResults("S"); /* skip warning*/ 44 | #endif 45 | 46 | CHKBindCol(1, SQL_C_CHAR, v_dec, 21, v_ind, "S"); 47 | 48 | CHKFetch("S"); 49 | 50 | printf("fetch 1: rows fetched = %d\n", (int) nrows); 51 | printf("fetch 1: value = [%s]\n", v_dec[0]); 52 | 53 | CHKFetch("No"); 54 | 55 | CHKMoreResults("No"); 56 | 57 | odbc_command("drop table mytab1"); 58 | 59 | odbc_disconnect(); 60 | 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/odbc/unittests/preperror.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* test error on prepared statement, from Nathaniel Talbott test */ 4 | 5 | static char software_version[] = "$Id: preperror.c,v 1.10 2011-07-12 10:16:59 freddy77 Exp $"; 6 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 7 | 8 | int 9 | main(int argc, char *argv[]) 10 | { 11 | SQLLEN cbInString = SQL_NTS; 12 | char buf[256]; 13 | SQLTCHAR msg[256]; 14 | SQLTCHAR sqlstate[6]; 15 | 16 | odbc_connect(); 17 | 18 | odbc_command("CREATE TABLE #urls ( recdate DATETIME ) "); 19 | 20 | /* test implicit conversion error */ 21 | CHKExecDirect(T("INSERT INTO #urls ( recdate ) VALUES ( '2003-10-1 10:11:1 0' )"), SQL_NTS, "E"); 22 | 23 | /* test prepared implicit conversion error */ 24 | CHKPrepare(T("INSERT INTO #urls ( recdate ) VALUES ( ? )"), SQL_NTS, "SI"); 25 | 26 | strcpy(buf, "2003-10-1 10:11:1 0"); 27 | CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 128, 0, buf, sizeof(buf), &cbInString, "SI"); 28 | 29 | CHKExecute("E"); 30 | 31 | CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, msg, ODBC_VECTOR_SIZE(buf), NULL, "SI"); 32 | printf("err=%s\n", C(msg)); 33 | 34 | /* assure initial state */ 35 | odbc_reset_statement(); 36 | 37 | /* try to prepare and execute a statement with error (from DBD::ODBC test) */ 38 | if (CHKPrepare(T("SELECT XXNOTCOLUMN FROM sysobjects"), SQL_NTS, "SE") == SQL_SUCCESS) 39 | CHKExecute("E"); 40 | 41 | CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, msg, ODBC_VECTOR_SIZE(buf), NULL, "SI"); 42 | printf("err=%s\n", C(msg)); 43 | 44 | 45 | odbc_disconnect(); 46 | 47 | printf("Done.\n"); 48 | ODBC_FREE(); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /src/odbc/unittests/t0001.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | static char software_version[] = "$Id: t0001.c,v 1.19 2010-07-05 09:20:33 freddy77 Exp $"; 4 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 5 | 6 | int 7 | main(int argc, char *argv[]) 8 | { 9 | 10 | int i; 11 | 12 | SQLLEN cnamesize; 13 | 14 | const char *command; 15 | SQLCHAR output[256]; 16 | 17 | odbc_connect(); 18 | 19 | odbc_command("if object_id('tempdb..#odbctestdata') is not null drop table #odbctestdata"); 20 | 21 | command = "create table #odbctestdata (" 22 | "col1 varchar(30) not null," 23 | "col2 int not null," 24 | "col3 float not null," "col4 numeric(18,6) not null," "col5 datetime not null," "col6 text not null)"; 25 | odbc_command(command); 26 | 27 | command = "insert #odbctestdata values (" 28 | "'ABCDEFGHIJKLMNOP'," 29 | "123456," "1234.56," "123456.78," "'Sep 11 2001 10:00AM'," "'just to check returned length...')"; 30 | odbc_command(command); 31 | 32 | odbc_command("select * from #odbctestdata"); 33 | 34 | CHKFetch("SI"); 35 | 36 | for (i = 1; i <= 6; i++) { 37 | CHKGetData(i, SQL_C_CHAR, output, sizeof(output), &cnamesize, "S"); 38 | 39 | printf("output data >%s< len_or_ind = %d\n", output, (int) cnamesize); 40 | if (cnamesize != strlen((char *) output)) 41 | return 1; 42 | } 43 | 44 | CHKFetch("No"); 45 | 46 | CHKCloseCursor("SI"); 47 | 48 | odbc_command("drop table #odbctestdata"); 49 | 50 | odbc_disconnect(); 51 | 52 | printf("Done.\n"); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /src/odbc/unittests/t0002.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | #define SWAP_STMT() do { SQLHSTMT xyz = odbc_stmt; \ 4 | odbc_stmt = old_odbc_stmt; old_odbc_stmt = xyz; } while(0) 5 | 6 | int 7 | main(int argc, char *argv[]) 8 | { 9 | HSTMT old_odbc_stmt = SQL_NULL_HSTMT; 10 | 11 | odbc_connect(); 12 | 13 | odbc_command("if object_id('tempdb..#odbctestdata') is not null drop table #odbctestdata"); 14 | 15 | odbc_command("create table #odbctestdata (i int)"); 16 | odbc_command("insert #odbctestdata values (123)"); 17 | 18 | /* 19 | * now we allocate another statement, select, get all results 20 | * then make another query with first select and drop this statement 21 | * result should not disappear (required for DBD::ODBC) 22 | */ 23 | SWAP_STMT(); 24 | CHKAllocStmt(&odbc_stmt, "S"); 25 | 26 | odbc_command("select * from #odbctestdata where 0=1"); 27 | 28 | CHKFetch("No"); 29 | 30 | CHKCloseCursor("SI"); 31 | 32 | SWAP_STMT(); 33 | odbc_command("select * from #odbctestdata"); 34 | SWAP_STMT(); 35 | 36 | /* drop first statement .. data should not disappear */ 37 | CHKFreeStmt(SQL_DROP, "S"); 38 | odbc_stmt = SQL_NULL_HSTMT; 39 | SWAP_STMT(); 40 | 41 | CHKFetch("SI"); 42 | 43 | CHKFetch("No"); 44 | 45 | CHKCloseCursor("SI"); 46 | 47 | odbc_command("drop table #odbctestdata"); 48 | 49 | odbc_disconnect(); 50 | 51 | printf("Done.\n"); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/odbc/unittests/t0003.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* Test for SQLMoreResults */ 4 | 5 | static char software_version[] = "$Id: t0003.c,v 1.21 2011-07-12 10:16:59 freddy77 Exp $"; 6 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 7 | 8 | static void 9 | DoTest(int prepared) 10 | { 11 | odbc_command("create table #odbctestdata (i int)"); 12 | 13 | /* test that 2 empty result set are returned correctly */ 14 | if (!prepared) { 15 | odbc_command("select * from #odbctestdata select * from #odbctestdata"); 16 | } else { 17 | CHKPrepare(T("select * from #odbctestdata select * from #odbctestdata"), SQL_NTS, "S"); 18 | CHKExecute("S"); 19 | } 20 | 21 | CHKFetch("No"); 22 | 23 | CHKMoreResults("S"); 24 | printf("Getting next recordset\n"); 25 | 26 | CHKFetch("No"); 27 | 28 | CHKMoreResults("No"); 29 | 30 | /* test that skipping a no empty result go to other result set */ 31 | odbc_command("insert into #odbctestdata values(123)"); 32 | if (!prepared) { 33 | odbc_command("select * from #odbctestdata select * from #odbctestdata"); 34 | } else { 35 | CHKPrepare(T("select * from #odbctestdata select * from #odbctestdata"), SQL_NTS, "S"); 36 | CHKExecute("S"); 37 | } 38 | 39 | CHKMoreResults("S"); 40 | printf("Getting next recordset\n"); 41 | 42 | CHKFetch("S"); 43 | 44 | CHKFetch("No"); 45 | 46 | CHKMoreResults("No"); 47 | 48 | odbc_command("drop table #odbctestdata"); 49 | 50 | ODBC_FREE(); 51 | } 52 | 53 | int 54 | main(int argc, char *argv[]) 55 | { 56 | odbc_connect(); 57 | 58 | DoTest(0); 59 | DoTest(1); 60 | 61 | odbc_disconnect(); 62 | 63 | printf("Done.\n"); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /src/odbc/unittests/t0004.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* Test for SQLMoreResults */ 4 | 5 | static char software_version[] = "$Id: t0004.c,v 1.19 2011-07-12 10:16:59 freddy77 Exp $"; 6 | static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; 7 | 8 | static void 9 | Test(int use_indicator) 10 | { 11 | char buf[128]; 12 | SQLLEN ind; 13 | SQLLEN *pind = use_indicator ? &ind : NULL; 14 | 15 | strcpy(buf, "I don't exist"); 16 | ind = strlen(buf); 17 | 18 | CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 20, 0, buf, 128, pind, "S"); 19 | 20 | CHKPrepare(T("SELECT id, name FROM master..sysobjects WHERE name = ?"), SQL_NTS, "S"); 21 | 22 | CHKExecute("S"); 23 | 24 | CHKFetch("No"); 25 | 26 | CHKMoreResults("No"); 27 | 28 | /* use same binding above */ 29 | strcpy(buf, "sysobjects"); 30 | ind = strlen(buf); 31 | 32 | CHKExecute("S"); 33 | 34 | CHKFetch("S"); 35 | 36 | CHKFetch("No"); 37 | 38 | CHKMoreResults("No"); 39 | 40 | ODBC_FREE(); 41 | } 42 | 43 | int 44 | main(int argc, char *argv[]) 45 | { 46 | odbc_connect(); 47 | 48 | Test(1); 49 | Test(0); 50 | 51 | odbc_disconnect(); 52 | 53 | printf("Done.\n"); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /src/odbc/unittests/timeout2.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | #ifdef HAVE_UNISTD_H 4 | #include 5 | #endif 6 | 7 | #include 8 | 9 | #include "replacements.h" 10 | 11 | /* 12 | * Test timeout on prepare 13 | * It execute a query wait for timeout and then try to issue a new prepare/execute 14 | * This test a BUG where second prepare timeouts 15 | * 16 | * Test from Ou Liu, cf "Query Time Out", 2006-08-08 17 | */ 18 | 19 | int 20 | main(int argc, char *argv[]) 21 | { 22 | int i; 23 | 24 | odbc_connect(); 25 | 26 | odbc_command("create table #timeout(i int)"); 27 | odbc_command("insert into #timeout values(1)"); 28 | 29 | for (i = 0; i < 2; ++i) { 30 | 31 | printf("Loop %d\n", i); 32 | 33 | CHKSetStmtAttr(SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER) 10, SQL_IS_UINTEGER, "S"); 34 | 35 | CHKPrepare(T("select * from #timeout"), SQL_NTS, "S"); 36 | CHKExecute("S"); 37 | 38 | do { 39 | while (CHKFetch("SNo") == SQL_SUCCESS) 40 | ; 41 | } while (CHKMoreResults("SNo") == SQL_SUCCESS); 42 | 43 | if (i == 0) { 44 | printf("Sleep 15 seconds to test if timeout occurs\n"); 45 | tds_sleep_s(15); 46 | } 47 | 48 | SQLFreeStmt(odbc_stmt, SQL_CLOSE); 49 | SQLFreeStmt(odbc_stmt, SQL_UNBIND); 50 | SQLFreeStmt(odbc_stmt, SQL_RESET_PARAMS); 51 | SQLCloseCursor(odbc_stmt); 52 | } 53 | 54 | odbc_disconnect(); 55 | 56 | ODBC_FREE(); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /src/odbc/unittests/wchar.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* test SQL_C_DEFAULT with NCHAR type */ 4 | 5 | int 6 | main(int argc, char *argv[]) 7 | { 8 | char buf[102]; 9 | SQLLEN ind; 10 | int failed = 0; 11 | 12 | odbc_use_version3 = 1; 13 | odbc_connect(); 14 | 15 | CHKBindCol(1, SQL_C_DEFAULT, buf, 100, &ind, "S"); 16 | odbc_command("SELECT CONVERT(NCHAR(10), 'Pippo 123')"); 17 | 18 | /* get data */ 19 | memset(buf, 0, sizeof(buf)); 20 | CHKFetch("S"); 21 | 22 | SQLMoreResults(odbc_stmt); 23 | SQLMoreResults(odbc_stmt); 24 | 25 | odbc_disconnect(); 26 | 27 | /* the second string could came from Sybase configured with UTF-8 */ 28 | if (strcmp(buf, "Pippo 123 ") != 0 29 | && (odbc_db_is_microsoft() || strcmp(buf, "Pippo 123 ") != 0)) { 30 | fprintf(stderr, "Wrong results '%s'\n", buf); 31 | failed = 1; 32 | } 33 | 34 | return failed ? 1 : 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/odbc/version.rc.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramiro/freetds/7c2ccf5e745f2baee1be16cd62524701e9bd4141/src/odbc/version.rc.in -------------------------------------------------------------------------------- /src/odbc/winmain.c: -------------------------------------------------------------------------------- 1 | #include "../../win32/initnet.c" 2 | -------------------------------------------------------------------------------- /src/pool/.gitignore: -------------------------------------------------------------------------------- 1 | tdspool 2 | -------------------------------------------------------------------------------- /src/pool/BUGS: -------------------------------------------------------------------------------- 1 | Need to handle results larger than 1 packet. fixed 11/18/00 2 | Disconnect doesn't leave the FDSET. fixed 11/18/00 3 | -------------------------------------------------------------------------------- /src/pool/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am,v 1.17 2012-01-16 00:27:04 jklowden Exp $ 2 | AM_CPPFLAGS = -I$(top_srcdir)/include -I. -I$(SERVERDIR) 3 | bin_PROGRAMS = tdspool 4 | 5 | tdspool_SOURCES = config.c main.c member.c user.c util.c pool.h 6 | SERVERDIR = ../server 7 | LDADD = ../server/libtdssrv.la $(LTLIBICONV) 8 | EXTRA_DIST = BUGS pool.conf 9 | 10 | ETC = $(DESTDIR)$(sysconfdir) 11 | 12 | install-data-local: 13 | $(mkinstalldirs) $(ETC) 14 | if test ! -f $(ETC)/pool.conf; then \ 15 | $(INSTALL) $(srcdir)/pool.conf $(ETC)/pool.conf; \ 16 | fi 17 | -------------------------------------------------------------------------------- /src/pool/TODO: -------------------------------------------------------------------------------- 1 | Handle closed connections by the dataserver (done) 2 | Timeout open member connections. (done) 3 | Open member connections on the fly. (done) 4 | Add TDS_SRV_WAIT state when all members are in use. (done) 5 | Handle SIGTERM (partial...add timeout to select() call) 6 | Error checking is weak in several places. 7 | Need to handle larger packet sizes 8 | Add blob support 9 | Add TDS 5/7 support 10 | -------------------------------------------------------------------------------- /src/pool/pool.conf: -------------------------------------------------------------------------------- 1 | [global] 2 | min pool conn = 5 3 | max pool conn = 10 4 | max member age = 120 5 | 6 | [mypool] 7 | user = guest 8 | password = sybase 9 | database = tempdb 10 | server = JDBC_42 11 | port = 5000 12 | -------------------------------------------------------------------------------- /src/replacements/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | include(CheckFunctionExists) 4 | 5 | set(FUNCS asprintf vasprintf strtok_r readpassphrase 6 | strlcpy strlcat basename getopt strsep) 7 | 8 | set(add_SRCS) 9 | 10 | foreach(func ${FUNCS}) 11 | string(TOUPPER "HAVE_${func}" var) 12 | check_function_exists(${func} ${var}) 13 | if(NOT ${var}) 14 | set(add_SRCS ${add_SRCS} ${func}.c) 15 | endif() 16 | endforeach(func) 17 | 18 | add_library(replacements STATIC 19 | iconv.c gettimeofday.c poll.c 20 | getpassarg.c socketpair.c win_mutex.c 21 | tds_cond.c getaddrinfo.c sleep.c 22 | ${add_SRCS} 23 | ) 24 | if (NOT WIN32) 25 | set_target_properties(replacements PROPERTIES COMPILE_FLAGS -fPIC) 26 | endif() 27 | 28 | add_subdirectory(unittests) 29 | -------------------------------------------------------------------------------- /src/replacements/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am,v 1.20 2012-03-06 20:40:12 freddy77 Exp $ 2 | SUBDIRS= . unittests 3 | AM_CPPFLAGS= -I$(top_srcdir)/include -I$(top_srcdir)/src/replacements 4 | noinst_LTLIBRARIES= libreplacements.la 5 | libreplacements_la_SOURCES = \ 6 | iconv.c gettimeofday.c poll.c getpassarg.c socketpair.c win_mutex.c \ 7 | tds_cond.c getaddrinfo.c sleep.c 8 | 9 | libreplacements_la_LDFLAGS= 10 | libreplacements_la_LIBADD= @LTLIBOBJS@ 11 | EXTRA_DIST= asprintf.c \ 12 | basename.c \ 13 | getopt.c \ 14 | readpassphrase.c \ 15 | strlcat.c \ 16 | getaddrinfo.c \ 17 | strlcpy.c \ 18 | strtok_r.c \ 19 | strsep.c \ 20 | vasprintf.c \ 21 | socketpair.c \ 22 | ptw32_MCS_lock.c \ 23 | daemon.c \ 24 | CMakeLists.txt 25 | 26 | -------------------------------------------------------------------------------- /src/replacements/asprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * asprintf(3) 3 | * 20020809 entropy@tappedin.com 4 | * public domain. no warranty. use at your own risk. have a nice day. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #if HAVE_STRING_H 13 | #include 14 | #endif /* HAVE_STRING_H */ 15 | 16 | #include 17 | #include "replacements.h" 18 | 19 | int 20 | tds_asprintf(char **ret, const char *fmt, ...) 21 | { 22 | int len; 23 | va_list ap; 24 | 25 | va_start(ap, fmt); 26 | len = vasprintf(ret, fmt, ap); 27 | va_end(ap); 28 | return len; 29 | } 30 | -------------------------------------------------------------------------------- /src/replacements/basename.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 2005 Ziglio Frediano 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #if HAVE_STRING_H 23 | #include 24 | #endif /* HAVE_STRING_H */ 25 | 26 | #include 27 | #include "replacements.h" 28 | 29 | #if ! HAVE_BASENAME 30 | 31 | #ifdef _WIN32 32 | #define TDS_ISDIR_SEPARATOR(c) ((c) == '/' || (c) == '\\') 33 | #else 34 | #define TDS_ISDIR_SEPARATOR(c) ((c) == '/') 35 | #endif 36 | 37 | char *tds_basename(char *path) 38 | { 39 | char *p; 40 | 41 | if (path == NULL) 42 | return path; 43 | 44 | /* remove trailing directories separators */ 45 | for (p = path + strlen(path); --p > path && TDS_ISDIR_SEPARATOR(*p);) 46 | *p = '\0'; 47 | 48 | p = strrchr(path, '/'); 49 | if (p) 50 | path = p + 1; 51 | #ifdef _WIN32 52 | p = strrchr(path, '\\'); 53 | if (p) 54 | path = p + 1; 55 | #endif 56 | return path; 57 | } 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /src/replacements/getpassarg.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Brian Bruns 3 | * Copyright (C) 2006, 2007, 2008, 2009, 2010 Frediano Ziglio 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Library General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Library General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | * Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | 25 | #if HAVE_STRING_H 26 | #include 27 | #endif /* HAVE_STRING_H */ 28 | 29 | #include 30 | #include "replacements.h" 31 | 32 | /* 33 | * return a copy of the password, reading from stdin if arg is '-' 34 | * trashing he argument in the process. 35 | */ 36 | char * 37 | tds_getpassarg(char *arg) 38 | { 39 | char pwd[256], *ptr, *q; 40 | 41 | if (strcmp(arg, "-") == 0) { 42 | if (fgets(pwd, sizeof(pwd), stdin) == NULL) 43 | return NULL; 44 | ptr = strchr(pwd, '\n'); 45 | if (ptr) *ptr = '\0'; 46 | arg = pwd; 47 | } 48 | 49 | ptr = strdup(arg); 50 | memset(pwd, 0, sizeof(pwd)); 51 | 52 | for (q = arg; *q; *q++ = '*') 53 | continue; 54 | 55 | return ptr; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/replacements/sleep.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 2015 Ziglio Frediano 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #if HAVE_UNISTD_H 25 | #include 26 | #endif /* HAVE_UNISTD_H */ 27 | 28 | #if HAVE_ERRNO_H 29 | #include 30 | #endif /* HAVE_ERRNO_H */ 31 | 32 | #if HAVE_POLL_H 33 | #include 34 | #endif /* HAVE_POLL_H */ 35 | 36 | #include 37 | #include 38 | #include "replacements.h" 39 | 40 | void 41 | tds_sleep_s(unsigned sec) 42 | { 43 | #ifdef _WIN32 44 | Sleep(sec * 1000u); 45 | #else 46 | sleep(sec); 47 | #endif 48 | } 49 | 50 | void 51 | tds_sleep_ms(unsigned ms) 52 | { 53 | #ifdef _WIN32 54 | Sleep(ms); 55 | #elif defined(HAVE_NANOSLEEP) 56 | struct timespec ts = { ms / 1000u, (ms % 1000u) * 1000000lu }, rem; 57 | int r; 58 | 59 | for (;;) { 60 | r = nanosleep(&ts, &rem); 61 | if (!r || errno != EINTR) 62 | break; 63 | ts = rem; 64 | } 65 | #elif defined(HAVE_USLEEP) 66 | usleep(ms * 1000u); 67 | #else 68 | struct pollfd fd; 69 | poll(&fd, 0, ms); 70 | #endif 71 | } 72 | -------------------------------------------------------------------------------- /src/replacements/strlcat.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 2005 Ziglio Frediano 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #if HAVE_STRING_H 23 | #include 24 | #endif /* HAVE_STRING_H */ 25 | 26 | #include 27 | #include "replacements.h" 28 | 29 | size_t 30 | tds_strlcat(char *dest, const char *src, size_t len) 31 | { 32 | size_t dest_len = strlen(dest); 33 | size_t src_len = strlen(src); 34 | 35 | if (len) { 36 | --len; 37 | if (dest_len + src_len > len) { 38 | if (len > dest_len) { 39 | memcpy(dest + dest_len, src, len - dest_len); 40 | dest[len] = 0; 41 | } 42 | } else { 43 | memcpy(dest + dest_len, src, src_len + 1); 44 | } 45 | } 46 | return dest_len + src_len; 47 | } 48 | -------------------------------------------------------------------------------- /src/replacements/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 2005 Ziglio Frediano 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #if HAVE_STRING_H 23 | #include 24 | #endif /* HAVE_STRING_H */ 25 | 26 | #include 27 | #include "replacements.h" 28 | 29 | size_t 30 | tds_strlcpy(char *dest, const char *src, size_t len) 31 | { 32 | size_t l = strlen(src); 33 | 34 | if (len) { 35 | --len; 36 | if (l > len) { 37 | memcpy(dest, src, len); 38 | dest[len] = 0; 39 | } else { 40 | memcpy(dest, src, l + 1); 41 | } 42 | } 43 | return l; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/replacements/strtok_r.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strtok_r(3) 3 | * 20020927 entropy@tappedin.com 4 | * public domain. no warranty. use at your own risk. have a nice day. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #if HAVE_STRING_H 13 | #include 14 | #endif /* HAVE_STRING_H */ 15 | 16 | #include 17 | #include "replacements.h" 18 | 19 | char * 20 | tds_strtok_r(char *str, const char *sep, char **lasts) 21 | { 22 | char *p; 23 | 24 | if (str == NULL) { 25 | str = *lasts; 26 | } 27 | if (str == NULL) { 28 | return NULL; 29 | } 30 | str += strspn(str, sep); /* skip any separators */ 31 | if ((p = strpbrk(str, sep)) != NULL) { 32 | *lasts = p + 1; 33 | *p = '\0'; 34 | } else { 35 | if (!*str) 36 | str = NULL; 37 | *lasts = NULL; 38 | } 39 | return str; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/replacements/unittests/.gitignore: -------------------------------------------------------------------------------- 1 | mutex1 2 | condition 3 | strings 4 | passarg 5 | strtok_r 6 | -------------------------------------------------------------------------------- /src/replacements/unittests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | foreach(target mutex1 condition strings passarg strtok_r) 2 | add_executable(r_${target} ${target}.c) 3 | set_target_properties(r_${target} PROPERTIES OUTPUT_NAME ${target}) 4 | target_link_libraries(r_${target} replacements ${lib_BASE}) 5 | endforeach(target) 6 | -------------------------------------------------------------------------------- /src/replacements/unittests/Makefile.am: -------------------------------------------------------------------------------- 1 | TESTS = mutex1$(EXEEXT) condition$(EXEEXT) strings$(EXEEXT) passarg$(EXEEXT) \ 2 | strtok_r$(EXEEXT) 3 | check_PROGRAMS = $(TESTS) 4 | 5 | mutex1_SOURCES = mutex1.c 6 | condition_SOURCES = condition.c 7 | strings_SOURCES = strings.c 8 | passarg_SOURCES = passarg.c 9 | strtok_r_SOURCES = strtok_r.c 10 | 11 | AM_CPPFLAGS = -I$(top_srcdir)/include -I$(srcdir)/.. -I../ 12 | LIBS = ../../replacements/libreplacements.la $(NETWORK_LIBS) 13 | EXTRA_DIST = CMakeLists.txt 14 | 15 | -------------------------------------------------------------------------------- /src/replacements/unittests/passarg.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 2014 Frediano Ziglio 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | #undef NDEBUG 20 | #include 21 | 22 | #include 23 | 24 | #if HAVE_STDLIB_H 25 | #include 26 | #endif /* HAVE_STDLIB_H */ 27 | 28 | #ifdef HAVE_UNISTD_H 29 | #include 30 | #endif 31 | 32 | #include 33 | 34 | #include 35 | 36 | #include "replacements.h" 37 | 38 | int main(void) 39 | { 40 | FILE *f; 41 | char *pwd = strdup("password"); 42 | char *p; 43 | 44 | p = tds_getpassarg(pwd); 45 | assert(p); 46 | assert(strcmp(pwd, "********") == 0); 47 | assert(strcmp(p, "password") == 0); 48 | free(p); 49 | free(pwd); 50 | 51 | f = fopen("passarg.in", "w"); 52 | assert(f); 53 | fputs("line1pwd\nline2pwd\n", f); 54 | fclose(f); 55 | 56 | f = freopen("passarg.in", "r", stdin); 57 | assert(f); 58 | 59 | p = tds_getpassarg("-"); 60 | assert(p); 61 | assert(strcmp(p, "line1pwd") == 0); 62 | free(p); 63 | 64 | unlink("passarg.in"); 65 | 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/server/.gitignore: -------------------------------------------------------------------------------- 1 | tdssrv 2 | -------------------------------------------------------------------------------- /src/server/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am,v 1.18 2011-06-08 09:25:53 freddy77 Exp $ 2 | AM_CPPFLAGS = -I$(top_srcdir)/include 3 | noinst_LTLIBRARIES = libtdssrv.la 4 | libtdssrv_la_SOURCES= query.c server.c login.c 5 | libtdssrv_la_LIBADD = ../tds/libtds.la ../replacements/libreplacements.la $(LTLIBICONV) $(FREETDS_LIBGCC) 6 | noinst_PROGRAMS = tdssrv 7 | tdssrv_LDADD = libtdssrv.la $(LTLIBICONV) 8 | tdssrv_SOURCES = unittest.c 9 | -------------------------------------------------------------------------------- /src/tds/.gitignore: -------------------------------------------------------------------------------- 1 | num_limits.h 2 | sybase_character_sets.h 3 | tds_willconvert.h 4 | encodings.h 5 | tds_types.h 6 | 7 | -------------------------------------------------------------------------------- /src/tds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(unittests) 2 | 3 | if(PERL_FOUND AND NOT EXISTS "${CMAKE_SOURCE_DIR}/configure") 4 | # get name of null device 5 | set(NULLNAME "/dev/null") 6 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 7 | set(NULLNAME "NUL:") 8 | endif(CMAKE_SYSTEM_NAME STREQUAL "Windows") 9 | 10 | add_custom_command(OUTPUT tds_willconvert.h 11 | COMMAND ${PERL_EXECUTABLE} tds_willconvert.pl ../../include/freetds/proto.h > tds_willconvert.h 12 | MAIN_DEPENDENCY tds_willconvert.pl 13 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) 14 | add_custom_command(OUTPUT encodings.h 15 | COMMAND ${PERL_EXECUTABLE} encodings.pl . > encodings.h 2> ${NULLNAME} 16 | MAIN_DEPENDENCY encodings.pl 17 | DEPENDS alternative_character_sets.h 18 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) 19 | add_custom_command(OUTPUT num_limits.h 20 | COMMAND ${PERL_EXECUTABLE} num_limits.pl > num_limits.h 21 | MAIN_DEPENDENCY num_limits.pl 22 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) 23 | add_custom_command(OUTPUT tds_types.h 24 | COMMAND ${PERL_EXECUTABLE} types.pl ../../misc/types.csv ../../include/freetds/proto.h > tds_types.h 25 | MAIN_DEPENDENCY types.pl 26 | DEPENDS ../../misc/types.csv ../../include/freetds/proto.h 27 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) 28 | endif(PERL_FOUND AND NOT EXISTS "${CMAKE_SOURCE_DIR}/configure") 29 | 30 | if(WIN32) 31 | set(add_SRCS sspi.c md5.c) 32 | else(WIN32) 33 | set(add_SRCS challenge.c md4.c md5.c des.c gssapi.c hmac_md5.c) 34 | endif(WIN32) 35 | 36 | add_library(tds STATIC 37 | mem.c token.c util.c login.c read.c 38 | write.c convert.c numeric.c config.c query.c iconv.c 39 | locale.c threadsafe.c vstrbuild.c 40 | tdsstring.c getmac.c data.c net.c tls.c 41 | tds_checks.c log.c 42 | bulk.c packet.c stream.c random.c 43 | sec_negotiate_gnutls.h sec_negotiate_openssl.h sec_negotiate.c 44 | tds_willconvert.h encodings.h num_limits.h tds_types.h 45 | ${add_SRCS} 46 | ) 47 | if (NOT WIN32) 48 | set_target_properties(tds PROPERTIES COMPILE_FLAGS -fPIC) 49 | endif() 50 | -------------------------------------------------------------------------------- /src/tds/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = . unittests 3 | AM_CPPFLAGS = -I$(top_srcdir)/include 4 | 5 | noinst_LTLIBRARIES = libtds.la 6 | if HAVE_SSPI 7 | AUTH_FILES_DIST = challenge.c md4.c md5.c des.c gssapi.c hmac_md5.c 8 | AUTH_FILES = sspi.c 9 | else 10 | AUTH_FILES = challenge.c md4.c md5.c des.c gssapi.c hmac_md5.c 11 | AUTH_FILES_DIST = sspi.c 12 | endif 13 | libtds_la_SOURCES= mem.c token.c util.c login.c read.c \ 14 | write.c convert.c numeric.c config.c query.c iconv.c \ 15 | locale.c threadsafe.c vstrbuild.c \ 16 | tdsstring.c getmac.c data.c net.c tls.c \ 17 | tds_checks.c log.c dlist.c \ 18 | bulk.c packet.c stream.c random.c \ 19 | sec_negotiate_gnutls.h sec_negotiate_openssl.h sec_negotiate.c \ 20 | $(AUTH_FILES) 21 | libtds_la_LDFLAGS= 22 | libtds_la_LIBADD = $(NETWORK_LIBS) 23 | 24 | noinst_HEADERS = tds_willconvert.h encodings.h num_limits.h tds_types.h 25 | EXTRA_DIST = tds_willconvert.h encodings.h num_limits.h tds_types.h \ 26 | CMakeLists.txt $(AUTH_FILES_DIST) 27 | 28 | # Perl is needed to build from a repository checkout. 29 | # Perl is *not* needed to build from a tarball. 30 | 31 | ## We have to build num_limits.h because automake can't infer the 32 | ## dependency (on num_limits.pl). 33 | 34 | data.c: tds_types.h 35 | 36 | if HAVE_PERL_SOURCES 37 | BUILT_SOURCES = tds_willconvert.h encodings.h num_limits.h tds_types.h 38 | 39 | clean-local: 40 | cd $(srcdir) && rm -f $(BUILT_SOURCES) 41 | 42 | tds_willconvert.h: tds_willconvert.pl Makefile 43 | perl $(srcdir)/tds_willconvert.pl $(top_srcdir)/include/freetds/proto.h > $@.tmp 44 | mv $@.tmp $@ 45 | 46 | encodings.h: encodings.pl alternative_character_sets.h Makefile 47 | perl $(srcdir)/encodings.pl $(srcdir) > $@.tmp 2> /dev/null 48 | mv $@.tmp $@ 49 | 50 | num_limits.h: num_limits.pl Makefile 51 | perl $(srcdir)/num_limits.pl > $@.tmp 52 | mv $@.tmp $@ 53 | 54 | tds_types.h: types.pl Makefile $(top_srcdir)/misc/types.csv 55 | perl $(srcdir)/types.pl $(top_srcdir)/misc/types.csv $(top_srcdir)/include/freetds/proto.h > $@.tmp 56 | mv $@.tmp $@ 57 | endif 58 | -------------------------------------------------------------------------------- /src/tds/dlist.c: -------------------------------------------------------------------------------- 1 | /* Dlist - dynamic list 2 | * Copyright (C) 2016 Frediano Ziglio 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #if ENABLE_EXTRA_CHECKS 25 | void dlist_ring_check(dlist_ring *ring) 26 | { 27 | const dlist_ring *item = ring; 28 | do { 29 | assert(item->prev->next == item); 30 | assert(item->next->prev == item); 31 | item = item->next; 32 | } while (item != ring); 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /src/tds/example/token2.c: -------------------------------------------------------------------------------- 1 | if ((ret = tds_process_row_tokens(dbproc->tds_socket, &rowtype)) 2 | == TDS_SUCCESS) { 3 | if (rowtype == TDS_REG_ROW) { 4 | /* Add the row to the row buffer */ 5 | resinfo = tds->current_results; 6 | buffer_add_row(&(dbproc->row_buf), resinfo->current_row, 7 | resinfo->row_size); 8 | result = REG_ROW; 9 | } else if (rowtype == TDS_COMP_ROW) { 10 | /* Add the row to the row buffer */ 11 | resinfo = tds->current_results; 12 | buffer_add_row(&(dbproc->row_buf), resinfo->current_row, 13 | resinfo->row_size); 14 | result = tds->current_results->computeid; 15 | } else 16 | result = FAIL; 17 | } else if (ret == TDS_NO_MORE_ROWS) { 18 | result = NO_MORE_ROWS; 19 | } else 20 | result = FAIL; 21 | -------------------------------------------------------------------------------- /src/tds/random.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998-1999 Brian Bruns 3 | * Copyright (C) 2005-2015 Frediano Ziglio 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Library General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Library General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | * Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include 22 | 23 | #if HAVE_STDLIB_H 24 | #include 25 | #endif /* HAVE_STDLIB_H */ 26 | 27 | #include 28 | 29 | #ifdef HAVE_GNUTLS 30 | #include 31 | #include 32 | #ifndef HAVE_GNUTLS_RND 33 | #include 34 | #endif 35 | #elif defined(HAVE_OPENSSL) 36 | #include 37 | #endif 38 | 39 | void 40 | tds_random_buffer(unsigned char *out, int len) 41 | { 42 | int i; 43 | 44 | #if defined(HAVE_GNUTLS) && defined(HAVE_GNUTLS_RND) 45 | if (gnutls_rnd(GNUTLS_RND_RANDOM, out, len) >= 0) 46 | return; 47 | if (gnutls_rnd(GNUTLS_RND_NONCE, out, len) >= 0) 48 | return; 49 | #elif defined(HAVE_GNUTLS) 50 | void *p = gcry_random_bytes(len, GCRY_STRONG_RANDOM); 51 | if (p) { 52 | memcpy(out, p, len); 53 | free(p); 54 | return; 55 | } 56 | #elif defined(HAVE_OPENSSL) 57 | if (RAND_bytes(out, len) == 1) 58 | return; 59 | if (RAND_pseudo_bytes(out, len) >= 0) 60 | return; 61 | #endif 62 | 63 | /* TODO find a better random... */ 64 | for (i = 0; i < len; ++i) 65 | out[i] = rand() / (RAND_MAX / 256); 66 | } 67 | -------------------------------------------------------------------------------- /src/tds/unittests/.gitignore: -------------------------------------------------------------------------------- 1 | t0001 2 | t0002 3 | t0003 4 | t0004 5 | t0005 6 | t0006 7 | t0007 8 | t0008 9 | tdsdump.out 10 | dynamic1 11 | convert 12 | dataread 13 | flags 14 | utf8_1 15 | utf8_2 16 | utf8_3 17 | numeric 18 | iconv_fread 19 | toodynamic 20 | challenge 21 | readconf 22 | charconv 23 | nulls 24 | collations 25 | corrupt 26 | -------------------------------------------------------------------------------- /src/tds/unittests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(..) 2 | 3 | add_library(t_common STATIC common.c common.h utf8.c) 4 | 5 | if(NOT WIN32) 6 | set(unix_TESTS challenge) 7 | endif(NOT WIN32) 8 | 9 | foreach(target t0001 t0002 t0003 t0004 t0005 t0006 t0007 t0008 dynamic1 10 | convert dataread utf8_1 utf8_2 utf8_3 numeric iconv_fread toodynamic 11 | readconf collations corrupt ${unix_TESTS}) 12 | add_executable(t_${target} EXCLUDE_FROM_ALL ${target}.c) 13 | set_target_properties(t_${target} PROPERTIES OUTPUT_NAME ${target}) 14 | target_link_libraries(t_${target} t_common tds replacements ${lib_NETWORK} ${lib_BASE}) 15 | if(NOT ${target} STREQUAL "collations") 16 | add_test(NAME t_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${target}) 17 | endif() 18 | add_dependencies(check t_${target}) 19 | endforeach(target) 20 | -------------------------------------------------------------------------------- /src/tds/unittests/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_h 2 | #define COMMON_h 3 | 4 | #undef NDEBUG 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #if HAVE_STDLIB_H 11 | #include 12 | #endif /* HAVE_STDLIB_H */ 13 | 14 | #if HAVE_STRING_H 15 | #include 16 | #endif /* HAVE_STRING_H */ 17 | 18 | #include 19 | #include 20 | 21 | #define FREETDS_SRCDIR FREETDS_TOPDIR "/src/tds/unittests" 22 | 23 | extern char PASSWORD[512]; 24 | extern char USER[512]; 25 | extern char SERVER[512]; 26 | extern char DATABASE[512]; 27 | extern char CHARSET[512]; 28 | 29 | extern TDSCONTEXT *test_context; 30 | 31 | int try_tds_login(TDSLOGIN ** login, TDSSOCKET ** tds, const char *appname, int verbose); 32 | int try_tds_logout(TDSLOGIN * login, TDSSOCKET * tds, int verbose); 33 | 34 | int run_query(TDSSOCKET * tds, const char *query); 35 | 36 | extern int utf8_max_len; 37 | 38 | int get_unichar(const char **psrc); 39 | char *to_utf8(const char *src, char *dest); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/tds/unittests/readconf.in: -------------------------------------------------------------------------------- 1 | [section1] 2 | opt1=value1 3 | 4 | [SECTION2] 5 | opt two=value2 6 | 7 | [Section 3] 8 | opt three = value three 9 | 10 | -------------------------------------------------------------------------------- /src/tds/unittests/t0001.c: -------------------------------------------------------------------------------- 1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases 2 | * Copyright (C) 1998-1999 Brian Bruns 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | /* 21 | * Just connect to server and disconnect 22 | */ 23 | #include "common.h" 24 | 25 | int 26 | main(int argc, char **argv) 27 | { 28 | TDSLOGIN *login; 29 | TDSSOCKET *tds; 30 | int ret; 31 | int verbose = 0; 32 | 33 | fprintf(stdout, "%s: Testing login, logout\n", __FILE__); 34 | ret = try_tds_login(&login, &tds, __FILE__, verbose); 35 | if (ret != TDS_SUCCESS) { 36 | fprintf(stderr, "try_tds_login() failed\n"); 37 | return 1; 38 | } 39 | 40 | try_tds_logout(login, tds, verbose); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /tds.dox: -------------------------------------------------------------------------------- 1 | #$Id: tds.dox,v 1.9 2005-06-26 14:25:19 jklowden Exp $ 2 | PROJECT_NAME = "FreeTDS API" 3 | OUTPUT_DIRECTORY = doc/reference 4 | GENERATE_LATEX = NO 5 | GENERATE_MAN = NO 6 | GENERATE_RTF = NO 7 | CASE_SENSE_NAMES = NO 8 | INPUT = $(SRCDIR)/src \ 9 | $(SRCDIR)/include \ 10 | $(SRCDIR)/win32 \ 11 | $(SRCDIR)/vms 12 | EXCLUDE_PATTERNS = */unittests/* 13 | RECURSIVE = YES 14 | QUIET = YES 15 | SHORT_NAMES = YES 16 | JAVADOC_AUTOBRIEF = YES 17 | PREDEFINED = HAVE_SSL 18 | INTERNAL_DOCS = YES 19 | EXAMPLE_PATH = $(SRCDIR)/src/tds/example 20 | SORT_BRIEF_DOCS = YES 21 | EXTRACT_STATIC = YES 22 | ALIASES += tds="@param tds A pointer to the TDSSOCKET structure managing a client/server operation." 23 | ALIASES += commit{1}="commit id \1" 24 | 25 | CALL_GRAPH = YES 26 | CALLER_GRAPH = YES 27 | HAVE_DOT = YES 28 | MAX_DOT_GRAPH_DEPTH = 3 29 | DOT_IMAGE_FORMAT = svg 30 | -------------------------------------------------------------------------------- /vms/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = config_h.vms configure.com edit.c descrip_mms.template \ 2 | getpass.c libodbc.opt odbc_driver_axp.opt README.vms \ 3 | vargdefs.h vmsarg_command_bcp.cld vmsarg_command_defncopy.cld \ 4 | vmsarg_command_isql.cld vmsarg_mapping_bcp.c \ 5 | vmsarg_mapping_defncopy.c vmsarg_mapping_isql.c \ 6 | vmsarg_parse.c 7 | 8 | clean: 9 | -------------------------------------------------------------------------------- /vms/libodbc.opt: -------------------------------------------------------------------------------- 1 | LIBODBC/Shareable 2 | -------------------------------------------------------------------------------- /win32/.gitignore: -------------------------------------------------------------------------------- 1 | freetds.nsh 2 | -------------------------------------------------------------------------------- /win32/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = initnet.c \ 2 | freetds/sysconfdir.h \ 3 | freetds.nsh freetds.nsh.in \ 4 | installfreetds.bat freetds.nsi 5 | -------------------------------------------------------------------------------- /win32/freetds.nsh.in: -------------------------------------------------------------------------------- 1 | !define PRODUCT_VERSION "@VERSION@" 2 | -------------------------------------------------------------------------------- /win32/freetds/sysconfdir.h: -------------------------------------------------------------------------------- 1 | #define FREETDS_SYSCONFDIR "c:" 2 | -------------------------------------------------------------------------------- /win32/initnet.c: -------------------------------------------------------------------------------- 1 | #if defined(_MSC_VER) && defined(_DEBUG) 2 | #define _CRTDBG_MAP_ALLOC 3 | #include 4 | #include 5 | #endif 6 | 7 | #include 8 | 9 | #ifdef DLL_EXPORT 10 | 11 | HINSTANCE hinstFreeTDS; 12 | 13 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); 14 | 15 | BOOL WINAPI 16 | DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 17 | { 18 | WSADATA wsaData; 19 | 20 | hinstFreeTDS = hinstDLL; 21 | switch (fdwReason) { 22 | case DLL_PROCESS_ATTACH: 23 | #if defined(_MSC_VER) && defined(_DEBUG) 24 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); 25 | _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT); 26 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); 27 | _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT); 28 | _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); 29 | _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT); 30 | _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 31 | #endif 32 | 33 | if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) 34 | return FALSE; 35 | 36 | DisableThreadLibraryCalls(hinstDLL); 37 | break; 38 | 39 | case DLL_PROCESS_DETACH: 40 | #if defined(_MSC_VER) && defined(_DEBUG) 41 | _CrtDumpMemoryLeaks(); 42 | #endif 43 | break; 44 | } 45 | return TRUE; 46 | } 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /win32/installfreetds.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM This shell script installs the FreeTDS ODBC driver 3 | set dest=%windir%\System 4 | IF EXIST %windir%\System32\ODBCCONF.exe SET dest=%windir%\System32 5 | ECHO Installing to %dest% 6 | COPY /Y Debug\FreeTDS.dll %dest%\FreeTDS.dll 7 | CD %dest% 8 | regsvr32 FreeTDS.dll 9 | --------------------------------------------------------------------------------