dbi

How do I get Ruby's DBI gem properly installed so that it can talk to MySql?

三世轮回 提交于 2019-12-25 02:22:22
问题 On my Windows 7 box, I've installed Ruby 1.9.2, and installed the following gems: * LOCAL GEMS * dbd-mysql (0.4.4) dbi (0.4.5) deprecated (2.0.1) httparty (0.8.1) rubygems-update (1.8.15) (I did this using gem install). I have also written the following simple test harness: require 'rubygems' require 'dbi' begin dbh = DBI.connect("DBI:Mysql:test", "username", "pwd") row = dbh.select_one("SELECT VERSION()") puts "Server Version: "+row[0] rescue DBI::DatabaseError => e puts "An error occurred"

Why do I get “ORA-00932: inconsistent datatypes: expected - got -” when using COLLECT() in a prepared statement?

百般思念 提交于 2019-12-24 16:57:18
问题 I am using this query with the Perl DBI: SELECT c.change_id , COLLECT(t.tag) AS the_tags FROM changes c LEFT JOIN tags t ON c.change_id = t.change_id WHERE c.project = ? GROUP BY c.change_id The DBI uses OCI to prepare this statement, bind the value I pass, and get the results. But Oracle, for some reason, does not like it. The error output is: ORA-00932: inconsistent datatypes: expected - got - (DBD ERROR: error possibly near <*> indicator at char 41 in ' SELECT c.change_id , <*>COLLECT(t

Perl dbi prepare is putting wrong quote

旧巷老猫 提交于 2019-12-24 12:26:05
问题 My code is similar to the below: $sth = $dbh->prepare("CREATE TABLE IF NOT EXISTS ? (`id` bigint(100) unsigned NOT NULL AUTO_INCREMENT"); $sth->execute('test'); I end up with the error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''test' From the trace I found perl DBI put single quote around the table name, which mysql doesnt like. How to tell DBI not to put any quote or to put (`)

same query, two different ways, vastly different performance

谁说胖子不能爱 提交于 2019-12-24 08:19:03
问题 I have a Postgres table with more than 8 million rows. Given the following two ways of doing the same query via DBD::Pg , I get wildly different results. $q .= '%'; ## query 1 my $sql = qq{ SELECT a, b, c FROM t WHERE Lower( a ) LIKE '$q' }; my $sth1 = $dbh->prepare($sql); $sth1->execute(); ## query 2 my $sth2 = $dbh->prepare(qq{ SELECT a, b, c FROM t WHERE Lower( a ) LIKE ? }); $sth2->execute($q); query 2 is at least an order of magnitude slower than query 1... seems like it is not using the

Perl Dbi and stored procedures

冷暖自知 提交于 2019-12-24 02:09:39
问题 How can i retrive the return value of stored procedure by using perl and the dbi against sql server ? could someone provide example. 回答1: There are examples in DBD::ODBC t/ dir (see 20SqlServer.t). Basically you do (not a full working example): my $output; my $input = 'fred'; my $sth = $dbh->prepare(q/{ ? = call myproc(?) }/); $sth->bind_param_inout(1, \$output, 100); $sth->bind_param(2, $input); $sth->execute Now $output should contain whatever your procedure returned. Make sure you set then

how to build sql server 2008 datetime object and insert it using perl DBI

房东的猫 提交于 2019-12-24 00:39:45
问题 How can i build a sql server 2008 datetime object with perl and insert it using the dbi module to specific table could someone provide example 回答1: If using ODBC: my $sth = $dbh->do(q/insert into mytable (mydatetimecol) values(?)/; $sth->execute(q/{ts 'yyyy-mm-dd hh:mm:ss'}/); The datetime can also have '.mmm' on the end for milliseconds. If not using ODBC it will depend on what DBD you are using. 来源: https://stackoverflow.com/questions/3044445/how-to-build-sql-server-2008-datetime-object-and

problems in using DBI

懵懂的女人 提交于 2019-12-23 01:52:59
问题 I'm new to all this this stuff. I'm trying to execute the following code use DBI; my $dsn = 'DBI:mysql:db:localhost'; my $db_user_name = 'root'; my $db_password = '*******'; my $dbh = DBI->connect($dsn, $db_user_name, $db_password); my $sth = $dbh->prepare("select id from table where field = 'value'"); $sth->execute(); ($id) = $sth->fetchrow_array(); print "id is $id"; $sth->finish(); print outputs nothing. Can you tell me what am I doing wrong? Thank you in advance! 回答1: You said in one of

MySQL connection not working from within Perl CGI script

好久不见. 提交于 2019-12-22 20:47:31
问题 I can easily connect to a remote MySQL server using the DBI module in my Perl scripts. However, when I try to use the same connection settings/properties from within a CGI script, the connection fails. There are no helpful errors/warnings being logged either in the apache error log, or the browser, in spite of using use CGI::Carp qw(warningsToBrowser fatalsToBrowser); Strangely, the exact same script works fine when executed from the terminal. I also tried connecting the CGI script to the

how to query sqlite for certain rows, i.e. dividing it into pages (perl DBI)

∥☆過路亽.° 提交于 2019-12-22 06:47:55
问题 sorry for my noob question, I'm currently writing a perl web application with sqlite database behind it. I would like to be able to show in my app query results which might get thousands of rows - these should be split in pages - routing should be like /webapp/N - where N is the page number. what is the correct way to query the sqlite db using DBI, in order to fetch only the relavent rows. for instance, if I show 25 rows per page so I want to query the db for 1-25 rows in the first page, 26

Perl DBI - Capturing errors

只谈情不闲聊 提交于 2019-12-21 09:29:09
问题 What's the best way of capturing any DBI errors in Perl? For example if an insert fails because there were illegal characters in the values being inserted, how can I not have the script fail, but capture the error and handle it appropriately. I don't want to do the "or die" because I don't want to stop execution of the script. 回答1: Use the RaiseError=>1 configuration in DBI->connect , and wrap your calls to the $dbh and $sth in a try block (TryCatch and Try::Tiny are good implementations for