Solved

MS SQL in Perl ?

Posted on 2001-06-13
3
214 Views
Last Modified: 2011-09-20
Here is my "select" part :

#!C:\perl\bin\perl

use DBI;
$dbHandle = (DBI->connect('DBI:ADO:DSN', 'sa', ''));
$sql = "SELECT * FROM Test";
$statementHandle = $dbHandle->prepare($sql);
$statementHandle->execute() || die $statementHandle->errstr;

while (($cat1) = $statementHandle->fetchrow_array )
{
     print $cat1."\n";
 }

Above script works fine.  I just wonder how can I insert some value into the table ?
May I have some example script for insert ?
0
Comment
Question by:johnmemor
  • 2
3 Comments
 

Author Comment

by:johnmemor
ID: 6189394
Here is my "insert" part :

#!C:\perl\bin\perl

 use DBI;
 $dbHandle = (DBI->connect('DBI:ADO:DSN', 'sa', ''));
 $sql = "insert into Test (name) values(\"some_value\")";
 $statementHandle = $dbHandle->prepare($sql);
 $statementHandle->execute() || die $statementHandle->errstr;


I got error after execution.
0
 
LVL 10

Accepted Solution

by:
makerp earned 10 total points
ID: 6190339
$sql = "INSERT INTO table (colname) VALUES (".$some_val.")"

where $some_val is a number, if its a string then wrap it in single quotes like this

$sql = "INSERT INTO table (colname) VALUES ('".$some_val."')"

hope this helps
0
 

Author Comment

by:johnmemor
ID: 6190589
How can I get the row count ?

This is what I have :

$rowCount = $dbh->do($sql);
print $rowCount."\n";


and I got -1, I have more than 1 record in the table.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Extract multiple value with delimiters from a string 4 170
Perl - Mawk 2 96
Perl script not writing to .csv file 6 109
Formatting stings with pack and printf in perl 5 72
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question