473,767 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS SQL + Perl = Phantom rows

3 New Member
Hi, I just posted this in the MS SQL Section, but maybe my problem is rooted in Perl, so it's more appropriate to post here instead (sorry for the double post)


I'm writing a PERL script to access and insert rows into a Microsoft SQL. i'm using MS SQL Server Management Studio Express (2005) to architect tables and queries.

I've inserted two records into my "Pools" table
One from MS SQL Manager as a test, and another from my PERL script.

The one inserted by MS SQL Manager shows up everytime. The row from my PERL script doesn't show up on MS SQL Manager and ONLY shows up on my PERL script and ONLY if the INSERT query isn't commented out.

For me, this is the second day of troubleshooting . Does anybody have any insight?

Expand|Select|Wrap|Line Numbers
  1. $dbHandle = S_dbConnect($hostname, $database, $username, $password, $port);
  2.  
  3. $query = qq{INSERT INTO Pools (site_ID, pool_name, last_job_ID)
  4.     VALUES(1, 'CSE_IAL_intnb6', 0)};
  5. print "$query\n";
  6.  
  7. $dbHandle->do($query);
  8.  
  9. $query = qq{SELECT * FROM Pools};
  10. print "$query\n";
  11.  
  12. $m_sth = S_dbExecute($dbHandle, $query);
  13.  
  14. while(my $row = $m_sth->fetchrow_hashref()) {
  15.     print "$row->{pool_ID}\t$row->{site_ID}\t$row->{pool_name}\t$row->{last_job_ID}\n";
  16. }
  17. print "END\n";
  18.  
  19. ######################################################################
  20. # Subroutine: S_dbConnect
  21. # Function:
  22. #       Creates a database connection to the database specified by the global
  23. #       variables in the database initialization section at the top of this
  24. #       file.
  25. # Variables:
  26. #       $g_serverName contains the name of the database server.
  27. #       $g_dbName contains the name of the database on the server.
  28. #       $g_interfacesFile contains the path to the interfaces file which is
  29. #               required by Perl::DBI.
  30. #       $g_dbUsername contains the username which will be used to access the DB.
  31. #       $g_dbPassword contains the password used to authenticate with the DB.
  32. # Returns:
  33. #       $H_DB is the database handle established by the database connection
  34. #
  35. ######################################################################
  36.  
  37. sub S_dbConnect{
  38.         my ($server,$db,$user,$password,$port) = @_;
  39.         print "Trying to connect to Database...   " if ($debug) ;
  40.         $H_DB = DBI->connect("dbi:Sybase;server=$server:$port;database=$db",$user,$password, 'Sybase' )
  41.         || die "DBI: Unable to connect to the database - $DBI::errstr\n";
  42.         $H_DB->{'RaiseError'} = 1;
  43.         print "Connected to the Database\n" if ($debug) ;
  44.         return $H_DB;
  45. }
  46.  
  47. ######################################################################
  48. # Subroutine: S_dbExecute
  49. # Function:
  50. #       Executes a SQL query on an already established database connection.
  51. # Variables:
  52. #       $m_sql contains the SQL query to be executed on the database.
  53. #       $H_DB is the database handle the sql query is to be executed on.
  54. # Returns:
  55. #       $m_sth is the handle for the data returned by the database.
  56. #
  57. ######################################################################
  58.  
  59. sub S_dbExecute{
  60.         my ($H_DB, $m_sql) = @_;
  61.         my $m_sth = $H_DB->prepare($m_sql);
  62.         # if prepare fails, sth is undefined
  63.         if (!defined $m_sth){
  64.                 print "Error preparing sql record: " . $H_DB->errstr .my @ret_val = (1,$m_sth);
  65.                 return @ret_val; "\n";
  66.         }
  67.  
  68. # sth returns true if it succeeds
  69.         if ($m_sth->execute()){
  70.                 return $m_sth;
  71.         }
  72. # sth returns false if it fails
  73.         else{
  74.                 die "Error quering Database\n";
  75.         }
  76. }
