X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id DAEC8D1B469 for ; Fri, 9 Jan 2004 16:59:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 37716-03 for ; Fri, 9 Jan 2004 12:58:54 -0400 (AST) Received: from relay.netbox.cz (relay.netbox.cz [212.96.166.9]) by svr1.postgresql.org (Postfix) with ESMTP id BD8E8D1DCDB for ; Fri, 9 Jan 2004 11:14:58 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by localhost.netbox.cz (Postfix) with ESMTP id C7AB437B72 for ; Fri, 9 Jan 2004 16:14:46 +0100 (CET) Received: from relay.netbox.cz ([127.0.0.1]) by localhost (relay [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 13017-01-15 for ; Fri, 9 Jan 2004 16:14:45 +0100 (CET) Received: from smtp.pzkagis.cz (gis.netbox.cz [212.96.173.85]) by relay.netbox.cz (Postfix) with ESMTP id 2038E37B0D for ; Fri, 9 Jan 2004 16:14:45 +0100 (CET) Received: (from luf@localhost) by smtp.pzkagis.cz (8.11.6/8.11.6) id i09FEic12627 for pgsql-odbc@postgresql.org; Fri, 9 Jan 2004 16:14:44 +0100 Date: Fri, 9 Jan 2004 16:14:44 +0100 From: Ludek Finstrle To: pgsql-odbc@postgresql.org Subject: schema and win1250 support + misc Message-ID: <20040109151444.GA12471@soptik.pzkagis.cz> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0OAP2g/MAC+5xKAE" Content-Disposition: inline User-Agent: Mutt/1.4i X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at relay.netbox.cz X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/18 X-Sequence-Number: 3647 --0OAP2g/MAC+5xKAE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, I need schema support in odbc driver (it means change schema when connecting) more user friendly. So I attach patch for US only. Second patch contains support for win1250 encoding and one (I think) bug fix. It's in pgtypes.c in getCharColumnSize. This function call SC_get_Curres which can return NULL and getCharColumnSize doesn't handle it. Comments are welcome Luf P.S. I use diff -iwaru to create *.diff. I create diffs againist CVS snapshoted today. --0OAP2g/MAC+5xKAE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="odbc-schema.diff" diff -iwaru PgSQL.orig/ODBC/connection.c PgSQL/ODBC/connection.c --- PgSQL.orig/ODBC/connection.c 2004-01-09 14:22:11.000000000 +0100 +++ PgSQL/ODBC/connection.c 2004-01-09 15:16:10.976734400 +0100 @@ -728,7 +728,7 @@ return 0; } - mylog("CC_connect(): DSN = '%s', server = '%s', port = '%s', database = '%s', username = '%s', password='%s'\n", ci->dsn, ci->server, ci->port, ci->database, ci->username, ci->password ? "xxxxx" : ""); + mylog("CC_connect(): DSN = '%s', server = '%s', port = '%s', database = '%s', schema = '%s', username = '%s', password='%s'\n", ci->dsn, ci->server, ci->port, ci->database, ci->schema, ci->username, ci->password ? "xxxxx" : ""); another_version_retry: @@ -1882,6 +1882,7 @@ char status = TRUE; char *cs, *ptr; + char schema[MEDIUM_REGISTRY_LEN+22]; #ifdef HAVE_STRTOK_R char *last; #endif /* HAVE_STRTOK_R */ @@ -1942,6 +1943,18 @@ } + /* schema (applicable since 7.3) */ + if (self->schema_support && ci->schema && strlen(ci->schema)) + { + snprintf(schema, sizeof(schema), "set search_path to '%s'", ci->schema); + result = PGAPI_ExecDirect(hstmt, schema, SQL_NTS, 0); + if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) + status = FALSE; + + mylog("%s: result %d, status %d from set search_path\n", func, result, status); + + } + /* Global settings */ if (ci->drivers.conn_settings[0] != '\0') { diff -iwaru PgSQL.orig/ODBC/connection.h PgSQL/ODBC/connection.h --- PgSQL.orig/ODBC/connection.h 2004-01-09 14:22:11.000000000 +0100 +++ PgSQL/ODBC/connection.h 2004-01-09 15:16:56.572297600 +0100 @@ -234,6 +234,7 @@ char drivername[MEDIUM_REGISTRY_LEN]; char server[MEDIUM_REGISTRY_LEN]; char database[MEDIUM_REGISTRY_LEN]; + char schema[MEDIUM_REGISTRY_LEN]; char username[MEDIUM_REGISTRY_LEN]; char password[MEDIUM_REGISTRY_LEN]; char conn_settings[LARGE_REGISTRY_LEN]; diff -iwaru PgSQL.orig/ODBC/dlg_specific.c PgSQL/ODBC/dlg_specific.c --- PgSQL.orig/ODBC/dlg_specific.c 2004-01-09 14:22:11.000000000 +0100 +++ PgSQL/ODBC/dlg_specific.c 2004-01-09 15:22:24.003120000 +0100 @@ -271,6 +271,9 @@ else if (stricmp(attribute, "driver") == 0) strcpy(ci->drivername, value); + else if (stricmp(attribute, INI_SCHEMA) == 0) + strcpy(ci->schema, value); + else if (stricmp(attribute, INI_DATABASE) == 0) strcpy(ci->database, value); @@ -328,7 +331,7 @@ else if (stricmp(attribute, "CX") == 0) unfoldCXAttribute(ci, value); - mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s',conn_settings='%s',disallow_premature=%d)\n", ci->dsn, ci->server, ci->database, ci->username, ci->password ? "xxxxx" : "", ci->port, ci->onlyread, ci->protocol, ci->conn_settings, ci->disallow_premature); + mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',schema='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s',conn_settings='%s',disallow_premature=%d)\n", ci->dsn, ci->server, ci->database, ci->schema, ci->username, ci->password ? "xxxxx" : "", ci->port, ci->onlyread, ci->protocol, ci->conn_settings, ci->disallow_premature); } void @@ -483,6 +486,9 @@ if (ci->database[0] == '\0' || overwrite) SQLGetPrivateProfileString(DSN, INI_DATABASE, "", ci->database, sizeof(ci->database), ODBC_INI); + if (ci->schema[0] == '\0' || overwrite) + SQLGetPrivateProfileString(DSN, INI_SCHEMA, "", ci->schema, sizeof(ci->schema), ODBC_INI); + if (ci->username[0] == '\0' || overwrite) SQLGetPrivateProfileString(DSN, INI_USER, "", ci->username, sizeof(ci->username), ODBC_INI); @@ -581,11 +587,12 @@ /* Allow override of odbcinst.ini parameters here */ getCommonDefaults(DSN, ODBC_INI, ci); - qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n", + qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',schema='%s',user='%s',passwd='%s'\n", DSN, ci->server, ci->port, ci->database, + ci->schema, ci->username, ci->password ? "xxxxx" : ""); qlog(" onlyread='%s',protocol='%s',showoid='%s',fakeoidindex='%s',showsystable='%s'\n", @@ -716,6 +723,11 @@ ODBC_INI); SQLWritePrivateProfileString(DSN, + INI_SCHEMA, + ci->schema, + ODBC_INI); + + SQLWritePrivateProfileString(DSN, INI_SERVER, ci->server, ODBC_INI); diff -iwaru PgSQL.orig/ODBC/dlg_specific.h PgSQL/ODBC/dlg_specific.h --- PgSQL.orig/ODBC/dlg_specific.h 2003-08-27 13:17:53.000000000 +0200 +++ PgSQL/ODBC/dlg_specific.h 2004-01-09 15:23:10.079374400 +0100 @@ -51,6 +51,7 @@ #define INI_PORT "Port" /* Port on which the * Postmaster is listening */ #define INI_DATABASE "Database" /* Database Name */ +#define INI_SCHEMA "Schema" /* Schema Name */ #define INI_USER "Username" /* Default User Name */ #define INI_PASSWORD "Password" /* Default Password */ #define INI_DEBUG "Debug" /* Debug flag */ diff -iwaru PgSQL.orig/ODBC/dlg_wingui.c PgSQL/ODBC/dlg_wingui.c --- PgSQL.orig/ODBC/dlg_wingui.c 2003-08-27 13:17:53.000000000 +0200 +++ PgSQL/ODBC/dlg_wingui.c 2004-01-09 15:24:29.663811200 +0100 @@ -56,6 +56,7 @@ /**}**/ SetDlgItemText(hdlg, IDC_DATABASE, ci->database); + SetDlgItemText(hdlg, IDC_SCHEMA, ci->schema); SetDlgItemText(hdlg, IDC_SERVER, ci->server); SetDlgItemText(hdlg, IDC_USER, ci->username); SetDlgItemText(hdlg, IDC_PASSWORD, ci->password); @@ -69,6 +70,7 @@ GetDlgItemText(hdlg, IDC_DESC, ci->desc, sizeof(ci->desc)); GetDlgItemText(hdlg, IDC_DATABASE, ci->database, sizeof(ci->database)); + GetDlgItemText(hdlg, IDC_SCHEMA, ci->schema, sizeof(ci->schema)); GetDlgItemText(hdlg, IDC_SERVER, ci->server, sizeof(ci->server)); GetDlgItemText(hdlg, IDC_USER, ci->username, sizeof(ci->username)); GetDlgItemText(hdlg, IDC_PASSWORD, ci->password, sizeof(ci->password)); diff -iwaru PgSQL.orig/ODBC/psqlodbc.rc PgSQL/ODBC/psqlodbc.rc --- PgSQL.orig/ODBC/psqlodbc.rc 2003-05-14 04:32:32.000000000 +0200 +++ PgSQL/ODBC/psqlodbc.rc 2004-01-09 15:31:48.004113600 +0100 @@ -384,6 +382,8 @@ EDITTEXT IDC_DESC,192,24,107,12,ES_AUTOHSCROLL RTEXT "Data&base",IDC_STATIC,16,40,38,12,NOT WS_GROUP EDITTEXT IDC_DATABASE,57,39,72,12,ES_AUTOHSCROLL + RTEXT "Sc&hema",IDC_STATIC,151,40,38,12,NOT WS_GROUP + EDITTEXT IDC_SCHEMA,192,39,72,12,ES_AUTOHSCROLL RTEXT "&Server",IDC_STATIC,26,55,29,12,NOT WS_GROUP EDITTEXT IDC_SERVER,57,54,72,12,ES_AUTOHSCROLL RTEXT "&Port",IDC_STATIC,168,56,22,12 diff -iwaru PgSQL.orig/ODBC/resource.h PgSQL/ODBC/resource.h --- PgSQL.orig/ODBC/resource.h 2003-05-12 18:44:08.000000000 +0200 +++ PgSQL/ODBC/resource.h 2004-01-09 15:31:47.994099200 +0100 @@ -21,6 +21,7 @@ #define IDC_DESC 404 #define IDC_SERVER 407 #define IDC_DATABASE 408 +#define IDC_SCHEMA 409 #define DLG_CONFIG 1001 #define IDC_PORT 1002 #define DLG_DRIVER_CHANGE 1002 --0OAP2g/MAC+5xKAE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="odbc-misc.diff" diff -iwaru PgSQL.orig/ODBC/multibyte.c PgSQL/ODBC/multibyte.c --- PgSQL.orig/ODBC/multibyte.c 2003-12-09 11:01:38.000000000 +0100 +++ PgSQL/ODBC/multibyte.c 2004-01-09 15:50:10.459366400 +0100 @@ -397,6 +397,9 @@ case 950: wenc = "BIG5"; break; + case 1250: + wenc = "WIN1250"; + break; case 1252: if (PG_VERSION_GE(self, 7.2)) wenc = "latin9"; diff -iwaru PgSQL.orig/ODBC/pgtypes.c PgSQL/ODBC/pgtypes.c --- PgSQL.orig/ODBC/pgtypes.c 2004-01-09 14:22:11.000000000 +0100 +++ PgSQL/ODBC/pgtypes.c 2004-01-09 15:54:24.104089600 +0100 @@ -704,7 +704,8 @@ if (col < 0) return maxsize; - result = SC_get_Curres(stmt); + if (!(result = SC_get_Curres(stmt))) + return maxsize; /* * Manual Result Sets -- use assigned column width (i.e., from --0OAP2g/MAC+5xKAE--