db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Hakim <dha...@webcodex.com>
Subject Re: No default values in my Object Model
Date Thu, 17 Apr 2003 19:40:25 GMT
What's curious about this is, if I generate an XML schema from my MySQL 
database using the jdbc ant target and then generate SQL scripts from 
that using the sql target, those SQL scripts don't work :) The problem 
is not just with the defaults. Passing in size for the MEDIUMTEXT 
fields (txtBody and txtSubject) is a big no-no as well.

Do these sorts of issues arise from the JDBC Driver being used ? Or 
perhaps the adaptor ? Or are they caused from within the Torque task 
code ?

Here is the generated XML from my small test database :

<?xml version="1.0"?>
<!DOCTYPE database SYSTEM 
"http://jakarta.apache.org/turbine/dtd/database.dtd">
<!-- Autogenerated by JDBCToXMLSchema! -->
<database>
     <table name="tblMessage">
         <column default="" name="idMessage" primaryKey="true"
             required="true" type="INTEGER"/>
         <column default="0" name="idParent" required="true" 
type="INTEGER"/>
         <column default="0" name="idThread" required="true" 
type="INTEGER"/>
         <column default="" name="txtAuthor" required="true" size="64" 
type="VARCHAR"/>
         <column default="" name="txtAuthorEmail" required="true"
             size="64" type="VARCHAR"/>
         <column default="" name="txtSubject" required="true"
             size="65535" type="LONGVARCHAR"/>
         <column default="" name="txtBody" required="true" size="65535" 
type="LONGVARCHAR"/>
         <column default="0000-00-00 00:00:00" name="datDatePosted"
             required="true" type="TIMESTAMP"/>
         <column default="0" name="intFlags" required="true" 
type="INTEGER"/>
     </table>
</database>

Which generated this SQL:

drop table if exists tblMessage;

CREATE TABLE tblMessage
(
         idMessage INTEGER default NOT NULL,
         idParent INTEGER default 0 NOT NULL,
         idThread INTEGER default 0 NOT NULL,
         txtAuthor VARCHAR (64) default '' NOT NULL,
         txtAuthorEmail VARCHAR (64) default '' NOT NULL,
         txtSubject MEDIUMTEXT (65535) default '' NOT NULL,
         txtBody MEDIUMTEXT (65535) default '' NOT NULL,
         datDatePosted TIMESTAMP default '0000-00-00 00:00:00' NOT NULL,
         intFlags INTEGER default 0 NOT NULL,
     PRIMARY KEY(idMessage)
);

-Dave

On Thursday, April 17, 2003, at 02:59  PM, David Hakim wrote:

>
> On Wednesday, April 16, 2003, at 03:05  PM, Jon King wrote:
>
>> This happens because the generated schema can specify defaults for 
>> integer
>> columns that are empty strings (i.e., default = "").  I'd like to be 
>> able to tell
>> the jdbc target to supress the generation of defaults but don't know 
>> how to do
>> this.  I end up stripping a lot of the default specification out of 
>> the xml with
>> a sed script.  If you eliminate the empty string defaults for integer 
>> columns,
>> the object model will build correctly.
>
> Interesting ... Under what circumstances does the jdbc target generate 
> 'default=""' for columns in the XML schema ?
>
> Is this a driver / database dependent behavior ? When running the jdbc 
> target against existing MSSQL databases I don't get any 'default' 
> attributes in the generated XML schema. When running the jdbc target 
> against MySQL databases I get defaults for every column!
>
> With MySQL, does 'default=""' only happen when columns are specified 
> to allow NULLs (and no other specific default is specified) ?
>
> To set the default for a column to actually be NULL do I just remove 
> the 'default' attribute ?
>
> -Dave
>
>> David Hakim wrote:
>>
>>>         Sorry if this a newbie question but I couldn't find anything 
>>> on it in
>>> the docs or mail archive. I used torque to generate an XML schema 
>>> file
>>> from an existing mysql database. I then generated the object model 
>>> for
>>> that database. The object model however will not compile because 
>>> there
>>> are syntax errors in the generated base classes:
>>>
>>>          /**
>>>           * The value for the print field
>>>           */
>>>          private int print = ;
>>>
>>>          /**
>>>           * The value for the condition field
>>>           */
>>>          private byte condition = ;
>>>
>>>         ...
>>>
>>> Any idea what would cause these errors in code generation ? I went
>>> through the same process with a SQLServer database the other day 
>>> (even
>>> though there were a couple hangups there in getting torque to 
>>> generate
>>> the XML from the existing mssql schema) however all the generated
>>> objects output and compiled correctly .
>>>
>>> Thoughts ?
>>> -Dave
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: torque-user-help@db.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: torque-user-help@db.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>


Mime
View raw message