I have created a table in postgres using the StaticSentence below. The table reads is created from another table products, and the data within is deleted because I just want the schema(I'm really new at this thing but I'm sure there's a better way to handle this).
public void syncProductsBefore() throws BasicException {
new StaticSentence(s,"CREATE TABLE PRODUCTS_imports(ID) WITH OIDS AS SELECT * FROM PRODUCTS ").exec();
new StaticSentence(s, "DELETE FROM PRODUCTS_imports").exec();
}
then I try to write into this table using a PreparedSentence in the method below. An update command is run first to know whether to insert new data or update existing ones.
public void syncProduct(final ProductInfoExt prod) throws BasicException {
Transaction t = new Transaction(s) {
public Object transact() throws BasicException {
/*Sync the Product in a transaction*/
/* Try to update*/
if (new PreparedSentence(
s,
"UPDATE PRODUCTS SET REFERENCE = ?, CODE = ?, NAME = ?, PRICEBUY = ?, PRICESELL = ?, CATEGORY = ?, TAXCAT = ?, IMAGE = ? WHERE ID = ?",
SerializerWriteParams.INSTANCE).exec(new DataParams() {
public void writeValues() throws BasicException {
setString(1, prod.getReference());
setString(2, prod.getCode());
setString(3, prod.getName());
// setBoolean(x, p.isCom());
// setBoolean(x, p.isScale());
setDouble(4, prod.getPriceBuy());
setDouble(5, prod.getPriceSell());
setString(6, prod.getCategoryID());
setString(7, prod.getTaxCategoryID());
setBytes(8, ImageUtils.writeImage(prod.getImage()));
// setDouble(x, 0.0);
// setDouble(x, 0.0);
setString(9, prod.getID());
}
}) == 0) {
/* leyonce */
/**
* If not updated, try to insert insert into the import
* temporary table create temporary sorted copies of product
* catalog and products
*/
new PreparedSentence(
s,
"INSERT INTO PRODUCTS_imports(ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, CATEGORY, TAXCAT, IMAGE, STOCKCOST, STOCKVOLUME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
SerializerWriteParams.INSTANCE)
.exec(new DataParams() {
public void writeValues() throws BasicException{
/*leyonce --insert values into temporary import table*/
setString(1, prod.getID());
setString(2, prod.getReference());
setString(3, prod.getCode());
setString(4, prod.getName());
setBoolean(5, prod.isCom());
setBoolean(6, prod.isScale());
setDouble(7, prod.getPriceBuy());
setDouble(8, prod.getPriceSell());
setString(9, prod.getCategoryID());
setString(10, prod.getTaxCategoryID());
setBytes(11, ImageUtils.writeImage(prod
.getImage()));
setDouble(12, 0.0);
setDouble(13, 0.0);
);
}
Now the update runs perfectly but when the compiler gets to the insert statement, it rolls back and returns an error.
org.postgresql.util.PSQLException:
ERROR: column "id" does not exist
Position: 84
I really don't understand why.
psql
\d PRODUCTS_imports
\d PRODUCTS
do they have the ID column?
If the original table (products) is missing the ID column that would explain the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With