Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIypB-0003OB-Vr for pgsql-odbc@arkaria.postgresql.org; Fri, 22 Mar 2013 10:03:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UIypB-0007w3-Dm for pgsql-odbc@arkaria.postgresql.org; Fri, 22 Mar 2013 10:03:49 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIyp9-0007tk-64 for pgsql-odbc@postgresql.org; Fri, 22 Mar 2013 10:03:47 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIyp4-0002a1-GT for pgsql-odbc@postgresql.org; Fri, 22 Mar 2013 10:03:45 +0000 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 06E742899A; Fri, 22 Mar 2013 03:03:37 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 03216400F3; Fri, 22 Mar 2013 03:03:37 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id 39DAA1219D1; Fri, 22 Mar 2013 03:07:32 -0700 (PDT) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-1.vmware.com Received: from zcs-prod-ext-mta-1.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-1.vmware.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6-lhsBuyfILf; Fri, 22 Mar 2013 03:07:31 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id D9EE81219C3; Fri, 22 Mar 2013 03:07:31 -0700 (PDT) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA; Fri, 22 Mar 2013 03:07:30 -0700 (PDT) Message-ID: <514C2C75.20302@vmware.com> Date: Fri, 22 Mar 2013 12:03:33 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: BGoebel CC: pgsql-odbc@postgresql.org Subject: Re: Issue with ALTER Table. References: <1363794560171-5749048.post@n5.nabble.com> In-Reply-To: <1363794560171-5749048.post@n5.nabble.com> Content-Type: multipart/mixed; boundary="------------080403020802090902030204" X-Pg-Spam-Score: -8.3 (--------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org This is a multi-part message in MIME format. --------------080403020802090902030204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 20.03.2013 17:49, BGoebel wrote: > The Catalog Schema seems not to be actualized when using ALTER Table. > > I had reported a problem with adding NEW tables, which was corrected by > Hiroshi > > http://postgresql.1045698.n5.nabble.com/SQLDescribeCol-schema-cache-not-being-updated-completely-tt4372956.html > > http://postgresql.1045698.n5.nabble.com/Error-Retrieving-Catalog-Info-tt4598955.html > > When "altering" a Datatype of column the problem still exists: > Say, we have a column which is defined as varchar(40) > Now we want to double the field length to varchar(80) > > ALTER TABLE customer > ALTER COLUMN address TYPE varchar(80), > > When we retrieving the Catalog-Info the value of field length is 40 > furthermore. > > After a new connect we get the correct values and only after that writing / > reading to the altered field is working reliable. Can you provide a self-contained test case? That seems like the exact same thing reported by Jan-Peter Seifelt, in the first thread that you linked to, and that one was fixed. I can't reproduce it here, either. I tested the attached test case, but it correctly prints the new size after ALTER. - Heikki --------------080403020802090902030204 Content-Type: text/x-csrc; name="alter-test.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="alter-test.c" #include #include #include "common.h" int main(int argc, char **argv) { SQLRETURN rc; HSTMT hstmt = SQL_NULL_HSTMT; char *param1; SQLLEN cbParam1; long longparam; SQL_INTERVAL_STRUCT intervalparam; SQLSMALLINT colcount; test_connect(); rc = SQLAllocStmt(conn, &hstmt); if (!SQL_SUCCEEDED(rc)) { print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); exit(1); } /* Create a table to test with */ rc = SQLExecDirect(hstmt, (SQLCHAR *) "CREATE TEMPORARY TABLE testtbl(t varchar(40))", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); /**** A simple query against the table, fetch column info ****/ rc = SQLExecDirect(hstmt, "SELECT * FROM testtbl", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); /* Get column metadata */ print_result_meta(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Alter the table */ rc = SQLExecDirect(hstmt, (SQLCHAR *) "ALTER TABLE testtbl ALTER COLUMN t TYPE varchar(80)", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); /* Run the query again, check if the metadata was updated */ rc = SQLExecDirect(hstmt, "SELECT * FROM testtbl", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); /* Get column metadata */ print_result_meta(hstmt); /* Clean up */ test_disconnect(); return 0; } --------------080403020802090902030204 Content-Type: text/x-chdr; name="common.h" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="common.h" #include #include #include #include static SQLHENV env; static SQLHDBC conn; #define CHECK_STMT_RESULT(rc, msg, hstmt) \ if (!SQL_SUCCEEDED(rc)) \ { \ print_diag(msg, SQL_HANDLE_STMT, hstmt); \ exit(1); \ } static void print_diag(char *msg, SQLSMALLINT htype, SQLHANDLE handle) { char sqlstate[32]; char message[1000]; SQLINTEGER nativeerror; SQLSMALLINT textlen; SQLRETURN ret; if (msg) printf("%s\n", msg); ret = SQLGetDiagRec(htype, handle, 1, sqlstate, &nativeerror, message, 256, &textlen); if (ret != SQL_ERROR) printf("%s=%s\n", (CHAR *)sqlstate, (CHAR *)message); } static void test_connect_ext(char *extraparams) { SQLRETURN ret; SQLCHAR str[1024]; SQLSMALLINT strl; SQLCHAR dsn[1024]; snprintf(dsn, sizeof(dsn), "DSN=psqlodbc_test_dsn;%s", extraparams ? extraparams : ""); SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env); SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0); SQLAllocHandle(SQL_HANDLE_DBC, env, &conn); ret = SQLDriverConnect(conn, NULL, dsn, SQL_NTS, str, sizeof(str), &strl, SQL_DRIVER_COMPLETE); if (SQL_SUCCEEDED(ret)) { printf("connected\n"); } else { print_diag("SQLDriverConnect failed.", SQL_HANDLE_DBC, conn); exit(1); } } static void test_connect(void) { test_connect_ext(NULL); } static void test_disconnect(void) { SQLRETURN rc; printf("disconnecting\n"); rc = SQLDisconnect(conn); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLDisconnect failed", SQL_HANDLE_DBC, conn); exit(1); } rc = SQLFreeConnect(conn); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLFreeConnect failed", SQL_HANDLE_DBC, conn); exit(1); } conn = NULL; rc = SQLFreeEnv(env); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLFreeEnv failed", SQL_HANDLE_ENV, env); exit(1); } env = NULL; } static const char * datatype_str(SQLSMALLINT datatype) { static char buf[100]; switch (datatype) { case SQL_CHAR: return "CHAR"; case SQL_VARCHAR: return "VARCHAR"; case SQL_LONGVARCHAR: return "LONGVARCHAR"; case SQL_WCHAR: return "WCHAR"; case SQL_WVARCHAR: return "WVARCHAR"; case SQL_WLONGVARCHAR: return "WLONGVARCHAR"; case SQL_DECIMAL: return "DECIMAL"; case SQL_NUMERIC: return "NUMERIC"; case SQL_SMALLINT: return "SMALLINT"; case SQL_INTEGER: return "INTEGER"; case SQL_REAL: return "REAL"; case SQL_FLOAT: return "FLOAT"; case SQL_DOUBLE: return "DOUBLE"; case SQL_BIT: return "BIT"; case SQL_TINYINT: return "TINYINT"; case SQL_BIGINT: return "BIGINT"; case SQL_BINARY: return "BINARY"; case SQL_VARBINARY: return "VARBINARY"; case SQL_LONGVARBINARY: return "LONGVARBINARY"; case SQL_TYPE_DATE: return "TYPE_DATE"; case SQL_TYPE_TIME: return "TYPE_TIME"; case SQL_TYPE_TIMESTAMP: return "TYPE_TIMESTAMP"; case SQL_GUID: return "GUID"; default: snprintf(buf, sizeof(buf), "unknown sql type %d", datatype); return buf; } } static const char *nullable_str(SQLSMALLINT nullable) { static char buf[100]; switch(nullable) { case SQL_NO_NULLS: return "not nullable"; case SQL_NULLABLE: return "nullable"; case SQL_NULLABLE_UNKNOWN: return "nullable_unknown"; default: snprintf(buf, sizeof(buf), "unknown nullable value %d", nullable); return buf; } } static void print_result_meta(HSTMT hstmt) { SQLRETURN rc; SQLSMALLINT numcols; int i; rc = SQLNumResultCols(hstmt, &numcols); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLNumResultCols failed", SQL_HANDLE_STMT, hstmt); return; } printf("Result set metadata:\n"); for (i = 1; i <= numcols; i++) { SQLCHAR colname[50]; SQLSMALLINT colnamelen; SQLSMALLINT datatype; SQLULEN colsize; SQLSMALLINT decdigits; SQLSMALLINT nullable; rc = SQLDescribeCol(hstmt, i, colname, sizeof(colname), &colnamelen, &datatype, &colsize, &decdigits, &nullable); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLDescribeCol failed", SQL_HANDLE_STMT, hstmt); return; } printf("%s: %s(%d) digits: %d, %s\n", colname, datatype_str(datatype), colsize, decdigits, nullable_str(nullable)); } } static void print_result(HSTMT hstmt) { SQLRETURN rc; SQLSMALLINT numcols; rc = SQLNumResultCols(hstmt, &numcols); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLNumResultCols failed", SQL_HANDLE_STMT, hstmt); return; } printf("Result set:\n"); while(1) { rc = SQLFetch(hstmt); if (rc == SQL_NO_DATA) break; if (rc == SQL_SUCCESS) { char buf[40]; int i; SQLLEN ind; for (i = 1; i <= numcols; i++) { rc = SQLGetData(hstmt,i, SQL_C_CHAR, buf, sizeof(buf), &ind); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLGetData failed", SQL_HANDLE_STMT, hstmt); return; } if (ind == SQL_NULL_DATA) strcpy(buf, "NULL"); printf("%s%s", (i > 1) ? "\t" : "", buf); } printf("\n"); } else { print_diag("SQLFetch failed", SQL_HANDLE_STMT, hstmt); exit(1); } } } --------------080403020802090902030204 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --------------080403020802090902030204--