You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Horacio de Oro <hg...@uolsinectis.com.ar> on 2004/11/20 20:18:10 UTC

Bad sql generated if table name contains "-" ???

Hi!

I'm having a problem with OJB with a table of Jabber. The table name is 
roster-items and is on a PostgreSQL server.

When I try to store() an object (using the PB api) I get this log:

[org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl]
   DEBUG: SQL:INSERT INTO roster-items
     (collection-owner,jid,ask,from,name,object-sequence,to)
     VALUES (?,?,?,?,?,?,?)

and this exception:

org.apache.ojb.broker.PersistenceBrokerSQLException:
    SQL failure while insert object data for class
    JabberRosterItem (...)
    exception message is [ERROR: syntax error at or near "-"]

I think Ojb has troubles with the table name. If I execute this on psql:

SELECT * FROM roster-items;

I get this error:

jabberd2=# SELECT * FROM roster-items;
ERROR:  syntax error at or near "-" at character 21

The valid SQL for viewing the roster-items table is:

SELECT * FROM "roster-items";

The same happen with ANY table containing the '-' character, and this is 
fixed if you put the table name between double quotes...

Is there any way to make Ojb put the table name between double quotes?

Thanks in advance!

Horacio

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Bad sql generated if table name contains "-" ???

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi horacio,

i just committed the pathes to support quoting of tables and columns. testcases 
are not yet available.

the ojb quoting character is a single quote ' . the default quoting character in 
the platform is th double-quote " .

please check it out.

jakob

Jakob Braeuchi schrieb:
> hi horacio,
> 
> i'm currently working on quoting of tables and columns for ojb-1.1.
> ojb will have it's own quoting character. this character is replaced by the
> dbms-specific character when building the sql, and stripped when reading
> from result set. i already checked in parts of the solution, but i need
> additional time. i'll drop you mail as soon as i have it finished. 
> 
> jakob
> 
> 
> 
>>Hi!
>>
>>I'm having a problem with OJB with a table of Jabber. The table name is 
>>roster-items and is on a PostgreSQL server.
>>
>>When I try to store() an object (using the PB api) I get this log:
>>
>>[org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl]
>>   DEBUG: SQL:INSERT INTO roster-items
>>     (collection-owner,jid,ask,from,name,object-sequence,to)
>>     VALUES (?,?,?,?,?,?,?)
>>
>>and this exception:
>>
>>org.apache.ojb.broker.PersistenceBrokerSQLException:
>>    SQL failure while insert object data for class
>>    JabberRosterItem (...)
>>    exception message is [ERROR: syntax error at or near "-"]
>>
>>I think Ojb has troubles with the table name. If I execute this on psql:
>>
>>SELECT * FROM roster-items;
>>
>>I get this error:
>>
>>jabberd2=# SELECT * FROM roster-items;
>>ERROR:  syntax error at or near "-" at character 21
>>
>>The valid SQL for viewing the roster-items table is:
>>
>>SELECT * FROM "roster-items";
>>
>>The same happen with ANY table containing the '-' character, and this is 
>>fixed if you put the table name between double quotes...
>>
>>Is there any way to make Ojb put the table name between double quotes?
>>
>>Thanks in advance!
>>
>>Horacio
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Bad sql generated if table name contains "-" ???

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi horacio,

i'm currently working on quoting of tables and columns for ojb-1.1.
ojb will have it's own quoting character. this character is replaced by the
dbms-specific character when building the sql, and stripped when reading
from result set. i already checked in parts of the solution, but i need
additional time. i'll drop you mail as soon as i have it finished. 

jakob


> Hi!
> 
> I'm having a problem with OJB with a table of Jabber. The table name is 
> roster-items and is on a PostgreSQL server.
> 
> When I try to store() an object (using the PB api) I get this log:
> 
> [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl]
>    DEBUG: SQL:INSERT INTO roster-items
>      (collection-owner,jid,ask,from,name,object-sequence,to)
>      VALUES (?,?,?,?,?,?,?)
> 
> and this exception:
> 
> org.apache.ojb.broker.PersistenceBrokerSQLException:
>     SQL failure while insert object data for class
>     JabberRosterItem (...)
>     exception message is [ERROR: syntax error at or near "-"]
> 
> I think Ojb has troubles with the table name. If I execute this on psql:
> 
> SELECT * FROM roster-items;
> 
> I get this error:
> 
> jabberd2=# SELECT * FROM roster-items;
> ERROR:  syntax error at or near "-" at character 21
> 
> The valid SQL for viewing the roster-items table is:
> 
> SELECT * FROM "roster-items";
> 
> The same happen with ANY table containing the '-' character, and this is 
> fixed if you put the table name between double quotes...
> 
> Is there any way to make Ojb put the table name between double quotes?
> 
> Thanks in advance!
> 
> Horacio
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 

-- 
Geschenkt: 3 Monate GMX ProMail + 3 Top-Spielfilme auf DVD
++ Jetzt kostenlos testen http://www.gmx.net/de/go/mail ++

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Bad sql generated if table name contains "-" ???

