473,671 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to insert a single quote inside a perl scalar

51 New Member
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,Ad dress) 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 3956
aurekha
34 New Member
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 Recognized Expert Contributor
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
pavanponnapalli
51 New Member
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
pavanponnapalli
51 New Member
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
1842
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
5764
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 object that contains a hash of sub-objects each sub-object is made up of a number of different objects and an array of an object type. Object1 contains scalars
2
12045
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 statements, each on their own lines. I'm also aware of the --skip-opt / -e / --skip-extended-insert But what I'd like is a combination of having a single insert statement, but with each record in its own line, like so: INSERT INTO `article` (`id`,...
8
6285
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 one-to-one relationship but on this occasion I must keep username/password details within a seperate table. Here's the basic specs and database schema: -------------------------------------------
5
3223
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: someArray = 6; I know I can't get the same syntactic sugar as Perl offers, with the usage of a string as the array key surrounded by square brackets. I just want the general functionality, that's all. That is, a data container that will maintain...
6
1491
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 ('12345678-1234-1234-1234-123456789123','VF-1234567','12345','Frederik','15-01-2006','125','VF')" it works. But I get my values from a method: Public Sub DB_Wegschrijven(ByVal Id As String, ByVal KlantNummer As String,
6
1440
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
7036
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 find syntax to insert values into a mysql database table. I'm able to use the below syntax to insert hard-coded values like 'josie' and 'smith' but can't find working syntax to insert $scalar data from another file (which is really what perl-mysql is...
1
47447
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8402
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8676
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.