pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Issues when using schema names with odbc
6+ messages / 2 participants
[nested] [flat]

* Issues when using schema names with odbc
@ 2010-11-18 16:22  michael.28.smith@bt.com
  0 siblings, 1 reply; 6+ messages in thread

From: michael.28.smith@bt.com @ 2010-11-18 16:22 UTC (permalink / raw)
  To: pgsql-odbc; +Cc: stephen.hindmarch@bt.com

I think there is an issue with the following version of postgresql-odbc where I am unable to use schema names.

Using "isql "  "help table_name"  returns information about the column names but "help schema.table_name returns nothing.

This assumes the identical tables are in public.table_name and schema.table_name

I actually come across this when using asterisk realtime - I was about to raise this as an asterisk issue and came across this - which suggests it is actually an underlying odbc issue.

https://issues.asterisk.org/view.php?id=15963


Has this been seen before..?

Many Thanks

Mike

rpm -qa |grep odbc
postgresql-odbc-08.01.0200-3.1

rpm -qa |grep postgres
postgresql-server-8.1.11-1.el5_1.1
postgresql-libs-8.1.11-1.el5_1.1
postgresql-8.1.11-1.el5_1.1
postgresql-libs-8.1.11-1.el5_1.1
postgresql-odbc-08.01.0200-3.1

Asterisk 1.6.2.12,



Mike Smith
Voice & Multimedia Platform | BT Innovate & Design
Tel: +44 (0) 20 7876 8005
ClickDial Me<http://www.ibridge.bt.com/ClickDial/MakeCall?+442078768005;

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Issues when using schema names with odbc
@ 2010-11-20 02:33  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: michael.28.smith@bt.com
  0 siblings, 2 replies; 6+ messages in thread

From: Hiroshi Inoue @ 2010-11-20 02:33 UTC (permalink / raw)
  To: michael.28.smith@bt.com; +Cc: pgsql-odbc; stephen.hindmarch@bt.com

(2010/11/19 1:22), michael.28.smith@bt.com wrote:
> I think there is an issue with the following version of postgresql-odbc
> where I am unable to use schema names.
>
> Using “isql ” “help table_name” returns information about the column
> names but “help schema.table_name returns nothing.

ODBC doesn't handle schema_name.table_name type format.
For example the syntax of SQLColumns() is as follows.

	SQLRETURN SQLColumns(
		SQLHSTMT       StatementHandle,
		SQLCHAR *      CatalogName,
		SQLSMALLINT    NameLength1,
		SQLCHAR *      SchemaName,
		SQLSMALLINT    NameLength2,
		SQLCHAR *      TableName,
		SQLSMALLINT    NameLength3,
		SQLCHAR *      ColumnName,
		SQLSMALLINT    NameLength4);

regards,
Hiroshi Inoue

> This assumes the identical tables are in public.table_name and
> schema.table_name
>
> I actually come across this when using asterisk realtime – I was about
> to raise this as an asterisk issue and came across this – which suggests
> it is actually an underlying odbc issue.
>
> https://issues.asterisk.org/view.php?id=15963
>
> Has this been seen before..?
>
> Many Thanks
>
> Mike
>
> rpm -qa |grep odbc
>
> postgresql-odbc-08.01.0200-3.1
>
> rpm -qa |grep postgres
>
> postgresql-server-8.1.11-1.el5_1.1
>
> postgresql-libs-8.1.11-1.el5_1.1
>
> postgresql-8.1.11-1.el5_1.1
>
> postgresql-libs-8.1.11-1.el5_1.1
>
> postgresql-odbc-08.01.0200-3.1
>
> Asterisk 1.6.2.12



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Issues when using schema names with odbc
@ 2010-11-29 14:51  michael.28.smith@bt.com
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  1 sibling, 1 reply; 6+ messages in thread

From: michael.28.smith@bt.com @ 2010-11-29 14:51 UTC (permalink / raw)
  To: inoue@tpf.co.jp; +Cc: pgsql-odbc; stephen.hindmarch@bt.com

Used a little test app to verify this and I get different results,

Assuming create schema test_schema;

create table public.test(
	row1 int,
	row2 text);

create table test_schema.test(
	row_t_1 int,
	row_t_2 text);

grant usage on schema test_schema to public;
grant select on public.test to public;
grant select on test_schema.test to public;

insert into public.test values (1,'public schema');
insert into test_schema.test values (2,'test schema');



The test app shows the following results....:


[root@winston scripts]# ./sqltest
SQLColumns Connection Test
Handles Allocated

Getting columns from test_schema.test
No data!

Getting all rows from test_schema.test
Row 0:1=2;2=test schema;