The two functions above are not mine, they are borrowed

Here are the results:
Expand|Select|Wrap|Line Numbers
  1. filc0201> ./test_db2.pl
  2. Trying to connect to Database...   Connected to the Database
  3. INSERT INTO Pools (site_ID, pool_name, last_job_ID)
  4.         VALUES(1, 'CSE_IAL_intnb6', 0)
  5. SELECT * FROM Pools
  6. 22      1       test    0
  7. 30      1       CSE_IAL_intnb6  0
  8. END
Here is my server's info:
Expand|Select|Wrap|Line Numbers
  1. filc0201> uname -a
  2. Linux filc0201 2.6.5-7.276.PTF.196309.1-smp #1 SMP Mon Jul 24 10:45:31 UTC 2006 x86_64 x86_64 x86_64 GNU/Linux
  3. filc0201> cat /etc/issue
  4.  
  5. Welcome to SUSE LINUX Enterprise Server 9 (x86_64) - Kernel \r (\l).
Jul 1 '08 #1
1 2279
Rebles
3 New Member
Ah, nevermind,
I needed to add a
$dbHandle->commit(); for the changes to take effect.

Also, Does anybody know if there is a way to retrieve the auto incremented ID in the same SQL statement? It would help cut down the over head in my script.
Jul 1 '08 #2

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

Similar topics

2
4443
by: ben moretti | last post by:
hi i'm learning python, and one area i'd use it for is data management in scientific computing. in the case i've tried i want to reformat a data file from a normalised list to a matrix with some sorted columns. to do this at the moment i am using perl, which is very easy to do, and i want to see if python is as easy. so, the data i am using is some epiphyte population abundance data for particular sites, and it looks like this:
5
2623
by: Andrew | last post by:
Hi All, Have come across something weird and am after some help. Say i run this query where rec_id is a column of table arlhrl, select * from arlhrl where rec_id >= 14260 This returns to me 2 records with rec_id's of 14260 and 14261
22
3722
by: Christopher Murtagh | last post by:
Greetings, I'm trying to write a pl/perl function that will return multiple rows. I've looked all over the web and only found vague references as to how to do this (some said it was possible, and some said it wasn't but it was for older versions of Postgres). Basically I would *love* to be able to do something like this: SELECT some_id
4
6475
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to define the servername / hostname in my Perl Progrem.. Here is the code:
9
1272
by: Dave | last post by:
Apologies if this has come up before, but I can't find it if it has. I am fairly new to .Net and am having problems with ghosts in the datagrid. Basically I have a find screen that accepts search criteria, then interrogates a database to find all matching records. These are put into a dataset, which has a dataview that is used as the datasource of my datagrid, which is read only. The idea is that the user selects which record they...
20
2216
by: Shawn Milo | last post by:
I'm new to Python and fairly experienced in Perl, although that experience is limited to the things I use daily. I wrote the same script in both Perl and Python, and the output is identical. The run speed is similar (very fast) and the line count is similar. Now that they're both working, I was looking at the code and wondering what Perl-specific and Python-specific improvements to the code would look like, as judged by others more...
2
1382
by: aktar | last post by:
Ok, I've been spending hours trying to catch this "phantom" bug but just cant locate it. This is the code <?php //this is an array containing the filed attribute $field = array(); $field = 'Description';
0
1393
by: Rebles | last post by:
I'm writing a PERL script to access and insert rows into a Microsoft SQL. i'm using MS SQL Server Management Studio Express (2005) to architect tables and queries. I've inserted two records into my "Pools" table One from MS SQL Manager as a test, and another from my PERL script. The one inserted by MS SQL Manager shows up everytime. The row from my PERL script doesn't show up on MS SQL Manager and ONLY shows up on my PERL script and...
10
6976
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration of section c. Not sure where went wrong as the web page displayed internal server error. Also, what is the error 543? and error 2114. Where to find the list of errors in websites as it is not the standard apache error. I could not find...
0
9571
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10013
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
8838
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
6655
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
5280
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
5424
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3930
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2807
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.