PDA

View Full Version : Insert into array column



wirasto
6th November 2009, 18:20
I have a column with type integer array (postgresql). But I don't know how to insert data with bindValue. I tried QVariantList, but failed.




QVariantList nomor;
nomor << 1 << 2 << 3 << 4;

sql.bindValue(":intarraycolumn", nomor);


Need your help

lyuts
8th November 2009, 08:53
You need to construct a string that will look like this one:
{ youInt1, yourInt2, ..., your intN } and bound it.

Goldmmbr
9th November 2009, 15:55
you can try something like:




QString nomor;
nomor.append("(");
for (int i=0; i < n; i++)
{
nomor.append(QString::number(i));
if (i != n-1)
{
nomor.append(", ");
}
}
nomor.append(")");

sql.bindValue(":intarraycolumn", nomor);

lyuts
9th November 2009, 16:07
PostgreSQL's doc says it should be "{...}", not "(...)".