pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: BGoebel <b.goebel@prisma-computer.de>
Cc: pgsql-odbc@postgresql.org
Subject: Re: Issue with ALTER Table.
Date: Fri, 22 Mar 2013 12:03:33 +0200
Message-ID: <514C2C75.20302@vmware.com> (raw)
In-Reply-To: <1363794560171-5749048.post@n5.nabble.com>
References: <1363794560171-5749048.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>

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-tt4...
>
> 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

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

alter-test.c (text/x-csrc, 1.4K) download #include <stdio.h> #include <stdlib.h> #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; }
common.h (text/x-chdr, 5.3K) download #include <stdio.h> #include <string.h> #include <sql.h> #include <sqlext.h> 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); } } }

view thread (3+ messages)  latest in thread

Message-ID: <514C2C75.20302@vmware.com>
Permalink:  ../514C2C75.20302@vmware.com/
Also on:    postgresql.org/message-id/514C2C75.20302@vmware.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: hlinnakangas@vmware.com, b.goebel@prisma-computer.de
  Subject: Re: Issue with ALTER Table.
  In-Reply-To: <514C2C75.20302@vmware.com>
  References: <1363794560171-5749048.post@n5.nabble.com> <514C2C75.20302@vmware.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox