Re: [gnome-db] Gda Introspection.

I found  the glue!!!

In PyGObject when a function have out parameters, like Gda.SqlParser.parse_string and Gda.Connection.parse_sql_string, it returns a tuple with the first element as the function's return value and then, in the same order of the parameters, the out ones.

Then to use the above functions you need:

(statement, str) = parser.parse_string ("SELECT * FROM customers; SELECT * FROM parts_table")

Then statement is set to a Gda.Statement object and str to "SELECT * FROM parts_table"

Or simple access the return values from the tuple by using its index like ret_tuple[index], as recomended in the last mail.

For future problems you can take a look at:

El ene 24, 2012 6:03 p.m., "Daniel Espinosa" <esodan gmail com> escribió:
I can confirm your problem and its present even if you use Gda.Connection.parse_sql_string, the return value is a tuple with the object you need inside it. I'm using Gda from master with python 2.7.2 and with python 3.2.2 with python-gobject 3.0.0.

I've used that functions in Vala and its not present.

I've review GIR file and it's correct.

I think this is a python-gobject problem.

In the middle you can use:

stm = parser.parse_string ("YOUR SQL")
statement = stm[0]

This is because the first element in the list is a Gda.Statement, witch you can use.

Or use Gda.Connection functions to execute directly string commands like: execute_non_select, execute_select, they return Gda.DataModel objects (I tested them and works in python)

2012/1/23 Carlos Savoretti <csavoretti gmail com>
Hi !!!

Being you're working (a lot and well) with libgda introspection, I'd
like to make you some question.

In the latest version of Gda I've found a problem w introspection
binding Python

Here it is
from gi.repository import Gda

connection = Gda.Connection().open_from_dsn("test", None, 0)
print connection.get_cnc_string()
parser = Gda.SqlParser ()
print parser
statement = parser.parse_string("SELECT * FROM customers")
print statement
if statement.check_structure():
    print "yes"
    print "no"
print statement
data_model = connection.statement_execute_select(statement, set1)
print data_model

python ./ 
<SqlParser object at 0xb73f616c (GdaSqlParser at 0x856f2a0)>
(<Statement object at 0xb73f634c (GdaStatement at 0x8568210)>, None)
Traceback (most recent call last):
  File "./", line 9, in <module>
    if statement.check_structure():
AttributeError: 'tuple' object has no attribute 'check_structure'

Conclussion: It seems (after some debugging) that the parsed statement DOES NOT
return a GdaStatement Object, but rather a 'tuple' Python object...
Of course connection.statement_execute_select() claims for the same issue...
the object statement is not an 'GdaStatment'... 

Could you give some clue about the problem is Python, the introspecton libs, or
what ? It is in order to correct the bug (if any)

Many thanks for your help ...


Carlos Savoretti

Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (en trámite, pero para los cuates: LIBRE)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]