The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-06-2007
Registered User
 

Join Date: Dec 2006
Posts: 31
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.
Reply With Quote
Forum Sponsor
  #2  
Old 02-07-2007
Registered User
 

Join Date: Feb 2007
Posts: 6
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!
Reply With Quote
  #3  
Old 02-07-2007
Registered User
 

Join Date: Dec 2006
Posts: 31
Yes, the problem was the quotes. I figured out the syntax. Thank you for the reply
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0