You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Karl Stenerud <ka...@webartjapan.com> on 2003/04/02 10:29:45 UTC

Delete not working with empty criteria

I'm trying to delete all entries in a table, but when I run the program, 
nothing happens.


I built the delete statement the same way I did a select all statement:

    Criteria crit = new Criteria();
    AdminuserPeer.doDelete(crit);

After running this, the table still has old data in it.  Is there something 
else I should be doing?


Re: (postscript) Delete not working with empty criteria

Posted by Thijs Verhagen <th...@mac.com>.
I find it convenient while testing to empty out entire tables. It can 
be tedious to do this in sql, especially if there are dependencies.
Adding   PrimaryKey  > 0 to the criteria threw a 
com.workingdogs.village.DataSetException:
(You must specify KeyDef attributes for this TableDataSet in order to 
delete a Record.)
when I tried this on a table with idmethod=none

Eventually I settled for a call to executeStatement found in BasePeer:
...
CgroupmemberPeer.executeStatement( "delete from " + 
CgroupmemberPeer.TABLE_NAME );
PersonPeer.executeStatement( "delete from " + PersonPeer.TABLE_NAME );
...

BasePeer.executeStatement() is a direct escape to jdbc; it skips all 
the elegant o/r-mappings torque builds, so it should be avoided, but 
it's OK for testing purposes I suppose.


Hope this is helpful to someone.

gr.
Thijs

Karl Stenerud heeft op donderdag, 3 apr 2003 om 02:40 
(Europe/Amsterdam) het volgende geschreven:

> Thanks for the help.
>
> After thinking about it a bit more, I've decided that I don't have the 
> belly
> for keeping code around that deletes an entire table, even if it is 
> only for
> testing purposes =)
>
>
> 2003 4月 3 木曜日 00:47、Eric Emminger さんは書きました:
>> Karl
>>
>>> I'm trying to delete all entries in a table, but when I run the 
>>> program,
>>> nothing happens.
>>>
>>>
>>> I built the delete statement the same way I did a select all 
>>> statement:
>>>
>>>     Criteria crit = new Criteria();
>>>     AdminuserPeer.doDelete(crit);
>>>
>>> After running this, the table still has old data in it.  Is there
>>> something else I should be doing?
>>
>> I'm guessing this is a safeguard against accidentally deleting 
>> everything.
>>
>> Try adding something to your Criteria, such as
>>
>> crit.add(YourPeer.YOUR_PRIMARYKEY, 0, Criteria.GREATER_THAN);
>>
>> Eric
>>
>>
>> ---------------------------------------------------------------------
>> 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
>

Re: Delete not working with empty criteria

Posted by Karl Stenerud <ka...@webartjapan.com>.
Thanks for the help.

After thinking about it a bit more, I've decided that I don't have the belly 
for keeping code around that deletes an entire table, even if it is only for 
testing purposes =)


2003 4月 3 木曜日 00:47、Eric Emminger さんは書きました:
> Karl
>
> > I'm trying to delete all entries in a table, but when I run the program,
> > nothing happens.
> >
> >
> > I built the delete statement the same way I did a select all statement:
> >
> >     Criteria crit = new Criteria();
> >     AdminuserPeer.doDelete(crit);
> >
> > After running this, the table still has old data in it.  Is there
> > something else I should be doing?
>
> I'm guessing this is a safeguard against accidentally deleting everything.
>
> Try adding something to your Criteria, such as
>
> crit.add(YourPeer.YOUR_PRIMARYKEY, 0, Criteria.GREATER_THAN);
>
> Eric
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org


Torque ignoring unique constraint?

Posted by Karl Stenerud <ka...@webartjapan.com>.
Torque seems to be ignoring the <unique> elements in my schema.

I built the following table in the schema:

   <table name="adminUser" description="Administrators">
        <column
          name="id"
          required="true"
          primaryKey="true"
          type="INTEGER"
          description="Administrator Id"/>
        <column
          name="username"
          required="true"
          type="VARCHAR"
          size="16"
          description="Username"/>
        <column
          name="password"
          required="true"
          type="VARCHAR"
          size="8"
          description="Password"/>
        <unique>
            <unique-column name="id"/>
            <unique-column name="username"/>
        </unique>
    </table>



But when I check mysql to see what it produced, I get the following:

# mysqldump --no-data tokoname;
-- MySQL dump 8.22
--
-- Host: localhost    Database: testdbase
---------------------------------------------------------
-- Server version       3.23.52-log

--
-- Table structure for table 'ID_TABLE'
--

CREATE TABLE ID_TABLE (
  ID_TABLE_ID int(11) NOT NULL default '0',
  TABLE_NAME varchar(255) NOT NULL default '',
  NEXT_ID int(11) default NULL,
  QUANTITY int(11) default NULL,
  PRIMARY KEY  (ID_TABLE_ID),
  UNIQUE KEY TABLE_NAME (TABLE_NAME)
) TYPE=MyISAM;

--
-- Table structure for table 'adminUser'
--

CREATE TABLE adminUser (
  id int(11) NOT NULL default '0',
  username varchar(16) NOT NULL default '',
  password varchar(8) NOT NULL default '',
  PRIMARY KEY  (id)
) TYPE=MyISAM;


I'm also able to add multiple users with the same username in my application.


Re: Delete not working with empty criteria

Posted by Eric Emminger <er...@ericemminger.com>.
Karl

> I'm trying to delete all entries in a table, but when I run the program, 
> nothing happens.
> 
> 
> I built the delete statement the same way I did a select all statement:
> 
>     Criteria crit = new Criteria();
>     AdminuserPeer.doDelete(crit);
> 
> After running this, the table still has old data in it.  Is there something 
> else I should be doing?

I'm guessing this is a safeguard against accidentally deleting everything.

Try adding something to your Criteria, such as

crit.add(YourPeer.YOUR_PRIMARYKEY, 0, Criteria.GREATER_THAN);

Eric