pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedIssue with ALTER Table.
3+ messages / 2 participants
[nested] [flat]
* Issue with ALTER Table.
@ 2013-03-20 15:49 BGoebel <b.goebel@prisma-computer.de>
2013-03-22 10:03 ` Re: Issue with ALTER Table. Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 1 reply; 3+ messages in thread
From: BGoebel @ 2013-03-20 15:49 UTC (permalink / raw)
To: pgsql-odbc
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.
Has someone found a another workaround, idea, hint preventing a reconnect?
regards,
BGoebel
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Issue-with-ALTER-Table-tp5749048.html
Sent from the PostgreSQL - odbc mailing list archive at Nabble.com.
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Issue with ALTER Table.
2013-03-20 15:49 Issue with ALTER Table. BGoebel <b.goebel@prisma-computer.de>
@ 2013-03-22 10:03 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2013-03-22 16:51 ` Re: Issue with ALTER Table. BGoebel <b.goebel@prisma-computer.de>
0 siblings, 1 reply; 3+ messages in thread
From: Heikki Linnakangas @ 2013-03-22 10:03 UTC (permalink / raw)
To: BGoebel <b.goebel@prisma-computer.de>; +Cc: pgsql-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);
}
}
}
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Issue with ALTER Table.
2013-03-20 15:49 Issue with ALTER Table. BGoebel <b.goebel@prisma-computer.de>
2013-03-22 10:03 ` Re: Issue with ALTER Table. Heikki Linnakangas <hlinnakangas@vmware.com>
@ 2013-03-22 16:51 ` BGoebel <b.goebel@prisma-computer.de>
0 siblings, 0 replies; 3+ messages in thread
From: BGoebel @ 2013-03-22 16:51 UTC (permalink / raw)
To: pgsql-odbc
Our test bench had an error.
psqlodbc30a.dll 9.1.2.1 is delivering the expected results.
Hiroshi wrote he had no time for check this issue, and so i never checked
our code.
I am really sorry for that.
BGoebel
Heikki Linnakangas-6 wrote
> 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@
> )
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-odbc
>
>
> alter-test.c (1K)
> <http://postgresql.1045698.n5.nabble.com/attachment/5749243/0/alter-test.c>
> common.h (5K)
> <http://postgresql.1045698.n5.nabble.com/attachment/5749243/1/common.h>
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Issue-with-ALTER-Table-tp5749048p5749301.html
Sent from the PostgreSQL - odbc mailing list archive at Nabble.com.
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2013-03-22 16:51 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-03-20 15:49 Issue with ALTER Table. BGoebel <b.goebel@prisma-computer.de>
2013-03-22 10:03 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2013-03-22 16:51 ` BGoebel <b.goebel@prisma-computer.de>
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