Coder Social home page Coder Social logo

freetds / freetds Goto Github PK

View Code? Open in Web Editor NEW
456.0 456.0 154.0 15.23 MB

Official FreeTDS repository

Home Page: http://www.freetds.org/

License: GNU General Public License v2.0

Shell 1.61% C 91.99% Perl 0.83% PHP 0.22% CMake 0.85% NSIS 0.07% DIGITAL Command Language 0.32% Batchfile 0.09% PowerShell 0.03% Makefile 0.68% M4 2.09% Roff 0.16% TSQL 1.03% Python 0.02%

freetds's Introduction

README for FreeTDS 1.5.dev (development)

Release date TBD

To build FreeTDS read the file INSTALL or the FreeTDS Users Guide

FreeTDS is a free implementation of Sybase's DB-Library, CT-Library, and ODBC libraries. FreeTDS builds and runs on every flavor of unix-like systems we've heard of (and some we haven't) as well as Win32 (with or without Cygwin), VMS, and Mac OS X. Failure to build on your system is probably considered a bug. It has C language bindings, and works also with Perl and PHP, among others.

FreeTDS is licensed under the GNU LGPL license. See COPYING_LIB.txt for details.

Other files you might want to peruse:

  • AUTHORS Who's involved
  • NEWS Summary of feature changes and fixes
  • TODO The roadmap, such as it is

Also, api_status shows which functions are implemented.

For details on what's new in this version, see NEWS. For unbearable detail, see git log.

Documentation

A User Guide, in XML and HTML form, is included in this distribution. Also included is a reference manual, generated in HTML with Doxygen. "make install" installs the HTML documentation, by default to /usr/local/share/doc/freetds-.

Note to Users

Submissions of test programs (self-contained programs that demonstrate functionality or problems) are greatly appreciated. They should create any tables needed (since we obviously don't have access to your database) and populate them. Unit tests for any of the libraries is appreciated

Notes to Developers

The code is split into several pieces.

  1. tds directory is the wire level stuff, it should be independent of the library using it, this will allow db-lib, ct-lib, and ODBC to sit on top.

  2. db-lib directory. This is the actual db-lib code which runs on top of tds.

  3. ct-lib directory. This is the ct-lib code which runs on top of tds.

  4. server directory. This will be a set of server routines basically to impersonate a dataserver, functions like send_login_ack() etc...

  5. odbc directory. ODBC implementation over tds. Uses iODBC or unixODBC as a driver manager. You need to have one of those if you are using the ODBC CLI.

  6. unittests directories. Test harness code for ct-lib, db-lib, ODBC and libtds.

  7. samples directories. Sample code for getting started with Perl, PHP, etc...

  8. pool directory. A connection pooling server for TDS. Useful if you have a connection limited license. Needs some hacking to get configured but is quite stable once configured correctly. Contact the list if interested in how to use it.

Please look at doc/getting_started.txt for a description of what is going on in the code.

Side note: Brian, as many free software authors, appreciates postcards from all over. So if you live someplace neat (read: not Michigan) and want to send one, email him ([email protected]) for his current snail mail address.

freetds's People

Contributors

alltilla avatar blieusong avatar brandonfoong avatar brianb avatar craigberry avatar dawsonlp avatar denisenkom avatar detule avatar fandrieu avatar freddy77 avatar hankinsoft avatar jalegido avatar jefarr avatar jklowden avatar john-kendall avatar klebertarcisio avatar lacak-sk avatar larskanis avatar maharmstone avatar marsupilami79 avatar mlilback avatar msabramo avatar orlitzky avatar peteralexharvey avatar ramiro avatar ravualhemio avatar sergeysatskiy avatar termim avatar ucko avatar vorlonofportland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

freetds's Issues

tdspool and 20017 Unexpected EOF from the server

Hello @freddy77 !
We are mirgating to tdspool on production. Everything works fine and thank you for you great work!
But today i got strange errors
SQLSTATE[01002]: Disconnect error: 20017 Unexpected EOF from the server [20017](severity 9) [(null)]
when try to execute query (testing with insert and update) with huge amount of text in one field (~100k symbols).
In sql server logs (2014 sql server) i see:

Date 01.07.2016 16:39:36
Log SQL Server (Current - 30.06.2016 17:59:00)
Source spid180
Message
Error: 4014, Severity: 20, State: 17.

Date 01.07.2016 16:39:36
Log SQL Server (Current - 30.06.2016 17:59:00)
Source spid180
Message
A fatal error occurred while reading the input stream from the network. The session will be terminated (input error: 0, output error: 0).

Over queries executed successfuly in this time. I restarted tdspool and problem was gone.
Do you have any ideas what's the problem?

I try to reproduce this error now but cann't>.< I think the problem appear after some hours / days tdspool work. I enabled dump and wating now.

It's only one problem that we got after migrating to tdspool on production. It works stable without any crashes. We are using it with centos 6, php-fpm 5.5 and 2014 sql server.

Geometry Column

Hello,

I would like to know how to perform a geometry query. All table data are returned except the geometry .

My settings:

Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes

Ex: SELECT ogr_geometry.STAsText ( ) FROM regioes_2010

Thanks

UTF-8 without ICONV returns wrong byte sequences

Hello,

I compiled FreeTDS using Cmake and Visual Studio 2013. For testing I generated sequences of random characters. One of those sequences is: Ē洅乕ཥ깳몊䚣ഒ컭閥

I used SQL Server Management Studio on SQL Express 2008R2 to insert this sequence. When fetching it from the database and setting freetds to use UTF-8 by calling dbSetLCharSet(LoginRec, "UTF-8") a freetds with ICONV support returns the following correct byte sequence:
C4 92 E6 B4 85 E4 B9 95 E0 BD A5 EA B9 B3 EB AA 8A E4 9A A3 E0 B4 92 EC BB AD E9 96 A5
If I use a FreeTDS without ICONV support, I get the following incorrect byte sequence:
C4 92 E6 B4 85 E4 B9 95 E1 FD A5 EA B9 B3 EB AA 8A E4 9A A3 E6 F4 92 EC BB AD E9 96 A5

I can only assume that the iconv.c in the replacements is somehow faulty.

LC_MONETARY / money format in freetds

Hello @freddy77 !
Could you explain me some information about using system locale LC_MONETARY setting by freetds / tdspool?
We faced with issue that tdspool do not use correct money format stored in system locale setting. We want to use ru_RU.utf8 locale and russian money format, i try to set this locale at the system / added new section locales.conf / etc but it didn't help - money format is wrong. Any ways to change this setting in freetds / tdspool or we need to use specific format functions on php side?

Thank you in advance!

bsqldb throws an error if the "go" command does not start in the first column

We have a deployment tool that uses bsqldb to run sql scripts to import data into SQL Server databases.

The issue is that some teams use SQL Developer to test their scripts and SQL Developer is ok with leading white spaces before the “go” command, but bsqldb is not ok so the deployment throws an error.

Below is a snippet containing the fix I made locally to the next_query() func in bsqldb.c:
(I just don't know how to incorporate this fix into your system)

while (fgets(query_line, sizeof(query_line), stdin)) {
    /* 'go' or 'GO' separates command batches */
    const char *p = query_line;

    while(isspace((unsigned char) *p)) p++;  /* Skip past leading white spaces */

    if (strncasecmp(p, "go", 2) == 0) {
        for (p+=2; isspace((unsigned char) *p); p++) {
            if (*p == '\n')
                return 1;
        }
    }

    fprintf(options.verbose, "\t%s", query_line);

    /* Add the query line to the command to be sent to the server */
    erc = dbcmd(dbproc, query_line);
    if (erc == FAIL) {
        fprintf(stderr, "%s:%d: dbcmd() failed\n", options.appname, __LINE__);
        return -1;
    }
}

0.95 Segfaulting on Multiple result sets.

After upgrading to 0.95 from 0.91, freetds segfaults when trying to get multiple result sets from MsSQL.

---------------------------------------
/private/tmp/php5420150921-73717-29hep5/php-5.4.45/ext/pdo/pdo_stmt.c(2074) : Block 0x7ff422688298 status:
Invalid pointer: ((thread_id=0x33380002) != (expected=0x74191310))
Segmentation fault: 11

Example script to cause the segfault with PHP:

<?php
require_once("dbinfo.php");
//putenv('FREETDSCONF=/opt/local/etc/freetds/freetds.conf');

$pdo = new PDO("dblib:host=" . DB_HOST . ";dbname=" . DB_NAME . ';charset=UTF-8', DB_USER, DB_PASS);

$multipleresults = "SELECT 1; SELECT 2; SELECT 3;";

$stmt = $pdo->prepare($multipleresults);

print "Executing SQL: '{$multipleresults}'\n";
$stmt->execute();

print "Looping through results. Should segfault on nextRowset\n";
do {
    print_r($stmt->fetchAll());
} while ($stmt->nextRowset());

print "Complete.\n";

Incorrect work of JOIN clause

create foreign table ms_tables (
tab_name varchar(128),
col_name varchar(128),
typ_name varchar(128),
len smallint
)
server fs_rc
options (query '
select so.name as tab_name, sc.name as col_name, st.name as typ_name, sc.length as len
from sysobjects so
join syscolumns sc on sc.id = so.id
join systypes st on st.xtype = sc.xtype
where so.xtype = ''U''
order by so.name, sc.colid;
');

select count (1) from ms_tables; -- 109 rows

select count (1) -- 16 rows
from information_schema.tables t
where table_schema = 'dbo'
and table_type = 'BASE TABLE';

select count (1) -- 12 rows
from information_schema.tables t
join ms_tables m on lower (m.tab_name) = lower (t.table_name)
where table_schema = 'dbo'
and table_type = 'BASE TABLE';

select count (1) -- 103 rows
from information_schema.tables t
full join ms_tables m on lower (m.tab_name) = lower (t.table_name)
where table_schema = 'dbo'
and table_type = 'BASE TABLE';

The schema dbo has 16 same table names on both sides. but join see 1 the same table name only!

The full join sees all 16 table names but simple join see the same quantity.

Postgres 9.6.1, tds_fdw-1.0.8, MS SQL 2008R2.

Unable to validate TLS hostname

When attempting to make a connection to a SQL Server and providing a CA Cert file, FreeTDS appears to be unable to validate a hostname (e.g. returns that differing hostnames are valid and exact hostnames are invalid). We tracked this down to the function check_name_match in tls.c on line 765.

That if-statement will set the return value to 1 if the lengths match and check_wildcard returns 0. However, check_wildcard returns 1 on success and 0 on failure, so this check will cause the function check_name_match to return a 1 on failure and 0 on success. Which ultimately causes the check_hostname call in tds_ssl_init on line 964 to incorrectly evaluate a successful match as failure (and vice versa).

In order to fix this, I believe that check_name_match should be checking to make sure check_wildcard is 1 (not 0):

if (strlen(name_utf8) == name_len && check_wildcard(name_utf8, hostname) == 1)
	ret = 1;

Build guide incorrect or incomplete

I've tried to build FreeTDS on centos for a docker image following the latest documentation here. I should execute ./configure which isn't included the repository.

autoconf reports a couple of errors (possibly undefined macros) and the generated configure script fails with a syntax error:

[freetds-R1_00RC5]# ./configure
./configure: line 2528: syntax error near unexpected token `dist-bzip2'
./configure: line 2528: `AM_INIT_AUTOMAKE(dist-bzip2 parallel-tests subdir-objects)'

ftp.freetds.org appears to be down

At least since Friday morning, I've been getting a "Resource temporarily unavailable" response trying to fetch the latest stable source.

tdspool segfault

Hello @freddy77 !
I've got another bug with tdspool :) it crash periodicaly. You can find core-dump and tdspool binary in the attachment.
tdspool_segfault.zip

Hope this helps for understanding the problem.
V.

TLS - intermittent bad_record_MAC error when connecting to MSSQL 2008 or 2012

Possibly related to MS KB3172605, using gnutls as default with freetds results in a bad_record_mac TLS error that is annoyingly intermittent.

Details of this and a related problem and various troubleshooting are described here: http://stackoverflow.com/questions/38485313/freetds-fails-to-connect-to-sql-server-after-recent-windows-patches-and-tls1-bei

For 1.00 freetds versions, I was able to get around this by leaving out --with-gnutls from configure and including --with-openssl=yes but that only works for RHEL6, not RHEL5. Interestingly, 0.82 when compiled from source on RHEL6 doesn't exhibit this problem with the default configuration options.

Using latest version of FreeTDS, I am getting Error 20020 (severity 9), when the older versions work just fine

Platform: openSUSE Leap 42.1 (x86_64)
FreeTDS version: freetds v1.00.9
Connecting to: Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
versions Tried couple of different versions <= 0.95.95 and 1.00.9

I am trying tsql to connect to a MS SQL Server to retrieve some data. When I try with version <= 0.95.95 it is working fine. But with the latest version 1.00.9, I am getting an error.

tsql -H xxxxxxx -U xxxxxxxxxxxxx -p 1433
[TinyTds][v1.0.5][tsql]: /usr/local/bin/tsql
Password: 
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"

2> USE yyyyyyyyyy
3> GO
1> Select C.CustomerID, ISNULL(C.TreeRepCode, P.RepCode) RepCode, P.FirstName, P.LastName, P.Headline, P.PhoneNumber, 
2>       P.Email, P.Occupation, P.Interest, P.Education, P.Story, P.Why, P.Gender, P.Relationship, P.Location, P.Hometown, 
3>       P.ModDate, P.Private, P.CompanyName, P.Birthday, P.MobileDisplay, VCM.WebPath AvatarPath, VCM.Name AvatarName,
4>       CWS.Twitter, CWS.Facebook, CWS.LinkedIn, CWS.YouTube, CWS.GooglePlus
5>       from .....BUNCH OF JOINS...... OFFSET 0 ROWS FETCH NEXT 2000 ROWS ONLY
6> GO

############################ After printing some rows, it prints
Error 2401 (severity 4):
        Character set conversion is not available between client character set '%.*s' and server character set '%.*s'
(1168 rows affected)
Error 20020 (severity 9):
        Bad token from the server: Datastream processing out of sync

The above tsql errors match with freetds log errors

stream.c:125:Error: tds_convert_stream: tds_iconv returned errno 22, conv_errno 22
stream.c:129:Error: tds_convert_stream: Gave up converting 2 bytes due to error 22.
stream.c:132:Troublesome bytes:
0000 3a df                  -                        |:.|

stream.c:125:Error: tds_convert_stream: tds_iconv returned errno 22, conv_errno 22
stream.c:129:Error: tds_convert_stream: Gave up converting 2 bytes due to error 22.
stream.c:132:Troublesome bytes:
0000 3a df                  -                        |:.|

util.c:322:tdserror(0x16586a50, 0x15a96080, 2401, 0)
dblib.c:7949:dbperror(0x1f78aca0, 2401, 0)

The row tsql is failing at, has the following in the columns. column-headers are between two *s, the column value are underneath it. The freetds.log said, it failed on interest column. It has things&#55356;� at the end (that could be a cause of concern)

*Occupation*
Registered Medical Assistant

*Interest*
I love to sew, read, work on my creative memory books, cook, bake, play casino games on my iPad , play bingo , work on crafts and many many other things&#55356;�

*Education*
Trade School

The column interest has the following metadata logged in freetds.log in the beginning

token.c:1507:tds7_get_data_info: 
        colname = Interest
        type = 39 (varchar)
        server's type = 231 (x UCS-2 varchar)
        column_varint_size = 8
        column_size = 2147483647 (1073741823 on server)
token.c:3160:adjust_character_column_size:
        Server charset: UTF-16LE
        Server column_size: 510
        Client charset: UTF-8
        Client column_size: 1020

The Bytes sequence from the freetds.log, corresponding to the end of the interest column-value is as follows. Each row has 16 bytes with a "-" after 8 bytes. On the right hand, we have equivalent characters, between pipes.

......
......
......
00 26 00 23 00 35 00 35-00 33 00 35 00 36 00 3b              |.&.#.5.5 .3.5.6.;|
00 3a df 00 00 00 00 18-00 54 00 72 00 61 00 64               |.:...... .T.r.a.d|
00 65 00 20 00 53 00 63-00 68 00 6f 00 6f 00 6c                |.e. .S.c .h.o.o.l|
......
......
......

In the final lines freetds dump, it was printing 3a df ----- trouble some bytes twice and failing right afterwards. It corresponds to the second line in the byte sequence.

00   -> #####second-byte of the previous utf-16 Character
26 00   ->  &.
23 00   ->  #.
35 00   ->  5.
35 00   ->  5.
33 00   ->  3.
35 00   ->  5.
36 00   ->  6.
3b 00   ->  ;.    # 00 from next line

TROUBLE Starts here
3a df  ->  invalid UTF+16LE? If so, can we just ignore it?

This used to work with older versions of freetds. Does this mean the new freetds, is more strict? Is there anyway to tell freetds to ignore any byte-conversion errors.

Errors With `defncopy` On v0.95.latest

I've never gotten the 0.95 defncopy binary to work where previously in 0.91 I have not had issues. My current setup is using SQL Server 2014 with a simple table. The error I keep seeing is:

Assertion failed: (ret >= 0), function print_ddl, file defncopy.c, line 511.

Missing odbc_export.h & tds_willconvert.h

Hello
I'm on Windows 8.1 64 bits I tried to build FreeTDS using CMake
and actually it seems these two files tds_willconvert.h and odbc_export.h are missing.
There is #include "tds_willconvert.h" in src\tds\convert.c line 3053
There is #include "odbc_export.h" in src\odbc\odbc.c line 7509
I cloned the repository yesterday using Sourcetree and cannot find these files...
Thank you in advance for your help
Philippe Roussel

When using FreeTDS .95 autocommit becomes enabled

Currently using pyodbc to make transactions.

Using FreeTDS .91-2, pyodbc would set autocommit to off, and the driver would respect it.

Seemingly, under FreeTDS 0.95.19 (shipped with CentOS 7) , once an initial commit is made, all further transactions are commit automatically. pyodbc shows autocommit turned off, but everything is commit by itself.

We are using the same exact codebase with the same version of pyodbc/python.

Any help would be appreciated. Thanks!

v0.95.65 Session Busy Errors After Error

This is in regards to the TinyTDS (Ruby C Extension) errors during our v0.95 upgrade. Basically after running some invalid SQL like SELECT * FROM [foobar] to generate an error, the re-use of the connection fails with.

The request failed to run because the batch is aborted, this can be caused by abort signal sent from client, or another request is running in the same session, which makes the session busy.

Our message/error handlers are the same between our working v0.91 code and v0.95. Perhaps you can take a look at this v0.95.65 dump file fragment to see if there is anything that could be a bug in FreeTDS?

dblib.c:1338:dbcmd(0x7fce5ab9bff0, SELECT * FROM [foobar])
dblib.c:1344:dbcmd() bufsz = 18
dblib.c:5845:dbfreebuf(0x7fce5ab9bff0)
dblib.c:6817:dbsqlsend(0x7fce5ab9bff0)
mem.c:648:tds_free_all_results()
util.c:165:Changed query state from IDLE to WRITING
util.c:165:Changed query state from WRITING to PENDING
packet.c:740:Sending packet
0000 01 01 00 4a 00 00 01 00-16 00 00 00 12 00 00 00 |...J.... ........|
0010 02 00 00 00 00 00 00 00-00 00 01 00 00 00 53 00 |........ ......S.|
0020 45 00 4c 00 45 00 43 00-54 00 20 00 2a 00 20 00 |E.L.E.C. T. .*. .|
0030 46 00 52 00 4f 00 4d 00-20 00 5b 00 66 00 6f 00 |F.R.O.M.  .[.f.o.|
0040 6f 00 62 00 61 00 72 00-5d 00                   |o.b.a.r. ].|

dblib.c:5743:dbgetuserdata(0x7fce5ab9bff0)
dblib.c:5743:dbgetuserdata(0x7fce5ab9bff0)
dblib.c:5743:dbgetuserdata(0x7fce5ab9bff0)
dblib.c:5743:dbgetuserdata(0x7fce5ab9bff0)
dblib.c:4625:dbsqlok(0x7fce5ab9bff0)
dblib.c:4654:dbsqlok() not done, calling tds_process_tokens()
token.c:549:tds_process_tokens(0x7fce5ab4ca90, 0x7fff5f584794, 0x7fff5f584790, 0x6914)
util.c:165:Changed query state from PENDING to READING
packet.c:639:Received packet
0000 04 01 00 6c 00 33 01 00-aa 54 00 d0 00 00 00 01 |...l.3.. ªT.Ð....|
0010 10 1d 00 49 00 6e 00 76-00 61 00 6c 00 69 00 64 |...I.n.v .a.l.i.d|
0020 00 20 00 6f 00 62 00 6a-00 65 00 63 00 74 00 20 |. .o.b.j .e.c.t. |
0030 00 6e 00 61 00 6d 00 65-00 20 00 27 00 66 00 6f |.n.a.m.e . .'.f.o|
0040 00 6f 00 62 00 61 00 72-00 27 00 2e 00 06 53 00 |.o.b.a.r .'....S.|
0050 53 00 32 00 30 00 31 00-34 00 00 01 00 00 00 fd |S.2.0.1. 4......ý|
0060 02 00 fd 00 00 00 00 00-00 00 00 00             |..ý..... ....|

token.c:564:processing result tokens.  marker is  aa(ERROR)
token.c:115:tds_process_default_tokens() marker is aa(ERROR)
token.c:2344:tds_process_msg() reading message 208 from server
token.c:2416:tds_process_msg() calling client msg handler
dbutil.c:76:_dblib_handle_info_message(0x7fce5ab845d0, 0x7fce5ab4ca90, 0x7fff5f584620)
dbutil.c:77:msgno 208: "Invalid object name 'foobar'."
dblib.c:5743:dbgetuserdata(0x7fce5ab9bff0)
dblib.c:4865:dbdead(0x7fce5ab9bff0) [alive]
dblib.c:3203:dbcancel(0x7fce5ab9bff0)
dblib.c:5743:dbgetuserdata(0x7fce5ab9bff0)
token.c:2429:tds_process_msg() returning TDS_SUCCESS
token.c:564:processing result tokens.  marker is  fd(DONE)
token.c:2080:tds_process_end: more_results = 0
    was_cancelled = 0
    error = 1
    done_count_valid = 0
token.c:2097:                rows_affected = 0
token.c:2100:tds_process_end() state set to TDS_IDLE
util.c:165:Changed query state from READING to IDLE
util.c:83:logic error: cannot change query state from IDLE to PENDING
util.c:165:Changed query state from IDLE to IDLE
dblib.c:4687:dbsqlok() end status is FAIL
dblib.c:5743:dbgetuserdata(0x7fce5ab9bff0)
dblib.c:5743:dbgetuserdata(0x7fce5ab9bff0)
dblib.c:4865:dbdead(0x7fce5ab9bff0) [alive]
dblib.c:4625:dbsqlok(0x7fce5ab9bff0)
dblib.c:4654:dbsqlok() not done, calling tds_process_tokens()
token.c:549:tds_process_tokens(0x7fce5ab4ca90, 0x7fff5f5847b4, 0x7fff5f5847b0, 0x6914)
token.c:552:tds_process_tokens() state is COMPLETED
dblib.c:3203:dbcancel(0x7fce5ab9bff0)
query.c:2186:tds_send_cancel: not in_cancel and idle

Should BCP code rtrim string data?

Hi there. I had meant to post this issue myself (I am the one who answered Neil's -- @neilmcguigan -- question on StackOverflow and found the bug) after doing a little more research, but Neil beat me to it ( #80) and Freddy -- @freddy77 -- was incredibly efficient in fixing it (kudos on being so responsive :-).

What I was researching was the behavior of the .NET SqlBulkCopy Class as it should be equivalent behavior (at least with respect to "bcp" for Microsoft SQL Server). The reason I was researching this was that it occurred to me that the "problem" with this rtrim function was larger than it just breaking NVARCHAR data if the last character was one of the 1000 Code Points starting with U+20xx.

Prior to this fix, the behavior of freebcp was:

  1. If data is VARCHAR / 8-bit Extended ASCII: trim trailing spaces
  2. If data is NVARCHAR / UTF-16:
    1. If final Code Point is U+2020: remove both bytes of said Code Point as they are both 20, and continue to checking the string (in which case it might remove another U+2020 entirely, or remove half of a U+20xx Code Point). Removing the entire Code Point won't produce an error, but it will silently corrupt the data.
    2. If final Code Point is U+20xx: remove 2nd byte of said Code Point as it will be 20 (i.e. space) due to byte-swapping Little Endian encoding, and exit (unless Code Point was U+2020). This produces an error (as was reported in this issue).

The net-effect of this behavior was to:

  1. always trim trailing spaces from VARCHAR data
  2. never actually trim any spaces from NVARCHAR data (due to the byte-swapped representation of U+0020 being 20 00 which ends with 00)
  3. occasionally fail due to removing half of a Code Point and/or silently corrupt the data by removing the entire Code Point.

For cases that fall into categories 1 and 2 directly above (I assume those represent the vast majority and that category 3 was somewhat rare), there is a behavior difference in that VARCHAR data is trimmed while NVARCHAR data is not.

With this fix, the net-effect of the behavior is merely to remove category 3 (the errors and/or corrupted data). While this is definitely an improvement over having the errors and/or corrupted data, the fact that VARCHAR is trimmed while NVARCHAR is not (now an intended behavior instead of a bug) seems inconsistent and non-intuitive. I would think that it should work the same for both types of string data.

With consistent behavior in mind, I would further question the practice of doing the trimming in the first place. Why is it being done? I actually consider the trimming behavior (even if modified to also work for NVARCHAR / UTF-16 data) to be a case of "data corruption" as those trailing spaces could be intentional, valid data. It does not seem (to me, at least) appropriate for a tool at this level to make that determination for the end-user, at least not without a configuration option to enable/disable; a simple import tool should import the data as is, and any "massaging" of it / transformation, should happen in the database, when such behavior is desired. And, coming full-circle now, the .NET SqlBulkCopy Class does not appear to do any trimming of strings. The ConvertValue method does call SqlParameter.CoerceValue, but there is no trimming done there either.

So, my recommendation is:

  • IF there is no technical reason for doing the rtrim, then it should probably removed entirely. And if this is needed for Sybase, then add an additional check to the same if condition that was updated in fix #80 to be something along the lines of && server_type = SYBASE.
  • ELSE, if the desire is to keep the current behavior of trimming, then:
    1. make it consistent by also working with NVARCHAR / UTF-16 data (i.e. if type=NCHAR / NVARCHAR then test for *p == '\0' && *p-1 == ' ')
    2. add a configuration option to disable the trimming

MSSQLODBC Transactions

My coworkers initially wrote an existing application (Linux Fedora 23) utilizing the MS ODBC Driver 11 for SQL Server with unixODBC at the system level and Ruby-odbc at the application level. In the application, making performing any writes to the db they are using transactions; however, being on the Mac and not having the official MS ODBC Driver 11 for SQL Server, I am unable to perform transactions with FreeTDS 1.00.19 enabled with unixodbc 2.3.4.

The action will execute but will not actual complete or perform any of the transactions.

Does FreeTDS have transactions capability that is compatible with the MS ODBC Driver 11 or 13 for SQL Server?

Can not find ./configure

I've read INSTALL. To build I have to run ./configure
But I can't find "configure" executable in the repository:

$ git clone https://github.com/FreeTDS/freetds.git
$ cd freetds
$ find . -name configure
$ git branch
* master

What should I do to build the application?

Type '12' not allowed before login when connecting to sybase

Every time I open a connection with a sybase I get these lines in the sybase log:
00:0009:00000:00260:2016/03/04 11:53:00.94 server Error: 1621, Severity: 18, State: 1
00:0009:00000:00260:2016/03/04 11:53:00.94 server Type '12' not allowed before login.
00:0009:00000:00352:2016/03/04 11:53:00.95 server Error: 1621, Severity: 18, State: 1
00:0009:00000:00352:2016/03/04 11:53:00.95 server Type '12' not allowed before login.
00:0009:00000:00440:2016/03/04 11:53:00.95 server Error: 1621, Severity: 18, State: 1
00:0009:00000:00440:2016/03/04 11:53:00.95 server Type '12' not allowed before login.
00:0009:00000:00312:2016/03/04 11:53:00.96 server Error: 1621, Severity: 18, State: 1
00:0009:00000:00312:2016/03/04 11:53:00.96 server Type '10' not allowed before login.

I tested against several version (last freetds-dev.0.99.633).
The odbc setting include:
[tabdp]
Driver = SybaseASE
Server = 10.10.xx.xx
Port = 4901
Database = BDP
uid = sapsa
encryption = request

client side I don't get any error and I can query the db correctly.

Question about odbc_mismatch

Hello @freddy77 !
Could you please explain what is "odbc_mismatch" in user.c?

Fragment of code:

/* swicth to dblib options */
if (odbc_mismatch)
strcat(str, "SET ANSI_DEFAULTS OFF\nSET CONCAT_NULL_YIELDS_NULL OFF\n");

These options break results of our SPs. I understood that we can change this options after connect / or modife source code. Is this options need to be OFF in current version of freetds by default?

Legacy numeric/decimal type support using Sybase ASE

Quick question: Does FreeTDS support the legacy decimal type of 55 (0x37)?

Background:
As I was using gofreetds in a go app I was working with, I came across this error:

Msg 20018, Level 12
General SQL Server error: Check messages from the SQL Server

Msg 7738, Level 12, State 2
Server 'SYBASE', Line 2
Message empty.

I noticed I would get this error in the Sybase ASE 16 database I was working with on some stored procedures and not others. It turns out the ones experiencing the error above had decimal/numeric input and/or output parameters.

After googling some, it became apparent that this type is regarded as a “legacy” type at least from TDS 7+’s standpoint and that 106 (0x6A) is the newer decimal type id value. You can see evidence of this on Microsoft/MSDN’s site where they provide the TDS7 specification. Specifically, on this page you see this:

 DECIMALTYPE         =   %x37  ; Decimal (legacy support)
 NUMERICTYPE         =   %x3F  ; Numeric (legacy support)
 BITNTYPE            =   %x68  ; (see below)
 DECIMALNTYPE        =   %x6A  ; Decimal
 NUMERICNTYPE        =   %x6C  ; Numeric

And then also wireshark has a TDS decoder plugin and if you look at their github source you see this:

#define TDS_DATA_TYPE_DECIMAL         0x37  /* Decimal (legacy support) */
#define TDS_DATA_TYPE_NUMERIC         0x3F  /* Numeric (legacy support) */
#define TDS_DATA_TYPE_BITN            0x68
#define TDS_DATA_TYPE_DECIMALN        0x6A  /* Decimal */
#define TDS_DATA_TYPE_NUMERICN        0x6C  /* Numeric */

However, when I look at the FreeTDS TDS Protocol Documentation page, in the Types section, I don't see any references to the legacy types.

Also, in sybdb.h, I don't see a reference to the legacy numeric/decimal datatypes either.

Datetimeoffset(n) Hour Bug - v0.95 & v0.99

While testing both the Ruby C extensions for FreeTDS, I found a bug with the hour part of the dbanydatecrack in the following conditions.

  • Does not matter on scale. Been able to reproduce the bug in datetimeoffset(7), (2), etc.
  • I have yet to trigger the bug when tzone is 0.
  • Seems to be coupled to hour & tzone value relationship.

Headers below are DB values inserted. Blow I show different values from dbanydatecrack when reading said data.

2010-12-31 15:00:00 -08:00

This value does not raise an error and hour appears fine.

hour: 15, minute: 0, second: 0, nanosecond: 0, tzone: -480

2010-12-31 16:00:00 -08:00

Now that the the hour is changed to 16, the hour comes back incorrectly.

hour: 1432, minute: 0, second: 0, nanosecond: 0, tzone: -480

From here I can keep playing with the zone in the DB increasing it and get in a win/loose tug of war. Any ideas where in the code I can look for this issue?

Can't install pymssql with freetds 1.0.0 on Mac OSX 10.11.4

pip version: 8.1.2
Python version: 2.7.10

Steps to reproduce:

sudo easy_install pip
brew install freetds
sudo pip install pymssql

Error seen:

Installing collected packages: pymssql
  Running setup.py install for pymssql ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-HROzBh/pymssql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-AHLpHT-record/install-record.txt --single-version-externally-managed --compile:
    setup.py: platform.system() => 'Darwin'
    setup.py: platform.architecture() => ('64bit', '')
    setup.py: platform.libc_ver() => ('', '')
    setup.py: Detected Darwin/Mac OS X.

You can install FreeTDS with Homebrew or MacPorts, or by downloading and compiling it yourself.

Homebrew (http://brew.sh/)
brew install freetds

MacPorts (http://www.macports.org/)
sudo port install freetds

setup.py: Not using bundled FreeTDS
setup.py: include_dirs = ['/usr/local/include']
setup.py: library_dirs = ['/usr/local/lib']
running install
running build
running build_ext
building '_mssql' extension
creating build
creating build/temp.macosx-10.11-intel-2.7
cc -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/usr/local/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mssql.c -o build/temp.macosx-10.11-intel-2.7/_mssql.o -DMSDBLIB
_mssql.c:18924:15: error: use of undeclared identifier 'DBVERSION_80'
    __pyx_r = DBVERSION_80;
              ^
1 error generated.
error: command 'cc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-HROzBh/pymssql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-AHLpHT-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-HROzBh/pymssql/

FreeTDS Pool low performance

You can abserve that FreeTDS Pool works well (from master) but still has very very low perfomance(using this one line test ).
The connection speed with freetds as is would be very low ~2,8ms per connnection. If launch same test with tdspool ~446ms per connection.

The query results with query test is same. Approximately 1ms per query SELECT 1,2,3 and ~1253 ms in case of pool using.

WSAEnumProtocols failed + Access Violation

In a test program the call to dbinit gives an access violation. Before this happens there is an error message printed saying:
tds_init_winsock: WSAEnumProtocols failed with 10055 (WSAENOBUFS: No buffer space available.)

The WSAEnumProtocols fails because on my PC windows wants to return 85 results and FreeTDS is only prepared for 64 results. According to the MS documentation WSAEnumProtocols will give the WSAENOBUFS error in this case.
I solved this problem for me with the attached patch. I had to rename it as a txt file for github. I can only assume that this mitigates the Access Violation. Unfortunately I don't have a chance to debug into this as I am not using C++ for my projects.

This is on WIN32, using the Branch-0_95 from 2016-01-28 compiled with cmake and Visual C++ 2013.
mem.c-wsaenumprotocols.patch.txt

Interesting issue with PDO construction and attributes.

Sorry for posting this here, I am not sure if this is a PHP issue or a FreeTDS issue.

I am using the dblib freetds driver (0.91 & 0.95) to connect to an mssql database and it appears to function correctly until I started using a query builder that wraps PDO. Said query builder passes some default attribute options to the PDO constructor which probably work for every driver except freetds. The weird part here is that passing any option on construction results in a 'PDOException' with message 'The auto-commit mode cannot be changed for this driver' exception.

  1. Why does setting ANY option in the PDO constructor for this driver produce a "auto-commit mode cannot be changed" exception?
  2. Why does setting other options work with the setAttribute(...) method?
// Works Fine, Returns True
$DB->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);  

// Error, auto-commit mode cannot be changed
new PDO(..., ..., ..., array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION))

So, is the PDO constructor incorrectly producing exceptions, or are the setAttribute methods just returning true and not doing anything?

Moving DBMAXNAME to dblib.h broke sybperl

a19a535 increased the size of DBMAXNAME to 128, but also moves it from sybdb.h to dblib.h (which is in noinst_HEADERS so doesn't get installed). Noticed because it broke OS packaging of sybperl. It's easy enough to workaround in sybperl, but should this move back?

tdspool segmentation fault

Hi all!
I try to launch tdspool (with default config files) but got segfault after it starts

/opt/freetds/bin/tdspool global

Found conf file in /opt/freetds/etc/pool.conf reading sections
Segmentation fault (core dumped)

https://www.dropbox.com/s/v543q33c3mgli03/core.4620?dl=0 coredump here

Linux 2.6.32-431.11.2.el6.i686 #1 SMP Tue Mar 25 17:17:46 UTC 2014 i686 i686 i386 GNU/Linux
(got same result on x64 server).
I'm pull freetds from master (same error with r95)
./configure --prefix=/opt/freetds
glibc-2.12-1.149.el6_6.9.i686

tsql command could not connect to sybase servers

found this in 1.00 brand when try to connect, not happened with 0.91 version:

SQL Anywhere Error -131: Syntax error near 'select' on line 1

seems that the option that enabling the sybae compatibility was gone? the complete error are:

root@systemaspc01:/home/systemas/Devel# tsql -H 10.10.34.21 -p 2638 -U dbauser -P secretpass -D T_001642
locale is "es_VE.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Setting T_001642 as default database in login packet
Msg 21 (severity 10, state 0) from [10.10.34.21]:
	"TDS: unexpected token 0"
Msg 102 (severity 15, state 0) from [10.10.34.21]:
	"SQL Anywhere Error -131: Syntax error near 'select' on line 1"
There was a problem connecting to the server
root@systemaspc01:/home/systemas/Devel# 

implement support in ctlib for CS_TIMEOUT and CS_LOGIN_TIMEOUT

currently ctlib applications will get an indefinite timeout when trying to reconnect to a server after a lost connection. This is correct according to the SAP/Sybase docs: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc32840.1550/html/ctref/X69451.htm

however ct_con_props() does not support CS_TIMEOUT or CS_LOGIN_TIMEOUT which are needed to allow users to control these timeouts.

Timeouts are implemented in the freetds tds layer, but not controllable using ct_con_props() - this issue is for implementing support for this in ctlib (patch in progress).

tdspool reconnect to sql server

Hello all!
Tdspool don't reconnect to sql server if disconnect appear (for example, after sql server restart), only write to console "Uh oh! member disconnected" and continue running without any actions. Could someone add reconnect feature (every 10-30-etc seconds) or add trying to reconnect when first client send queries via pool?

v0.95.67 Corrupt Packets After - Error converting characters into server's character set

Cross post from the mailing list.

When testing the Ruby C-extensions, TinyTDS, FreeTDS 0.95. We have a test that checks usage of the client after inserting invalid characters. The following insert is done when the client encoding is set to 'ASCII'.

INSERT INTO [datatypes] ([nvarchar_50]) VALUES ('Test ✓')

After handling the message, the followup SELECT 1 AS [one] test query returns

Incorrect syntax near '3'

When examining the TDSDUMP file, it seems there is some garbage in the packets. Thoughts?

dblib.c:1338:dbcmd(0x7fca058a4f60, INSERT INTO [datatypes] ([nvarchar_50]) VALUES ('Test ✓'))
dblib.c:1344:dbcmd() bufsz = 56
dblib.c:5845:dbfreebuf(0x7fca058a4f60)
dblib.c:6817:dbsqlsend(0x7fca058a4f60)
mem.c:648:tds_free_all_results()
util.c:165:Changed query state from IDLE to WRITING
util.c:322:tdserror(0x7fca046f4a80, 0x7fca044b0240, 2402, 0)
dblib.c:7897:dbperror(0x7fca058a4f60, 2402, 0)
dblib.c:7965:dbperror: Calling dblib_err_handler with msgno = 2402; msg->msgtext = "Error converting characters into server's character set. Some character(s) could not be converted"
dblib.c:5743:dbgetuserdata(0x7fca058a4f60)
dblib.c:5845:dbfreebuf(0x7fca058a4f60)
dblib.c:5743:dbgetuserdata(0x7fca058a4f60)
dblib.c:1338:dbcmd(0x7fca058a4f60, SELECT 1 AS [one])
dblib.c:1344:dbcmd() bufsz = 0
dblib.c:6817:dbsqlsend(0x7fca058a4f60)
util.c:165:Changed query state from WRITING to PENDING
packet.c:740:Sending packet
0000 01 01 00 56 00 00 01 00-16 00 00 00 12 00 00 00 |...V.... ........|
0010 02 00 01 00 00 00 33 00-00 00 01 00 00 00 16 00 |......3. ........|
0020 00 00 12 00 00 00 02 00-01 00 00 00 33 00 00 00 |........ ....3...|
0030 01 00 00 00 53 00 45 00-4c 00 45 00 43 00 54 00 |....S.E. L.E.C.T.|
0040 20 00 31 00 20 00 41 00-53 00 20 00 5b 00 6f 00 | .1. .A. S. .[.o.|
0050 6e 00 65 00 5d 00      -                        |n.e.].|

dblib.c:5743:dbgetuserdata(0x7fca058a4f60)
dblib.c:5743:dbgetuserdata(0x7fca058a4f60)
dblib.c:5743:dbgetuserdata(0x7fca058a4f60)
dblib.c:5743:dbgetuserdata(0x7fca058a4f60)
dblib.c:4625:dbsqlok(0x7fca058a4f60)
dblib.c:4654:dbsqlok() not done, calling tds_process_tokens()
token.c:549:tds_process_tokens(0x7fca044b0240, 0x7fff5b414fd4, 0x7fff5b414fd0, 0x6914)
util.c:165:Changed query state from PENDING to READING
packet.c:639:Received packet
0000 04 01 00 66 00 33 01 00-aa 4e 00 66 00 00 00 01 |...f.3.. ªN.f....|
0010 0f 1a 00 49 00 6e 00 63-00 6f 00 72 00 72 00 65 |...I.n.c .o.r.r.e|
0020 00 63 00 74 00 20 00 73-00 79 00 6e 00 74 00 61 |.c.t. .s .y.n.t.a|
0030 00 78 00 20 00 6e 00 65-00 61 00 72 00 20 00 27 |.x. .n.e .a.r. .'|
0040 00 33 00 27 00 2e 00 06-53 00 53 00 32 00 30 00 |.3.'.... S.S.2.0.|
0050 31 00 34 00 00 01 00 00-00 fd 02 00 fd 00 00 00 |1.4..... .ý..ý...|
0060 00 00 00 00 00 00      -                        |......|

DSN Less Connection:Message String: Server name not found in configuration files.

I' ve a problem connecting without using the freetds.conf:
Tested with
DBD::Sybase: 1.15
freetds: 0.95.67

use DBI;
use strict;

my $username = "sa";
my $password = "password";
my $dsn = "DBI:Sybase:;host=myhost.com;port=61234";
if (my $dbh = DBI->connect(
    $dsn, $username, $password,
    { RaiseError => 1, AutoCommit => 0, PrintError => 1 })) {
  printf "connection succeeded\n";
} else {
  printf "connection failed\n";
}

Error message:

DBI connect(';host=myhost.com;port=61234','sa',...) failed: OpenClient message: LAYER = (0) ORIGIN = (0) SEVERITY = (78) NUMBER = (44)
Server , database
Message String: Server name not found in configuration files.
OpenClient message: LAYER = (0) ORIGIN = (0) SEVERITY = (78) NUMBER = (45)
Server , database
Message String: Unknown host machine name.

The problem was already reported: http://comments.gmane.org/gmane.comp.db.tds.freetds/15090 and it seems like the problem is not fixed.

socket handle leak when fails to connect remote sql server

I'm compiling ftds without the ENABLE_ODBC_MARS macro.

When the network between the client and the sql server (version 2008) is ok, all goes well. But if I shutdown the sql server service purposely, sock handle leak happens. Here the command I used:
watch -n 1 ' lsof -p | wc -l'

Every time my program tries to reconnect the server, the opened handle count of the program keeps increasing by three.

Here's the root cause of the leak.
qq 20151209141309

When I reconnect the server, which will certainly fail, the tds variable is DEAD. But tds->conn isn't closed here!

So I fix it by adding an else branch right after the if, like this:
fix

connecting to remote mssql from linux plesk via php

I am trying to connect to remote Microsoft SQL server 2012 service pack 2 database from my Linux machine which is having php 5.3, php-mssql support and mysql version 5.5 enabled. Meanwhile I am getting below error message even if the login details are correct.

The ms-sql database is using Persian collation which cannot be changed. Is there any possible fix for this?

[root@i]# /usr/bin/tsql -H remove-server-ip -p 1433 -U mssql-user

locale is "en_IN" locale charset is "UTF-8" using default charset "UTF-8" Msg 4075 (severity 16, state 1) from RAHKARAN Line 1: "

The USE database statement failed because the database collation Persian_100_CI_AI is not recognized by older client drivers. Try upgrading the client operating system or applying a service update to the database client software, or use a different collation. See SQL Server Books Online for more information on changing collations."

Msg 18456 (severity 14, state 1) from RAHKARAN Line 1: "Login failed for user 'mssql-user'." Error 20002 (severity 9): Adaptive Server connection failed There was a problem connecting to the server

Error 20002 (severity 9)

Freetds version is below

tsql -C Compile-time settings (established with the "configure" script) Version: freetds v0.91 freetds.conf directory: /etc MS db-lib source compatibility: yes Sybase binary compatibility: yes Thread safety: yes iconv library: yes TDS version: 4.2 iODBC: no unixodbc: yes SSPI "trusted" logins: no Kerberos: yes

missing datatype for sybase cannot resolve datatype 'univarchar'

i got a error on some data types, seems related to unicode to UTF8 conversion

[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'

**this error resulting on many tables, and specially on proxy tables! seems that need convert UNIVARCHAR, UNICHAR, and UNITEXT data to utf-8 client encoding in this case the tdsodbc encoding when they are retrieved.

Of course alsio we need when updating a unicode column will cause Sybase to convert any incoming data from utf-8 to its internal utf-16 encoding. so the tdsodbc driver must send the data converted!**

i see a very older patch here: http://marc.info/?l=freetds&m=106941196411173&w=2 i this are so older today the univarchar support must have included! but seems does not!

SQL> select * from ta_cpp
+--------------+-------------+
| num_promocion| cod_sucursal|
+--------------+-------------+
+--------------+-------------+
SQLRowCount returns 0
SQL> select * from usuarios
[37000][unixODBC][FreeTDS][SQL Server]SQL Anywhere Error -85: Communication error
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'unitext'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'unitext'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'unitext'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[01000][unixODBC][FreeTDS][SQL Server]TDS: cannot resolve datatype 'univarchar'
[ISQL]ERROR: Could not SQLExecute
SQL> 

i posted the patch here if the source dissapears, dated from 2003:

Index: include/cspublic.h
===================================================================
RCS file: /cvsroot/freetds/freetds/include/cspublic.h,v
retrieving revision 1.42
diff -u -r1.42 cspublic.h
--- include/cspublic.h	1 Nov 2003 23:02:07 -0000	1.42
+++ include/cspublic.h	21 Nov 2003 10:33:23 -0000
@@ -737,6 +737,7 @@
 #define CS_VOID_TYPE	25
 #define CS_USHORT_TYPE	26
 #define CS_UNIQUE_TYPE	27
+#define CS_UNIVARCHAR_TYPE  28
 
 /* cs_dt_info type values */
 enum
Index: include/tds.h
===================================================================
RCS file: /cvsroot/freetds/freetds/include/tds.h,v
retrieving revision 1.154
diff -u -r1.154 tds.h
--- include/tds.h	16 Nov 2003 08:19:34 -0000	1.154
+++ include/tds.h	21 Nov 2003 10:33:23 -0000
@@ -413,8 +413,10 @@
 
 	SYBUNIQUE = 36,		/* 0x24 */
 #define SYBUNIQUE	SYBUNIQUE
-	SYBVARIANT = 98 	/* 0x62 */
+	SYBVARIANT = 98, 	/* 0x62 */
 #define SYBVARIANT	SYBVARIANT
+	SYBUNIVARCHAR = -1001
+#define SYBUNIVARCHAR	SYBUNIVARCHAR
 } TDS_SERVER_TYPE;
 
 #define SYBAOPCNT  0x4b
@@ -568,6 +570,7 @@
 #define is_unicode_type(x) (x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
 #define is_collate_type(x) (x==XSYBVARCHAR || x==XSYBCHAR || x==SYBTEXT || x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
 #define is_ascii_type(x) ( x==XSYBCHAR || x==XSYBVARCHAR || x==SYBTEXT || x==SYBCHAR || x==SYBVARCHAR)
+#define is_binary_type(x) (x==SYBLONGBINARY)
 #define is_char_type(x) (is_unicode_type(x) || is_ascii_type(x))
 #define is_similar_type(x, y) ((is_char_type(x) && is_char_type(y)) || ((is_unicode_type(x) && is_unicode_type(y))))
 
Index: src/ctlib/cs.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/ctlib/cs.c,v
retrieving revision 1.42
diff -u -r1.42 cs.c
--- src/ctlib/cs.c	1 Nov 2003 23:02:09 -0000	1.42
+++ src/ctlib/cs.c	21 Nov 2003 10:33:23 -0000
@@ -371,11 +371,13 @@
 				}
 			}
 			break;
+		case SYBUNIVARCHAR:
 		case SYBCHAR:
 		case SYBVARCHAR:
 		case SYBTEXT:
 			tdsdump_log(TDS_DBG_FUNC, "%L cs_convert() desttype = character\n");
 			if (src_len > destlen) {
+				tdsdump_log(TDS_DBG_FUNC, "%L src_len > destlen\n");
 				ret = CS_FAIL;
 			} else {
 				switch (destfmt->format) {
@@ -416,6 +418,7 @@
 					ret = CS_SUCCEED;
 					break;
 				default:
+					tdsdump_log(TDS_DBG_FUNC, "%L no destination format specified!\n");
 					ret = CS_FAIL;
 					break;
 				}
Index: src/ctlib/ct.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/ctlib/ct.c,v
retrieving revision 1.107
diff -u -r1.107 ct.c
--- src/ctlib/ct.c	16 Nov 2003 08:19:58 -0000	1.107
+++ src/ctlib/ct.c	21 Nov 2003 10:33:23 -0000
@@ -49,7 +49,7 @@
  */
 static int _ct_fetch_cursor(CS_COMMAND * cmd, CS_INT type, CS_INT offset, CS_INT option, CS_INT * rows_read);
 static int _ct_bind_data(CS_COMMAND * cmd, CS_INT offset);
-static int _ct_get_client_type(int datatype, int size);
+static int _ct_get_client_type(int datatype, int usertype, int size);
 static int _ct_fetchable_results(CS_COMMAND * cmd);
 static int _ct_process_return_status(TDSSOCKET * tds);
 
@@ -1369,6 +1369,11 @@
 	for (i = 0; i < resinfo->num_cols; i++) {
 		curcol = resinfo->columns[i];
 
+		tdsdump_log(TDS_DBG_FUNC, "%L _ct_bind_data(): column_type: %d column_len: %d\n",
+			curcol->column_type,
+			curcol->column_cur_size
+		);
+
 		if (curcol->column_hidden) 
 			continue;
 
@@ -1397,7 +1402,7 @@
 
 		if (dest && !tds_get_null(resinfo->current_row, i)) {
 
-			srctype = _ct_get_client_type(curcol->column_type, curcol->column_size);
+			srctype = _ct_get_client_type(curcol->column_type, curcol->column_usertype, curcol->column_size);
 
 			src = &(resinfo->current_row[curcol->column_offset]);
 			if (is_blob_type(curcol->column_type))
@@ -1413,7 +1418,8 @@
 			destfmt.locale = cmd->con->locale;
 			destfmt.format = curcol->column_bindfmt;
 			/* if convert return FAIL mark error but process other columns */
-			if (cs_convert(ctx, &srcfmt, (CS_VOID *) src, &destfmt, (CS_VOID *) dest, &len) != CS_SUCCEED) {
+			if ((result= cs_convert(ctx, &srcfmt, (CS_VOID *) src, &destfmt, (CS_VOID *) dest, &len) != CS_SUCCEED)) {
+				tdsdump_log(TDS_DBG_FUNC, "%L cs_convert-result = %d\n", result);
 				result = 1;
 				len = 0;
 				tdsdump_log(TDS_DBG_INFO1, "%L \n  convert failed for %d \n", srcfmt.datatype);
@@ -1472,9 +1478,9 @@
 
 
 static int
-_ct_get_client_type(int datatype, int size)
+_ct_get_client_type(int datatype, int usertype, int size)
 {
-	tdsdump_log(TDS_DBG_FUNC, "%L _ct_get_client_type(type %d, size %d)\n", datatype, size);
+	tdsdump_log(TDS_DBG_FUNC, "%L _ct_get_client_type(type %d, user %d, size %d)\n", datatype, usertype, size);
 	switch (datatype) {
 	case SYBBIT:
 	case SYBBITN:
@@ -1568,6 +1574,11 @@
 	case SYBUNIQUE:
 		return CS_UNIQUE_TYPE;
 		break;
+	case SYBLONGBINARY:
+		if (usertype == 35)
+			return CS_UNIVARCHAR_TYPE;
+		return CS_BINARY_TYPE;
+		break;
 	}
 
 	return CS_FAIL;
@@ -1635,6 +1646,8 @@
 	case CS_LONGBINARY_TYPE:	/* vicm */
 		return SYBLONGBINARY;
 		break;
+	case CS_UNIVARCHAR_TYPE:
+		return SYBUNIVARCHAR;
 	default:
 		return -1;
 		break;
@@ -1703,7 +1716,7 @@
 	strncpy(datafmt->name, curcol->column_name, len);
 	datafmt->namelen = len;
 	/* need to turn the SYBxxx into a CS_xxx_TYPE */
-	datafmt->datatype = _ct_get_client_type(curcol->column_type, curcol->column_size);
+	datafmt->datatype = _ct_get_client_type(curcol->column_type, curcol->column_usertype, curcol->column_size);
 	tdsdump_log(TDS_DBG_INFO1, "%L ct_describe() datafmt->datatype = %d server type %d\n", datafmt->datatype,
 		    curcol->column_type);
 	/* FIXME is ok this value for numeric/decimal? */
Index: src/tds/convert.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/convert.c,v
retrieving revision 1.125
diff -u -r1.125 convert.c
--- src/tds/convert.c	24 Oct 2003 10:11:11 -0000	1.125
+++ src/tds/convert.c	21 Nov 2003 10:33:23 -0000
@@ -1608,6 +1608,7 @@
 	assert(srclen >= 0 && srclen <= 2147483647u);
 
 	switch (srctype) {
+	case SYBUNIVARCHAR:
 	case CASE_ALL_CHAR:
 		length = tds_convert_char(srctype, src, srclen, desttype, cr);
 		break;
@@ -3220,6 +3221,9 @@
 		break;
 	case SYBLONGBINARY:
 		result = "SYBLONGBINARY";
+		break;
+	case SYBUNIVARCHAR:
+		result = "SYBUNIVARCHAR";
 		break;
 	default:
 		break;
Index: src/tds/token.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/token.c,v
retrieving revision 1.226
diff -u -r1.226 token.c
--- src/tds/token.c	16 Nov 2003 18:10:18 -0000	1.226
+++ src/tds/token.c	21 Nov 2003 10:33:23 -0000
@@ -1520,8 +1520,11 @@
 	switch (curcol->column_varint_size) {
 	case 4:
 		curcol->column_size = tds_get_int(tds);
-		curcol->table_namelen =
-			tds_get_string(tds, tds_get_smallint(tds), curcol->table_name, sizeof(curcol->table_name) - 1);
+		/* Only read table_name for blob columns (eg. not for SYBLONGBINARY) */
+		if (is_blob_type (curcol->column_type)) {
+			curcol->table_namelen =
+				tds_get_string(tds, tds_get_smallint(tds), curcol->table_name, sizeof(curcol->table_name) - 1);
+		}
 		break;
 	case 2:
 		curcol->column_size = tds_get_smallint(tds);
@@ -1812,7 +1815,7 @@
 {
 	unsigned char *dest;
 	int len, colsize;
-	int fillchar;
+	int fillchar, pos;
 	TDSBLOBINFO *blob_info = NULL;
 
 	tdsdump_log(TDS_DBG_INFO1, "%L processing row.  column is %d varint size = %d\n", i, curcol->column_varint_size);
@@ -1830,6 +1833,15 @@
 			tds_set_null(current_row, i);
 			return TDS_SUCCEED;
 		}
+		
+		/* LONGBINARY
+		 * This type just stores a 4-byte length
+		 */
+		if (curcol->column_type == SYBLONGBINARY) {
+			colsize = tds_get_int(tds);
+			break;
+		}
+		
 		/* It's a BLOB... */
 		len = tds_get_byte(tds);
 		blob_info = (TDSBLOBINFO *) & (current_row[curcol->column_offset]);
@@ -1949,6 +1961,7 @@
 	} else {		/* non-numeric and non-blob */
 		if (is_char_type(curcol->column_type)) {
 			/* this shouldn't fail here */
+			tdsdump_log(TDS_DBG_INFO1, "%L curcol->iconv_info? %d\n", (int)curcol->iconv_info);
 			if (tds_get_char_data(tds, (char *) dest, colsize, curcol) == TDS_FAIL)
 				return TDS_FAIL;
 		} else {
@@ -1968,6 +1981,11 @@
 				break;
 			/* FIXME use client charset */
 			fillchar = ' ';
+		/* just to prevent \0 to interrupt display, as long as we cannot decode utf-16 */
+		case SYBLONGBINARY:
+			for (pos= 0; pos < colsize; pos++) {
+				if (dest[pos] == '\0') { dest[pos]= '.'; }
+			}
 		case SYBBINARY:
 		case XSYBBINARY:
 			if (colsize < curcol->column_size)
@@ -3151,6 +3169,7 @@
 		TYPE(SYBAOPSUM, "sum");
 
 		TYPE(SYBBINARY, "binary");
+		TYPE(SYBLONGBINARY, "longbinary");
 		TYPE(SYBBIT, "bit");
 		TYPE(SYBBITN, "bit-null");
 		TYPE(SYBCHAR, "char");

FreeTDS Pool segmentation fault with php client connection

FreeTDS Pool segmentation fault on connection to it with mssql or pdo api in php.

Using the following code pdo code

 $host = "your pool ip";
 $port = "your pool port";
 $login = "...";
 $password = "...";
 $link = new PDO("dblib:host=$host:$port", $login, $password);

You got error PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[01002] Adaptive Server connection failed (severity 9)'.

Using the following mssql api code

$link = mssql_connect("$host:$port ", $login, $password);

You got warning PHP Warning: mssql_connect(): Unable to connect to server.

Both connection try cause freetds pool segmentation fault if login and password not empty. If using empty login/password freetds pool do not segmentation fault but php client has same errors as above writen.

The following link https://www.dropbox.com/s/trcx5qvmfpi4bpc/freetds.zip to freetds pool application, config and core dump files. Used freetds from master. Same with 0.95/0.99 branches.

since v0.91 last character of nvarchar chopped when string is at max length and contains unicode chars

To reproduce: create table with nvarchar(128) and insert the following string which contains unicode character "ì"

Soprintendenza per il patrimonio storico artistico e demoetnoantropologico per Bologna, Ferrara,, Forlì-Cesena, Ravenna e Rimini

In patched 0.82, this string is properly returned and length reported as 128. In version 0.91 and newer, length is reported as 129, the last "i" in the string (not the unicode char) is chopped off and the last byte is the null character.

RHEL6, 32 bit, Perl 5 - freetds and freetds-unixodbc packages built using rpmbuild. Can reproduce problem using isql utility in addition to the following code:

#!/usr/bin/perl
use warnings;
use strict;
use DBI;
use Error qw(:try);
use MIME::Lite;
use Data::Dumper;
use Sys::Hostname;
use Time::HiRes qw(usleep);
my $dbh;

my $cnt=0;
while (++$cnt) { // loop used for testing another problem with intermittent TLS errors

try {
    print "$cnt:\ttrying connection\n";
    $dbh = DBI->connect('dbi:ODBC:MYDB',myuser', 'mypassword');
    die 'no dbh' if ! $dbh;
    $dbh->{LongTruncOk}=1;
    my $inst = $dbh->selectrow_array('SELECT mystring FROM mytable WHERE id=12345');
    my $char = chop $inst;
    die "bug with unicode exists" if $char ne "i";
}
catch Error with {
    my $details = "";
    $details = "Can't connect to database: $DBI::errstr!" if defined $DBI::errstr;
    my $exception = shift;
    $details = $details."\n".Dumper($exception);
    print "DB error: $details\n";
}
finally {
    $dbh->disconnect if $dbh;;
    # sleep for a short time
    usleep(10000);
};

}

FreeTDS apt-get package

Hello,

I really appreciate all the work that's gone into FreeTDS over the years. I've been able to successfully use it when developing on OS X, but it seems that the packages on Debian apt-get is rather old (hoping to pull it into a docker container):
https://packages.debian.org/search?keywords=freetds&searchon=names&suite=stable&section=all

Package freetds-bin
jessie (stable) (database): FreeTDS command-line utilities 
0.91-6+b1: amd64 armel armhf i386 mips mipsel powerpc s390x 
0.91-6: arm64 ppc64el
Package freetds-common
jessie (stable) (libs): configuration files for FreeTDS SQL client libraries 
0.91-6: all
Package freetds-dev
jessie (stable) (devel): MS SQL and Sybase client library (static libs and headers) 
0.91-6+b1: amd64 armel armhf i386 mips mipsel powerpc s390x 
0.91-6: arm64 ppc64el
Package libdbd-freetds
jessie (stable) (libs): Freetds database server driver for libdbi 
0.9.0-3: amd64 arm64 armel armhf i386 mips mipsel powerpc ppc64el s390x

I understand that maintaining the code is different from updating it in the numerous package managers that exist, but I was hoping that one of the current maintainers might find it helpful (and, hopefully, not especially painful) to update these to the current stable release. I would consider doing it but I would almost certainly muck it up. Homebrew has 0.95.95, and there is likely communal utility in having it on apt-get as well.

-Jeffrey

Unknown `dbcoltype` 98

From an issue filed on TinyTDS here: rails-sqlserver/tiny_tds#317

SELECT LOGINPROPERTY('sa', 'IsLocked') as v

I noticed that the following function returns 98 for dbcoltype but this type is no where in sydb.h or tds.h. Have you encountered that one before? Should I treat 98 as an int?

undefined reference to `dlopen' - libcrypto.a

When trying to compile 0.95.87 against a static openssl, I'm getting an error when freetds is compiling the fisql tool:

Making all in fisql make[3]: Entering directory/home/dsteckbeck/apache-php/freetds-0.95.87/src/apps/fisql'
CC fisql.o
CC edit.o
CC handlers.o
CC interrupt.o
CCLD fisql
/home/dsteckbeck/apache-php/libs/lib/libcrypto.a(dso_dlfcn.o): In function dlfcn_globallookup': dso_dlfcn.c:(.text+0x31): undefined reference todlopen'
dso_dlfcn.c:(.text+0x44): undefined reference to dlsym' dso_dlfcn.c:(.text+0x4f): undefined reference todlclose'
/home/dsteckbeck/apache-php/libs/lib/libcrypto.a(dso_dlfcn.o): In function dlfcn_pathbyaddr': dso_dlfcn.c:(.text+0xa0): undefined reference todladdr'
dso_dlfcn.c:(.text+0x101): undefined reference to dlerror' /home/dsteckbeck/apache-php/libs/lib/libcrypto.a(dso_dlfcn.o): In functiondlfcn_bind_func':
dso_dlfcn.c:(.text+0x454): undefined reference to dlsym' dso_dlfcn.c:(.text+0x512): undefined reference todlerror'
/home/dsteckbeck/apache-php/libs/lib/libcrypto.a(dso_dlfcn.o): In function dlfcn_bind_var': dso_dlfcn.c:(.text+0x584): undefined reference todlsym'
dso_dlfcn.c:(.text+0x642): undefined reference to dlerror' /home/dsteckbeck/apache-php/libs/lib/libcrypto.a(dso_dlfcn.o): In functiondlfcn_unload':
dso_dlfcn.c:(.text+0x69f): undefined reference to dlclose' /home/dsteckbeck/apache-php/libs/lib/libcrypto.a(dso_dlfcn.o): In functiondlfcn_load':
dso_dlfcn.c:(.text+0x754): undefined reference to dlopen' dso_dlfcn.c:(.text+0x7c2): undefined reference todlclose'
dso_dlfcn.c:(.text+0x7f2): undefined reference to dlerror' collect2: ld returned 1 exit status make[3]: *** [fisql] Error 1 make[3]: Leaving directory/home/dsteckbeck/apache-php/freetds-0.95.87/src/apps/fisql'
`

The configure options are:
./configure --prefix=/home/dsteckbeck/apache-php/libs --with-pic --with-tdsver=7.1 --enable-static --enable-msdblib --disable-shared --disable-odbc --disable-pool --disable-server --with-openssl=/home/dsteckbeck/apache-php/libs

This is with OpenSSL 1.0.2f. Previous builds of FreeTDS 0.92.79 and OpenSSL 1.0.1j compiled together just fine.

Move TDS Connection Pooling to separate repository

FreeTDS is an big product with large history. And TDS Connection Pooling obe thet things which should be important feature in it.

I propose to move TDS Connection Pooling to separate repository under FreeTDS organization. And If need it - add it as a submodule in the main project. This change allow us use separate release pipeline and faster development this project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.