From: | "Jeff" <jklcom(at)mindspring(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | How to insert/update multiple records in web envirnoment |
Date: | 2001-04-03 13:14:10 |
Message-ID: | 9acit8$6qf$1@news.tht.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
When there's only one recorde to Insert/updat, the server cgi works fine.
When try to insert/update multiple records the cgi keeps running and never
ends.
Here's the code snippet:
while(ip)
{
strcpy(buffer, ip->Item);
ip = ip->next;
while(strstr(buffer, "``")) replace_str(buffer, "``", "` `");
sscanf(buffer,
"%[^`]`%[^`]`%[^`]`%[^`]`%[^`]`%[^`]`%[^`]`%[^`]`%[^`]`%[^`]`%[^`]`%[^`]`%[^
`]`%[^`]`%[^`]`s",
op.key, op.last, op.first, op.jobcode, op.address,
op.city, op.state, op.zip,
op.phone, op.id, op.password, op.notes, op.status,
op.permissions, op.wages);
sprintf(query_string, "SELECT * FROM employees WHERE key = '%s'",
op.key);
PQclear(res);
res = PQexec(conn, query_string);
if (PQresultStatus(res) != PGRES_TUPLES_OK) /* did the query
fail? */
{
postMessage("SELECT query failed", 0);
PQclear(res);
PQfinish(conn);
exit(1);
}
if(PQntuples(res) == 0)
{
sprintf(query_string, "INSERT INTO employees "
"(startdate, last, first, jobcode, address,
city, state, zip, "
"phone, id, password, notes, status,
permissions, wages) "
"VALUES ('%s', '%s', '%s', '%s', '%s',
'%s',"
"'%s', '%s', '%s', '%s', '%s',"
"'%s', '%s', '%s', '%s')",
today, op.last, op.first, op.jobcode, op.address,
op.city, op.state, op.zip,
op.phone, op.id, op.password, op.notes, op.status,
op.permissions, op.wages);
PQclear(res);
res = PQexec(conn, query_string);
}
else {
sprintf(query_string, "UPDATE employees SET lastmodified = '%s',"
"last = '%s',"
"first = '%s',"
"jobcode = '%s',"
"address = '%s',"
"city = '%s',"
"state = '%s',"
"zip = '%s',"
"phone = '%s',"
"id = '%s',"
"password = '%s',"
"notes = '%s',"
"status = '%s',"
"permissions = '%s',"
"wages = '%s'"
"WHERE key = '%s'",
today, op.last, op.first, op.jobcode, op.address,
op.city, op.state, op.zip,
op.phone, op.id, op.password, op.notes, op.status,
op.permissions, op.wages, op.key);
PQclear(res);
res = PQexec(conn, query_string);
ip = ip->next;
}
}
PQclear(res);
PQfinish(conn);
}
From | Date | Subject | |
---|---|---|---|
Next Message | Livio Righetti | 2001-04-03 13:30:12 | speed on Postgresql compared to Mysql |
Previous Message | The Hermit Hacker | 2001-04-03 13:09:13 | Re: News gateway down? |