incubator-empire-db-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Döbele <doeb...@esteam.de>
Subject re: Copy and Insert DBRecord (Urgent for me)
Date Fri, 15 Jan 2010 19:42:13 GMT

I know it is tempting to use initRecord() but it has not been designed for doing what you
want to do.
Rather it should be used for modifying existing records.

IMO the right approach is to create a new record and copy all but pk and timestamp columns.
In fact this is similar to what initRecord() does internally.

So basically the layout could be as follows: 

    reader.open(cmd, conn);
    DBIndex pk = table.getPrimaryKey();
    DBColumn ts = table.getTimestampColumn();
    DBRecord rec = new DBRecord();
    while (reader.moveNext())
    {
        rec.create(table);
        for (DBColumn c : table.getColumns())
        {   // ignore PK and timestamp columns
            if (pk.contains(c) || c==ts)
                continue; 
            // copy other fields
            rec.setValue(c, reader.getValue(c));
        }
        rec.update(conn);
    }

Regards
Rainer

McKinley wrote:
> re: Copy and Insert DBRecord (Urgent for me)
> 
> I'd like to get a DBRecord and use it as a template for an insert. Is
> that possible?
> 
> if(reader.getRecordData(cmd, conn)){
>     tableA.initRecord(recA, reader);
>     // I would like to create a new record where only KeyColumn1 and
> Name
>     // are different than the old one.
>     // can't do the following, key is read only;
>     //recA.setKeyColumn1(null);
>     recA.setName("Some New Name for a New Record");
>     recA.create(tableA, conn); // <-- still points to old primary key.
> }
> 
> OK, thanks if you can help!
> 
> Cheers,
> 
> McKinley

Mime
View raw message