Posted by Horacio de Oro <ho...@trimaxcba.com>.
Jakob Braeuchi wrote:
> hi horacio,
> 
> you'll have to quote the tablename in the repository. ojb currently does 
> not support automatic quoting.
> 
> hth
> jakob
> 

Hi again! I've add &quot; to the table name, but I have other problems now.

<class-descriptor
    class="ar.com.hdeoro.eua.model.JabberRosterItem"
    table="&quot;roster-items&quot;">

The problem is the columns collection-owner, object-sequence, etc. (with 
'-' in its names):

If I use: (without &quot;)

      <field-descriptor
         name="collectionOwner"
         column="collection-owner"
         jdbc-type="VARCHAR"
         primarykey="true"/>

I get:

org.postgresql.util.PSQLException:
     ERROR: column a0.collection does not exist

If I use: (with &quot;)

      <field-descriptor
         name="collectionOwner"
         column="&quot;collection-owner&quot;"
         jdbc-type="VARCHAR"
         primarykey="true"/>

I get:

org.apache.ojb.broker.PersistenceBrokerException:
    Error reading class type: ar.com.hdeoro.eua.model.JabberRosterItem
    from result set, current read field was collectionOwner
(...)
Caused by: org.postgresql.util.PSQLException: The column name 
"collection-owner" not found.
	at 
org.postgresql.jdbc1.AbstractJdbc1ResultSet.findColumn(AbstractJdbc1ResultSet.java:677)
	at 
org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet.java:479)
	at 
org.apache.ojb.broker.util.JdbcTypesHelper$T_Varchar.readValueFromResultSet(JdbcTypesHelper.java:378)
	at 
org.apache.ojb.broker.util.JdbcTypesHelper$BaseType.getObjectFromColumn(JdbcTypesHelper.java:302)
	at 
org.apache.ojb.broker.util.JdbcTypesHelper$BaseType.getObjectFromColumn(JdbcTypesHelper.java:281)
	at 
org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.readValuesFrom(RowReaderDefaultImpl.java:201)
	... 12 more


This time, the SELECT was ok, but OJB fail to get the values for that 
field... findColumn() should be called without the double quotes arround 
the column name...

So, what to do with this? Is anyone working with ojb and column names 
with '-' in its names?

Thanks in advance!

Horacio




> Horacio de Oro schrieb:
> 
>> Hi!
>>
>> I'm having a problem with OJB with a table of Jabber. The table name 
>> is roster-items and is on a PostgreSQL server.
>>
>> When I try to store() an object (using the PB api) I get this log:
>>
>> [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl]
>>   DEBUG: SQL:INSERT INTO roster-items
>>     (collection-owner,jid,ask,from,name,object-sequence,to)
>>     VALUES (?,?,?,?,?,?,?)
>>
>> and this exception:
>>
>> org.apache.ojb.broker.PersistenceBrokerSQLException:
>>    SQL failure while insert object data for class
>>    JabberRosterItem (...)
>>    exception message is [ERROR: syntax error at or near "-"]
>>
>> I think Ojb has troubles with the table name. If I execute this on psql:
>>
>> SELECT * FROM roster-items;
>>
>> I get this error:
>>
>> jabberd2=# SELECT * FROM roster-items;
>> ERROR:  syntax error at or near "-" at character 21
>>
>> The valid SQL for viewing the roster-items table is:
>>
>> SELECT * FROM "roster-items";
>>
>> The same happen with ANY table containing the '-' character, and this 
>> is fixed if you put the table name between double quotes...
>>
>> Is there any way to make Ojb put the table name between double quotes?
>>
>> Thanks in advance!
>>
>> Horacio
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Bad sql generated if table name contains "-" ???

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi horacio,

you'll have to quote the tablename in the repository. ojb currently does not 
support automatic quoting.

hth
jakob

Horacio de Oro schrieb:

> Hi!
> 
> I'm having a problem with OJB with a table of Jabber. The table name is 
> roster-items and is on a PostgreSQL server.
> 
> When I try to store() an object (using the PB api) I get this log:
> 
> [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl]
>   DEBUG: SQL:INSERT INTO roster-items
>     (collection-owner,jid,ask,from,name,object-sequence,to)
>     VALUES (?,?,?,?,?,?,?)
> 
> and this exception:
> 
> org.apache.ojb.broker.PersistenceBrokerSQLException:
>    SQL failure while insert object data for class
>    JabberRosterItem (...)
>    exception message is [ERROR: syntax error at or near "-"]
> 
> I think Ojb has troubles with the table name. If I execute this on psql:
> 
> SELECT * FROM roster-items;
> 
> I get this error:
> 
> jabberd2=# SELECT * FROM roster-items;
> ERROR:  syntax error at or near "-" at character 21
> 
> The valid SQL for viewing the roster-items table is:
> 
> SELECT * FROM "roster-items";
> 
> The same happen with ANY table containing the '-' character, and this is 
> fixed if you put the table name between double quotes...
> 
> Is there any way to make Ojb put the table name between double quotes?
> 
> Thanks in advance!
> 
> Horacio
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org