Getting columns from public.test
No data!

Getting all rows from public.test
Row 0:1=1;2=public schema;

Getting columns from (null).test
Column 0: row
Column 1: row
Column 2: row
Column 3: row

Getting all rows from (null).test
Row 0:1=1;2=public schema;


It shows that when using schema.table_name no column data is returned, but returns when not using a schema name.

Any other ideas?

Cheers


Mike Smith
Voice & Multimedia Platform | BT Innovate & Design
Tel: +44 (0) 20 7876 8005
ClickDial Me


-----Original Message-----
From: Hiroshi Inoue [mailto:inoue@tpf.co.jp] 
Sent: 20 November 2010 02:33
To: Smith,M,Michael,DLW C
Cc: pgsql-odbc@postgresql.org; Hindmarch,SJ,Stephen,DLW R
Subject: Re: [ODBC] Issues when using schema names with odbc

(2010/11/19 1:22), michael.28.smith@bt.com wrote:
> I think there is an issue with the following version of postgresql-odbc
> where I am unable to use schema names.
>
> Using "isql " "help table_name" returns information about the column
> names but "help schema.table_name returns nothing.

ODBC doesn't handle schema_name.table_name type format.
For example the syntax of SQLColumns() is as follows.

	SQLRETURN SQLColumns(
		SQLHSTMT       StatementHandle,
		SQLCHAR *      CatalogName,
		SQLSMALLINT    NameLength1,
		SQLCHAR *      SchemaName,
		SQLSMALLINT    NameLength2,
		SQLCHAR *      TableName,
		SQLSMALLINT    NameLength3,
		SQLCHAR *      ColumnName,
		SQLSMALLINT    NameLength4);

regards,
Hiroshi Inoue

> This assumes the identical tables are in public.table_name and
> schema.table_name
>
> I actually come across this when using asterisk realtime - I was about
> to raise this as an asterisk issue and came across this - which suggests
> it is actually an underlying odbc issue.
>
> https://issues.asterisk.org/view.php?id=15963
>
> Has this been seen before..?
>
> Many Thanks
>
> Mike
>
> rpm -qa |grep odbc
>
> postgresql-odbc-08.01.0200-3.1
>
> rpm -qa |grep postgres
>
> postgresql-server-8.1.11-1.el5_1.1
>
> postgresql-libs-8.1.11-1.el5_1.1
>
> postgresql-8.1.11-1.el5_1.1
>
> postgresql-libs-8.1.11-1.el5_1.1
>
> postgresql-odbc-08.01.0200-3.1
>
> Asterisk 1.6.2.12



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Issues when using schema names with odbc
@ 2010-11-29 15:03  michael.28.smith@bt.com
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  1 sibling, 0 replies; 6+ messages in thread

From: michael.28.smith@bt.com @ 2010-11-29 15:03 UTC (permalink / raw)
  To: michael.28.smith@bt.com; inoue@tpf.co.jp; +Cc: pgsql-odbc; stephen.hindmarch@bt.com


Attaching test app source for reference.



Mike Smith
Voice & Multimedia Platform | BT Innovate & Design
Tel: +44 (0) 20 7876 8005
ClickDial Me


-----Original Message-----
From: Smith,M,Michael,DLW C 
Sent: 29 November 2010 14:51
To: 'Hiroshi Inoue'
Cc: pgsql-odbc@postgresql.org; Hindmarch,SJ,Stephen,DLW R
Subject: RE: [ODBC] Issues when using schema names with odbc

Used a little test app to verify this and I get different results,

Assuming create schema test_schema;

create table public.test(
	row1 int,
	row2 text);

create table test_schema.test(
	row_t_1 int,
	row_t_2 text);

grant usage on schema test_schema to public;
grant select on public.test to public;
grant select on test_schema.test to public;

insert into public.test values (1,'public schema');
insert into test_schema.test values (2,'test schema');



The test app shows the following results....:


[root@winston scripts]# ./sqltest
SQLColumns Connection Test
Handles Allocated

Getting columns from test_schema.test
No data!

Getting all rows from test_schema.test
Row 0:1=2;2=test schema;

Getting columns from public.test
No data!

Getting all rows from public.test
Row 0:1=1;2=public schema;

Getting columns from (null).test
Column 0: row
Column 1: row
Column 2: row
Column 3: row

Getting all rows from (null).test
Row 0:1=1;2=public schema;


It shows that when using schema.table_name no column data is returned, but returns when not using a schema name.

Any other ideas?

Cheers


Mike Smith
Voice & Multimedia Platform | BT Innovate & Design
Tel: +44 (0) 20 7876 8005
ClickDial Me


