Set up client charset with DSN-less configuration

Johnny Yan <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <BY2PR0301MB0663539E51D169A158A74ABDC3390@BY2PR0301MB0663.namprd03.prod.outlook.com>
Hi,


We're writing data analytic application on Linux using FreeTDS(0.95.81) with unixODBC(2.3.4) to connect to SQL Server databases. Since we need to programmatically decide the hosts and other info provided by our customers, we decided to use the DSN-less configuration and pass the attributes through the connection string. However it seems that we can't set up the client side charset correctly.


From the attached simple sample code, you could see that we could connect with that connection string(you need to change the server and username/password if you want to test it). And we get the following head in the freetds.log file,


log.c:167:Starting log file for FreeTDS 0.95.81
    on 2016-06-30 18:17:32 with debug flags 0x4fff.
iconv.c:328:tds_iconv_open(0xff47a0, UTF-8)
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:346:setting up conversions for client charset "UTF-8"
iconv.c:348:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:395:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion


It seems that the client charset is set to UTF-8. Am I correct? My understanding is that this is from the LANG env variable since we didn't specify it anywhere. Right?


However when we try to specify the charset in the connection string, that is appending ";ClientCharset=UTF-16" to the connection string in the sample, we didn't observe the expected behavior. In another words, we still see the above bold line which implies that the ClientCharset attr in the connection string didn't make any difference. Is that expected? Did we do it correctly? Probably not. If so, how can we make it right?


Let me know if you need any other info. Thank you very much!


Johnny

_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds
sample.cpp (text/x-c++src, 677 B)
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>

main() {
  SQLHENV env;
  SQLHDBC dbc;
  SQLRETURN ret;
  const char instr[] = "DRIVER={FreeTDS};SERVER=servername;PORT=1433;UID=username;PWD=password;Fetch=2048;TDS_Version=auto";
  SQLCHAR outstr[1024];
  SQLSMALLINT outstrlen;

  SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
  SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
  SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);

  ret = SQLDriverConnect(dbc, NULL, instr, SQL_NTS,
             outstr, sizeof(outstr), &outstrlen,
             SQL_DRIVER_COMPLETE);

  SQLFreeHandle(SQL_HANDLE_DBC, dbc);
  SQLFreeHandle(SQL_HANDLE_ENV, env);
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.