![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Output number of rows inserted, updated... | kushal_cog | UNIX for Dummies Questions & Answers | 0 | 01-30-2008 12:28 AM |
| awk help needed. | cskumar | Shell Programming and Scripting | 0 | 07-20-2006 04:24 AM |
| cd inserted event | massimo_ratti | High Level Programming | 9 | 02-10-2004 06:04 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
help needed with getting last inserted row id
Hi,
I am working on a script that inserts one row of data at the time to a table. Among the fields of that table is the “serial” which is the auto increment. I need to be able to retrieve last inserted row id to use it for another insert. To retrieve last row id right after I do successful insert I am doing following …. $sql1 = " \"SELECT MAX(serial) FROM transaction\""; $command = "echo $sql1 | tee -a h.sql &>/dev/null"; system($command); $comm = "dbaccess mydb h.sql "; system($comm) However I am getting error sh: syntax error at line 1: `|' unexpected Can some see any problems with the $command ( I assume that is where error is)? Or can it even be done this way. I guess my question is How does one SELECT a value from a table into a Unix variable? Thank you in advance Last edited by arushunter; 02-06-2007 at 01:12 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I'm not going to pretend be a Unix/SQL pro, my SQL experience is through Perl. So I'm just guessing here. Since it is finding the unexpected "|" immediately following your variable for the SELECT statement, it makes me wonder if the escaped quotation marks are being taken literally in your next statement. I mean, if you do the substitution manually, it reads like this:
$command = "echo "SELECT MAX(serial) FROM transaction" | tee -a h.sql &>/dev/null"; So does using the variable "sql1" make that statement realize that the inner set of quotation marks should not be interpreted literally in that statement? I don't know. But it seems worth a shot to try it in a different context, i.e. use unescaped single quotation marks in the first statement, such as $sql1 = " 'SELECT MAX(serial) FROM transaction'"; Like I said though, I'm just guessing! |
|
#3
|
|||
|
|||
|
Yes, the problem was the quotes. I figured out the syntax. Thank you for the reply
|
|||
| Google The UNIX and Linux Forums |