-----Original Message-----
From: Hiroshi Inoue [mailto:inoue@tpf.co.jp] 
Sent: 20 November 2010 02:33
To: Smith,M,Michael,DLW C
Cc: pgsql-odbc@postgresql.org; Hindmarch,SJ,Stephen,DLW R
Subject: Re: [ODBC] Issues when using schema names with odbc

(2010/11/19 1:22), michael.28.smith@bt.com wrote:
> I think there is an issue with the following version of postgresql-odbc
> where I am unable to use schema names.
>
> Using "isql " "help table_name" returns information about the column
> names but "help schema.table_name returns nothing.

ODBC doesn't handle schema_name.table_name type format.
For example the syntax of SQLColumns() is as follows.

	SQLRETURN SQLColumns(
		SQLHSTMT       StatementHandle,
		SQLCHAR *      CatalogName,
		SQLSMALLINT    NameLength1,
		SQLCHAR *      SchemaName,
		SQLSMALLINT    NameLength2,
		SQLCHAR *      TableName,
		SQLSMALLINT    NameLength3,
		SQLCHAR *      ColumnName,
		SQLSMALLINT    NameLength4);

regards,
Hiroshi Inoue

> This assumes the identical tables are in public.table_name and
> schema.table_name
>
> I actually come across this when using asterisk realtime - I was about
> to raise this as an asterisk issue and came across this - which suggests
> it is actually an underlying odbc issue.
>
> https://issues.asterisk.org/view.php?id=15963
>
> Has this been seen before..?
>
> Many Thanks
>
> Mike
>
> rpm -qa |grep odbc
>
> postgresql-odbc-08.01.0200-3.1
>
> rpm -qa |grep postgres
>
> postgresql-server-8.1.11-1.el5_1.1
>
> postgresql-libs-8.1.11-1.el5_1.1
>
> postgresql-8.1.11-1.el5_1.1
>
> postgresql-libs-8.1.11-1.el5_1.1
>
> postgresql-odbc-08.01.0200-3.1
>
> Asterisk 1.6.2.12

Attachments:

