Looking at DBI Part 10, Getting it For Free


In part 9 we had a look at ASIC transactions as implemented by DBI now we are going to have a look at getting more back from DBD $sth than just the rows updated or the the record set.

Look Ma no Hands

There are many times when playing with RDBS that we would like to get just a little more back form the DB when we do something. What comes to mind first of is those nasty primary_key values after we do an insert. Most if not all RDBS have some way to get them back at least in the SQL world but how do I do this in DBI.

bind_param_inout

Well the answer is to use the SQL and the bind_param_inout method to get value from the DB. Most mainstream DBD do work I will just use DBD::Oracle as I have the code handy.

AUTOINCREMENT

jHackers

I found the site that Japanese hackers is introduced by English. This will help to know what Japanese hacker think.

jHacker


Post #1

Hello everyone, this is my first post here.
I'm fairly new to Perl (~1 year experience) and to testing. I'd like to write not so much articles, but short, to the point code snippets with comments that are useful for those, who are new to Perl, DBIx::Class, PerlDancer2 and testing.
I will try to post things that I would like to know when I started out, but could not find them.

Porting Test::Class to the p5-mop

Stevan Little has been asking people to port things to the p5-mop-redux or to create new modules. I decided to reimplement Test::Class::Moose as Test::Class::MOP. The following works:

Looking at DBI Part 9, d'ho

Ouch I didn't Mean to do That

In part 8 we used fetchall_arrayref to get just the fields we want and not the entire row now we will looks at when we make mistakes.

DBI Transactions

In a perfect world, we would never need our old friends commit and rollback. But hard disks die, the power goes out, and fingers click the wrong buttons; so DBI supports the age-old ACID Module for transactions. As long as the underlying DBD driver and RDBMS and Driver support it as well.

To get transactions to work on DBI, you first have to set the AutoCommit attribute of our database handle to off. One normally does this when creating the handle like this:

$dbh = DBI->connect('dbi:Oracle:', 'hr@localhost/XE', 'hr', {AutoCommit => 0});


We can now use the DB handle's rollback and commit methods much as you would in any PSQL program.

UPDATE employees SET salary = ? WHERE last_name = ?

To use transactions with the foregoing SQL, you would create the handle like this:

Perl and Raspberry Pi

Perl and Raspberry Pi :

[From my blog.]

In Delicious, I start to inform translation of Perl Tutorial by Code Examples

In Delicious, I start to inform translation of Perl Tutorial by Code Examples. You can know the post of my transation.

Delicious - yukikimoto

Debuging method for perl Complex data structures

For complex data structures (references, arrays and hashes) you can use the Data::Dumper

use Data::Dumper qw(Dumper);

print Dumper \@an_array;
print Dumper \%a_hash;
print Dumper $a_reference;

These will print something like this, which helps understand the content of the variables, but shows only a generic variable name such as $VAR1 and $VAR2.

Great Mystic Mystery Revealed

Your all excited you spent 3 months of your own special free time working on your first CPAN package.

You spent so many hours on an IRC discussing how it should work your spouse suspects your getting a bit on the side.

You included a test suite of over 500 tests,

You put blood, sweat and tears into the Makefile.PL so it will load on any perl on any platform.

If you see one more comment on prepan from that son of a jerk off byterock you're going to punch in in the throat next time you see him at YAPCE:EU

So you clicked the button on PAUSE and had to endure that wait, while PAUSE does it thing. So you go to bed and sleep soundly knowing that by morning my code will be up on CPAN.

You jump out of bed with the anticipation of a six year old on Christmas morning only
to see this

d'ho.jpg

on your Module page.

Billions of Blue Blistering Barnacles

OT: DataCite Recommends "doi:" Scheme Prefix

(Posted here so I don't forget it and others can find it...)

In the latest DataCite Metadata Kernel document, section "2.2 Citation", DataCite recommends ("prefers" is their term) that original-format DOIs used in citations include the doi: scheme prefix. ("Original format" refers to non-URL DOIs.) Unfortunately, the DataCite Metadata Kernel document does not mention that the string doi: is a scheme prefix, making it hard to find.

An example DOI with the scheme prefix is doi:10.1006/ijhc.1996.0110.

Enable Travis-CI for a Github repository from the command line

Travis-CI is a Really Useful Engine, but I've only enabled it for a handful of my GitHub repositories because navigating though GitHub's settings to do so is a bit of a pain.

Seemed like this should be scriptable though - turns out it is! Edit that script to include your GitHub login details, and Travis-CI details, save it as travis-status somewhere in your $PATH, chmod +x travis-status and you're ready to go!

Running travis-status in a project's root directory (and I'm assuming the project's root directory has the same name as the repository's slug) with no parameters will print out a list of all event hooks for the project (not just Travis ones). Running it and passing "1" or "0" as the parameter will enable or disable Travis for the project.

Windows Shell to Perl Program

