473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to insert a single quote inside a perl scalar

hi,
I need to send some values to a subroutine where i use insert query.
suppose say my scalar is as follows:

my ($name,$number,$address) etc and i get the values into those scalars dynamically by some other process. When i send these values to the subroutine containing an insert query, there for the columns containing
varchar i need to have ' some value' for int no quotes are requried. For
example if we take $name, the Name column in the database is varchar.
So value inside $name need to have ' ' (A single quote). For number it is not the case . If i do assign the values as $name="'Pavan'"(here i am including single quotes inside double quotes). But when the data comes from some other source , it comes as $name="pavan" and when i pass this value to a subroutine,
to the query , the query becomes something like
insert into employee (Empno,Ename,Address) values (1,pavan,add);
It need to be (1,'pavan','add'); So, please tell me how to insert single quotes.

Thanks & Regards,
Pavan
Sep 12 '08 #1
4 3939
aurekha
34
if your scalar i.e $name = 'pavan';

Inorder to insert into database, escape the singlequotes.

i.e $name = "\'pavan\'"

then you end with singlequotes as 'pavan'
Sep 12 '08 #2
eWish
971 Expert 512MB
Try this on your SQL statement. This should eliminate the need for the quotes.

Expand|Select|Wrap|Line Numbers
  1. my $insert = $dbh->prepare(qq{INSERT INTO table_names($col1, $col2) VALUES(?,?)});
  2.    $insert->execute($value1, $value2);
  3.    $insert->finish();
--Kevin
Sep 12 '08 #3
Dear friends,
I am sorry to tell you that you did not catch me properly.
Actually i have $name=pavan. So since it is set as varchar in the database, the insert module i have written need to have single quotes as
insert into $tablename ($colnames) values ($values);
and $colnames contains string as (Name,Desig,....)
and $values contains ($name,$desig)... etc
Now, if Name column in the database is set as int, there would not have been any problem. But since $name is set as varchar, we need to have the value as
'pavan' . But since i have got pavan,it is copied as pavan in $name and hence the error. I have worked on that and got this solution.
my $name1 = "'$name'" (single quotes within double quotes).
Any other solution is highly appreciated.

Thanks & Regards,
Pavan kumar
Sep 12 '08 #4
wish,
I got u. I am sorry to send u a post, without understanding ur theorey.
I will definitly try that.

Thanks ,
Pavan
Sep 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © import sys © © nn = len(sys.argv) © © if not nn==5: © print "error: %s search_text replace_text in_file out_file" % sys.argv
5
by: John Smith | last post by:
Can someone point me to an example of how to implement and access the kind of object shown below? Most of the examples if found are an object that contains one other object. I need to create an...
2
by: HomerCritic | last post by:
I'm aware of the recent mysqldump change, in that it now by default enables some optimizations. One of those optimizations is to use single insert statements, instead of separate insert...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
5
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
6
by: Frederik Vanderhaeghe | last post by:
Yo, I have a problem inserting into my database. When i try the following: "INSERT INTO TBL_Bestanden_Zoeken (Id,docnr,klnr,klnaam,datum,bedrag,type) VALUES...
6
by: Allan Stirrett | last post by:
Hi, I've got a section of code that basically goes like so: int l_Index = 0; std::set<intl_Set; while(l_Index < 10) { l_Set.insert(l_Index++); }
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.