sqltest.c (text/plain, 5.5K) download #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <sql.h> #include <sqlext.h> #include <sqltypes.h> /* SQL Test. Test the SQLColumns feature of odbc to check that schemas can be * used. * $URL: https://svn.coolworld.bt.co.uk/svn/sjh/trunk/scripts/sqltest.c $ * $Author: sjh $ * $Date: 2010-11-29 10:56:21 +0000 (Mon, 29 Nov 2010) $ * $Revision: 268 $ * * Copyright British Telecommunications PLC 2009 * */ /* This function courtesy of the unixODBC tutorial * http://www.easysoft.com/developer/languages/c/odbc_tutorial.html */ void print_error(char *location,SQLHANDLE handle,SQLSMALLINT type) { SQLINTEGER i = 0; SQLINTEGER native; SQLCHAR state[ 7 ]; SQLCHAR text[256]; SQLSMALLINT len; SQLRETURN ret; printf("Error encountered in %s\n Diagnostics follow:-\n",location); do{ ret = SQLGetDiagRec(type, handle, ++i, state, &native, text, sizeof(text), &len ); if (SQL_SUCCEEDED(ret)) printf("%s:%ld:%ld:%s\n", state, i, native, text); }while(ret == SQL_SUCCESS); } SQLCHAR *get_column_name(SQLHSTMT stmt,char *buf){ SQLINTEGER name_col=4; SQLLEN ind; SQLGetData(stmt,name_col,SQL_C_CHAR,buf,sizeof(buf),&ind); return buf; } int show_columns(SQLHSTMT stmt,unsigned char *schema,unsigned char *table){ SQLRETURN ret; SQLSMALLINT res; char buf[255]; int i=0; /* Do a SQLColumns on the table */ if(!SQL_SUCCEEDED(ret=SQLColumns(stmt, NULL,0, schema,schema?SQL_NTS:0, table,SQL_NTS, (unsigned char *)"%", SQL_NTS))){ print_error("SQLColumns",stmt,SQL_HANDLE_STMT); return ret; } /* Loop through results to enumerate the columns */ while((ret=SQLFetch(stmt)) != SQL_NO_DATA && ret!=SQL_ERROR){ printf("Column %i: %s\n",i++,get_column_name(stmt,buf)); } /* Why were no columns described? */ if(i==0){ switch(ret){ case SQL_NO_DATA:printf("No data!\n"); break; case SQL_ERROR:printf("Error!\n"); break; default: printf("Other=%i\n",ret); } } return ret; } int describe_table(SQLHDBC con,SQLCHAR *schema,SQLCHAR *table){ SQLRETURN ret; SQLHSTMT stmt; printf("\nGetting columns from %s.%s\n",schema,table); if(!SQL_SUCCEEDED(ret=SQLAllocHandle(SQL_HANDLE_STMT,con,&stmt))){ print_error("stmt handle",stmt,SQL_HANDLE_STMT); return ret; } ret=show_columns(stmt,schema,table); SQLFreeHandle(SQL_HANDLE_STMT, stmt); return ret; } SQLCHAR *new_row_select(SQLCHAR *schema,SQLCHAR *table){ SQLCHAR *select=(SQLCHAR *)malloc(sizeof(SQLCHAR)*255); if(schema){ sprintf(select,"select * from %s.%s",schema,table); }else{ sprintf(select,"select * from %s",table); } return select; } int show_data(SQLHSTMT stmt){ SQLRETURN ret; SQLSMALLINT col; int i=0,j; /* How many columns are there? */ if(!SQL_SUCCEEDED(SQLNumResultCols(stmt,&col))){ print_error("get num columns",stmt,SQL_HANDLE_STMT); return 0; } /* Loop through results to display the data */ while((ret=SQLFetch(stmt)) != SQL_NO_DATA && ret!=SQL_ERROR){ printf("Row %i:",i++); for(j=1;j<=col;j++){ SQLLEN ind; char buf[255]; if(SQL_SUCCEEDED( SQLGetData(stmt,j,SQL_C_CHAR,buf,sizeof(buf),&ind))){ if(ind==SQL_NULL_DATA) printf("%i=NULL;",j); else printf("%i=%s;",j,buf); } } printf("\n"); } return i; } int select_table(SQLHDBC con,SQLCHAR *schema,SQLCHAR *table){ SQLRETURN ret; SQLHSTMT stmt; SQLCHAR *select; printf("\nGetting all rows from %s.%s\n",schema,table); if(!SQL_SUCCEEDED(ret=SQLAllocHandle(SQL_HANDLE_STMT,con,&stmt))){ print_error("stmt handle",stmt,SQL_HANDLE_STMT); return ret; } select=new_row_select(schema,table); if(!SQL_SUCCEEDED(ret=SQLExecDirect(stmt,select,SQL_NTS))){ print_error("stmt select",stmt,SQL_HANDLE_STMT); return ret; } show_data(stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt); free(select); return ret; } int main(int argc, char **argv){ SQLHENV env; SQLHDBC dbc; SQLRETURN ret; SQLCHAR *dsn="pbx"; SQLCHAR *schema="test_schema"; SQLCHAR *public="public"; SQLCHAR *table="test"; printf("SQLColumns Connection Test\n"); /* Create connection handles */ if(!SQL_SUCCEEDED(ret=SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env))){ print_error("env handle",dbc,SQL_HANDLE_ENV); } if(!SQL_SUCCEEDED(ret=SQLSetEnvAttr( env,SQL_ATTR_ODBC_VERSION,(void *)SQL_OV_ODBC2, 0))){ print_error("odbc version",dbc,SQL_HANDLE_ENV); } if(!SQL_SUCCEEDED(ret=SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc))){ print_error("connection handle",dbc,SQL_HANDLE_DBC); } printf("Handles Allocated\n"); /* Connect to the database */ if(!SQL_SUCCEEDED(ret=SQLConnect(dbc,dsn,SQL_NTS,NULL,0,NULL,0))){ print_error("connection",dbc,SQL_HANDLE_DBC); } /* In turn, describe each table and get the contents */ describe_table(dbc,schema,table); select_table(dbc,schema,table); describe_table(dbc,public,table); select_table(dbc,public,table); describe_table(dbc,NULL,table); select_table(dbc,NULL,table); /* Free handles */ SQLFreeHandle(SQL_HANDLE_DBC, dbc); SQLFreeHandle(SQL_HANDLE_ENV, env); }
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: Issues when using schema names with odbc
@ 2010-11-30 14:17  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: michael.28.smith@bt.com
  0 siblings, 1 reply; 6+ messages in thread

From: Hiroshi Inoue @ 2010-11-30 14:17 UTC (permalink / raw)
  To: michael.28.smith@bt.com; +Cc: pgsql-odbc; stephen.hindmarch@bt.com

