[Gambas-user] PostgreSQL multiple column problem
Fabien Bodard
gambas.fr at ...626...
Wed Oct 17 10:27:37 CEST 2012
I think there is not simple way for that. It's a collection of names. You
need to distinct the by your self.
Le 16 oct. 2012 22:34, "Markus Schatten" <markus.schatten at ...2005...> a écrit :
> Dear all,
>
> I have a problem with a PostgreSQL connection (haven't tested it with
> other dbms'). When a query has the same attribute name for a column,
> there seems to be no way in accessing any of these columns except for
> the first one. Consider the following example.
>
> I create a table test with:
>
> db=# create table test( id serial );
>
> and insert a few rows:
>
> db=# insert into test default values;
> INSERT 0 1
> db=# insert into test default values;
> INSERT 0 1
> db=# insert into test default values;
> INSERT 0 1
> db=# select * from test;
> id
> ----
> 1
> 2
> 3
> (3 rows)
>
> Now if I issue the query:
>
> db=# select * from test t1, test t2;
> id | id
> ----+----
> 1 | 1
> 1 | 2
> 1 | 3
> 2 | 1
> 2 | 2
> 2 | 3
> 3 | 1
> 3 | 2
> 3 | 3
> (9 rows)
>
> I get, as expected, all possible combinations. But, when I create a
> datasource and a dataview in Gambas (FMain):
>
> Public con As New Connection
>
>
> Public Sub _new()
> With con
> .Type = "postgresql"
> .Name = "db"
> .User = "markus"
> .Password = "secret"
> .Open
> End With
> With DataSource1
> .Connection = con
> .Table = "SELECT * FROM test t1, test t2"
> End With
> End
>
> I get:
>
> id | id
> --------
> 1 | 1
> 1 | 1
> 1 | 1
> 2 | 2
> 2 | 2
> 2 | 2
> 3 | 3
> 3 | 3
> 3 | 3
>
> e.g. only the first id is accessed. I've also tried to implement the
> dataview manually by using a grid view but the res!att syntax doesn't
> allow me to access any other but the first id attribute. Is there a
> way to get the attributes by index?
>
> I know I could rewrite the query as "select t1.id as id1, t2.id from
> test t1, test t2" to get distinct column names, but this is not an
> option for the application at hand since it deals with user supplied
> queries. Yes, I could parse each query and rewrite it before
> executing, but this would be at least an "ugly hack".
>
> Any ideas?
>
> All the best,
>
> M.
>
>
>
>
> --
> Markus Schatten, PhD
> Assistant professor
> University of Zagreb
> Faculty of Organization and Informatics
> Pavlinska 2, 42000 Varazdin, Croatia
> http://www.foi.hr/nastavnici/schatten.markus/index.html
> http://www.researchgate.net/profile/Markus_Schatten1
>
>
> ------------------------------------------------------------------------------
> Don't let slow site performance ruin your business. Deploy New Relic APM
> Deploy New Relic app performance management and know exactly
> what is happening inside your Ruby, Python, PHP, Java, and .NET app
> Try New Relic at no cost today and get our sweet Data Nerd shirt too!
> http://p.sf.net/sfu/newrelic-dev2dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list