Have you ever whipped up a quick shell script that later you wished was a real program? We did an experimental workshop at MadMongers on Tuesday where we, as a group, roughed out a Perl program from a Windows batch file. The whole process worked out rather well and we plan to try it again with another topic, perhaps something like web scraping or doing something with a web service. Here are the brief notes (also available in MadMongers files):

Premise
We have a windows script that we want to convert to a real programming language for the following reasons:


* Cross platform availability
* Code readability
* Flexibility in parsing, templating, and storage of data
* To learn a real programming language


The existing script looks like this:

Looking at DBI Part 8, Splice That Batch

Get Just What You Want

In part 7 we used fetchall_arrayref to get an entire resultset into an array ref. One nice thing that DBI adds with this method it the ability to get just the fields we want and not the entire row.

So if where given this this SQL

SELECT Employee_Id, First_Name, Last_Name, Email, Phone_Number, Hire_Date, Job_Id, Salary, Commission_Pct, Manager_Id, Department_Id FROM employees

and from this were are required only want the first, third, second, and the fifth column, we can invoke fetchall_arrayref() to cut down on the amount of space our array ref may take up.

So what we want is simply invoke fetchall_arrayref() like this:

my $employees = $sth->fetchall_arrayref([0,2,1,5]);

Our final code would look like this:

Perl Redis Mailing List

cross-posted from dams blog

Perl Redis Mailing List

This is going to be a short post. I'm the new maintainer of Redis.pm, the most used Redis Perl client. Pedro Melo was the previous maintainer, but due to Real Life, he is unable to continue. I'd like to thank him for all his efforts so far in maintaining and improving this module. I hope I'll be able to achieve the same level of quality. Pedro will actually stay around for a while, watching over my shoulder and giving his opinions about stuff, to allow for a smooth transition.

We've used this maintainership change to improve the tools we use around this project. So we've moved the code to the github's PerlRedis organization (notice the cool logo), and I've performed quite a few code cleanups and housekeeping.

But the big thing is the creation of a mailing list, that aims at gathering forces around Redis support in Perl. It's located here, and hosted by the good folks at ShadowCat Systems Limited (thank you guys).

It is not limited to the Redis.pm module: any Perl related Redis topic is welcome, including other Perl clients. So if you have any interest in Perl and Redis, feel free to subscribe !

dams.

Using Stratopan Beta

This morning, an innocent message landed in my mailbox:

[Stratopan] The Beta Is Here

Usually, advertisements go directly to .. "you-know-where", but this one was highly appreciated!

(Read on for what I did. With screenshots! :-)

Marpa's Advantages

Anyone looking for an overview of Marpa's advantages, is encouraged to head straight for chapter 2 of the Marpa Papers.

Looking at DBI Part 7, Batch Fetching

More Data Fetching

In part 5 and part 6 we looked at fetching a single record from queries into either a array, array ref or even a hash refs now we will look at fetching more than one record at a time.

selectall_arrayref

Many times when working with data, it is desirable to have all of the rows returned at once. The is especially so in the Perl world, which has so many nifty little tools to manipulate arrays in all sorts of different ways. DBI has a both a method on the statement handle and one on the database handle that can utilize batch fetching.

The database handle method, selectall_arrayref(), is most useful when you want to get the data from static SQL more that once in a program.

Hello Perl World

I will record the fun and valued things during my advanture of perl learning.

Failed compilations can be partially successful

Apparently Perl doesn't clean up after a failed compile. However far it got sticks around. I didn't discover this myself, but here's an example:

Padre 1.00 has been released

That's right, Padre, the Perl IDE has just hit the 1.0 milestone.

Sadly there's not a lot of fanfare over this release. For the most part the changes from 0.98 to 1.0 have been patches applied by Kevin Dawson (bowtie) and improvements to the Debugger - Kevin's project in Padre.

The Change list for release 1.0 is as follows:

- Applied Patch in #1488 comment:7 itcharlie++ (BOWTIE)
- Apply patch for #1504 dod++ (BOWTIE)
- Apply patch2 from #1459 bojinlund++ (BOWTIE)
- Update Makefile.PL with new versions (BOWTIE)
- Add Patch for cut n paste adam++ #1312 (BOWTIE)
- Fix Debug ip hanging, use 127.0.0.1 instead of localhost (BOWTIE)
- fix some unwanted background noise from debug raw (BOWTIE)
- Apply patch from #1508 itcharlie++ (BOWTIE)
- Add refresh_breakpoint_panel to Wx::Main (BOWTIE)
- Add correct comment for PerlXS (BOWTIE)

As you can see Kevin is keeping the wheels turning and people are submitting patches.

While development isn't as active as it once was, Padre is still seeing improvements, but releases are a little further apart.

If you are using Padre and you want to see something fixed or added feel free to drop into #padre on irc.perl.org say hi, ask questions, change the world! :)

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.