$sql = "declare \@usrid int, \@sysusrid int " .
"select \@sysusrid = suser_id\(\'$usrname\'\) " .
"select \@usrid = $IDVALUE from $ID " .
"where $IDNAME = \'USR_ID\' " .
"insert into APPUSR (APP_CD, USR_ID, USRNAME, USRFNAME, USRLNAM
+E, FNCGRP_CD, SYSUSR_ID) " .
"values (\'A\', \@usrid, \'$usrname\', \'$first\', \'$full_last
+\', $fncgrp, \@sysusrid)";
Please don't! This code is hard to read and dangerous!
First, this is Perl, not Visual Basic or some other language with restricted string literals. You can write this much more readably. And actually even if you kept using doublequotes you do not need to escape singlequotes. "d\'Artagnan" is equivalent to "d'Artagnan". You could write the code like this:
$sql = qq{
declare \@usrid int, \@sysusrid int
select \@sysusrid = suser_id('$usrname')
select \@usrid = $IDVALUE from $ID
where $IDNAME = 'USR_ID'
insert into APPUSR (APP_CD, USR_ID, USRNAME, USRFNAME, USRLNAME, FNC
+GRP_CD, SYSUSR_ID)
values ('A', \@usrid, '$usrname', '$first', '$full_last', $fncgrp, \
+@sysusrid)
};
Easier on the eyes, isn't it?
In either case it's dangerous! Guess what happens if someone claims his username is "d'Artagnan"? Or maybe "') delete from APPUSR; select length('gotcha" ?
USE placeholders!
my $sth = $$dbhCurrent->prepare( qq{
declare \@usrid int, \@sysusrid int
select \@sysusrid = suser_id(?)
select \@usrid = $IDVALUE from $ID
where $IDNAME = 'USR_ID'
insert into APPUSR (APP_CD, USR_ID, USRNAME, USRFNAME, USRLNAME, FNC
+GRP_CD, SYSUSR_ID) " .
values ('A', \@usrid, ?, ?, ?, ?, \@sysusrid)
};
$sth->execute( $usrname, $usrname, $first, $full_last, $fncgrp);
Your use of $IDVALUE and $ID looks suspicious too, but those two cannot be replaced by placeholders. I do hope they are comming from someplace safe!
| [reply] [d/l] [select] |
| [reply] |
That's strange. under normal circumstances placeholders are much more efficient, especially if you reuse the statement handle returned by $dbh->prepare() and run the query many times. Do you have any links to this problem?
In case you need to use $dbh->quote() it's possible to use Interpolation to make the syntax nicer:
use Interpolation "'" => sub {"'".$dbh->quote($_[0])};
#...
$sql = qq{
declare \@usrid int, \@sysusrid int
select \@sysusrid = suser_id($'{$usrname}')
select \@usrid = $IDVALUE from $ID
where $IDNAME = 'USR_ID'
insert into APPUSR (APP_CD, USR_ID, USRNAME,
USRFNAME, USRLNAME, FNCGRP_CD, SYSUSR_ID)
values ('A', \@usrid, $'{$usrname}',
$'{$first}', $'{$full_last}', $fncgrp, \@sysusrid)
};
| [reply] [d/l] |
| [reply] |
I'd look to what occurs before sub add_login{. Once perl finds a syntax error, all bets are off. So I would not take any notice of the "@_" error until you fix your syntax error.
| [reply] [d/l] [select] |
I can't count how many times I've been hit by this. The fact that line 227 is a closing curly bracket usually almost always indicates that you have problem with parentheses/bracket matching. Check before line 202 upward, since line 202 is fine.
One way I use to find the exact line of error is by consequetively putting die "OK" line between lines or blocks of code.
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
| [reply] [d/l] |
I fail to see how adding die statements would help find a *compile* error. BEGIN { die } might help, but for this type of problem, I usually remove entire chunks from the file until perl -c doesn't find the error. The last thing removed contains the error. Re-add smaller bits until the error comes back if the chunk was too big.
| [reply] [d/l] [select] |
You are right, ikegami. My second paragraph has nothing to do with the original problem. It's the technical I use for runtime error. Thanks for reminding me :-)
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
| [reply] |
I'd need to see a little bit more of the code, but it sounds like you have a typo in the lines preceding line 200. My first bet would be a missing/extra quote somewhere.
----
I Go Back to Sleep, Now.
OGB
| [reply] |
#!/usr/bin/perl
({
sub add_login{
my ($var) = @_;
#...
}
}
At least, this produces a rather similar error:
$ perl -c <629906.pl
syntax error at - line 5, near "sub add_login"
Can't use global @_ in "my" at - line 7, near "= @_"
- had compilation errors.
| [reply] [d/l] [select] |
As others have said, look at the code preceeding the error. Likely you are missing a comma, semicolon, or anything that comes in pairs such as quotes, braces, etc.. | [reply] |