(2010/11/29 23:51), michael.28.smith@bt.com wrote:
> Used a little test app to verify this and I get different results,
>
> Assuming create schema test_schema;
>
> create table public.test(
> 	row1 int,
> 	row2 text);
>
> create table test_schema.test(
> 	row_t_1 int,
> 	row_t_2 text);
>
> grant usage on schema test_schema to public;
> grant select on public.test to public;
> grant select on test_schema.test to public;
>
> insert into public.test values (1,'public schema');
> insert into test_schema.test values (2,'test schema');
>
> The test app shows the following results....:
>
> [root@winston scripts]# ./sqltest
> SQLColumns Connection Test
> Handles Allocated
>
> Getting columns from test_schema.test
> No data!
>
> Getting all rows from test_schema.test
> Row 0:1=2;2=test schema;
>
> Getting columns from public.test
> No data!
>
> Getting all rows from public.test
> Row 0:1=1;2=public schema;
>
> Getting columns from (null).test
> Column 0: row
> Column 1: row
> Column 2: row
> Column 3: row
>
> Getting all rows from (null).test
> Row 0:1=1;2=public schema;

Which version of psqlodbc driver are you using?
Here I get the following results.

Getting columns from test_schema.test
Column 0: row_t_1
Column 1: row_t_2

Getting all rows from test_schema.test
Row 0:1=2;2=test schema;

Getting columns from public.test
Column 0: row1
Column 1: row2

Getting all rows from public.test
Row 0:1=1;2=public schema;

Getting columns from (null).test
Column 0: row1
Column 1: row2

Getting all rows from (null).test
Row 0:1=1;2=public schema;

regards,
Hiroshi Inoue




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Issues when using schema names with odbc
@ 2010-11-30 14:38  michael.28.smith@bt.com
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 0 replies; 6+ messages in thread

From: michael.28.smith@bt.com @ 2010-11-30 14:38 UTC (permalink / raw)
  To: inoue@tpf.co.jp; +Cc: pgsql-odbc; stephen.hindmarch@bt.com

[btoc@rdl10090app15 ~]$ rpm -qa |grep odbc
postgresql-odbc-08.01.0200-3.1

Are you using a later version ? is so which one and any ideas what version it has been fixed in ?

Cheers


Mike Smith
Voice & Multimedia Platform | BT Innovate & Design
Tel: +44 (0) 20 7876 8005
ClickDial Me

-----Original Message-----
From: Hiroshi Inoue [mailto:inoue@tpf.co.jp] 
Sent: 30 November 2010 14:17
To: Smith,M,Michael,DLW C
Cc: pgsql-odbc@postgresql.org; Hindmarch,SJ,Stephen,DLW R
Subject: Re: [ODBC] Issues when using schema names with odbc

(2010/11/29 23:51), michael.28.smith@bt.com wrote:
> Used a little test app to verify this and I get different results,
>
> Assuming create schema test_schema;
>
> create table public.test(
> 	row1 int,
> 	row2 text);
>
> create table test_schema.test(
> 	row_t_1 int,
> 	row_t_2 text);
>
> grant usage on schema test_schema to public;
> grant select on public.test to public;
> grant select on test_schema.test to public;
>
> insert into public.test values (1,'public schema');
> insert into test_schema.test values (2,'test schema');
>
> The test app shows the following results....:
>
> [root@winston scripts]# ./sqltest
> SQLColumns Connection Test
> Handles Allocated
>
> Getting columns from test_schema.test
> No data!
>
> Getting all rows from test_schema.test
> Row 0:1=2;2=test schema;
>
> Getting columns from public.test
> No data!
>
> Getting all rows from public.test
> Row 0:1=1;2=public schema;
>
> Getting columns from (null).test
> Column 0: row
> Column 1: row
> Column 2: row
> Column 3: row
>
> Getting all rows from (null).test
> Row 0:1=1;2=public schema;

Which version of psqlodbc driver are you using?
Here I get the following results.

Getting columns from test_schema.test
Column 0: row_t_1
Column 1: row_t_2

Getting all rows from test_schema.test
Row 0:1=2;2=test schema;

Getting columns from public.test
Column 0: row1
Column 1: row2

Getting all rows from public.test
Row 0:1=1;2=public schema;

Getting columns from (null).test
Column 0: row1
Column 1: row2

Getting all rows from (null).test
Row 0:1=1;2=public schema;

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2010-11-30 14:38 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-11-18 16:22 Issues when using schema names with odbc michael.28.smith@bt.com
2010-11-20 02:33 ` Hiroshi Inoue <inoue@tpf.co.jp>
2010-11-29 14:51   ` michael.28.smith@bt.com
2010-11-30 14:17     ` Hiroshi Inoue <inoue@tpf.co.jp>
2010-11-30 14:38       ` michael.28.smith@bt.com
2010-11-29 15:03   ` michael.28.smith@bt.com

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