473,406 Members | 2,847 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,406 software developers and data experts.

mSQL + Perl = Phantom rows

3
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
0 1381

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

Similar topics

2
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...
5
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...
4
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...
9
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...
0
by: anthony | last post by:
Hi. I am attempting to get msql3 installed with php. Using php version php5.1-200604070430 and msql-3.7. I am getting the following error on compile. ...
20
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...
2
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(); ...
1
by: Rebles | last post by:
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...
10
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...
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: 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,...
0
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...
0
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...
0
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,...

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.