help needed with getting last inserted row id


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help needed with getting last inserted row id
# 1  
Old 02-06-2007
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 04:12 PM..
# 2  
Old 02-07-2007
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  
Old 02-07-2007
Yes, the problem was the quotes. I figured out the syntax. Thank you for the reply
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Date from filename inserted into records

Hi Folks, I have below files in one directory: Spiross-MBP:AIRTEMP spirospap$ ls -1 CPK2004001 CPK2004002 CPK2004003 etc... JFK2003001 JFK2003002 JFK2003003 etc... TEB1999001 TEB1999002 TEB1999003 etc... Month/year is in Filename and also in the file Header, first line. (18 Replies)
Discussion started by: spirospap
18 Replies

2. Shell Programming and Scripting

How to add new line after every data inserted to file?

Hi all, I need help for solve my problem. my problem is like this.. i want to add many word to file. but after I add 1 word, the second word should be in the under of the first word. i have tried but the result is like this word1word2word3 i want the result to be like this word1 word2... (5 Replies)
Discussion started by: weslyarfan
5 Replies

3. Solaris

Copying existing OS to new inserted drives

Hi, I was wondering if there is an easy / recommended way to do the following: Copy existing OS to 2 NEW drives inserted to server. Netra 440 / Solaris 8 1. install the 2 new physical drives, 2. reconfigure the four drives to a RAID 1 array, and 3. copy the existing 2 drives... (4 Replies)
Discussion started by: kmac22068
4 Replies

4. Shell Programming and Scripting

Comparing two files to get only records to be inserted and updated

Hello all, Please help me for a script that compares two files and reads only those records that are to be inserted and updated. File1: c_id name place contact_no 1 abc xyz 34567 10 efg uvw 82725 6 hjk wth 01823 2 iuy ... (4 Replies)
Discussion started by: T@ni@
4 Replies

5. UNIX for Dummies Questions & Answers

Binary line being inserted while truncating a file

Hi All, I have a ln between two files (say ln a b), when i truncate file " b ", this truncates file " a " also, a binary line is being added as the first line of both the files. This is causing problems with other scripts which grep on the above files. (though i can work my way around... (4 Replies)
Discussion started by: akshay61286
4 Replies

6. Shell Programming and Scripting

how to run a script when pen drive is inserted

Hi, I need to run a script whenever a pen drive is connected to my ubuntu machine. The script is to be run from local disk and with privileges of current user. How do I achieve this? Thanks. (1 Reply)
Discussion started by: friendlyweb
1 Replies

7. UNIX for Dummies Questions & Answers

Output number of rows inserted, updated...

Hi all, I am new to Unix. I have written pl/sql script to be run in Unix. I have used Merge statement and subsequently would like to know the number of rows updated or inserted. Any suggestions in this regard would be great Thanks in advance Kushal (0 Replies)
Discussion started by: kushal_cog
0 Replies

8. Programming

cd inserted event

:confused: i am programming in c and i need to start a procedure automatically when a cd is inserted. Anyone knows how can i do it? thanx (9 Replies)
Discussion started by: massimo_ratti
9 Replies
Login or Register to Ask a Question