June 2018 Archives

Gather Up Baby Moose

Its gather in the dream day here in the Moose-pen

Well going to skip a post on creating a gaggle of new tests today and instead do some core coding in Driver::DBI and Database::Accessor. Now believe it or not I had a dream last night that something was wrong in the way I set the architecture of Grathers and Filters, GROUP BY and , HAVING in SQL, in Database::Accessor. Boy this does sound corny!. So today I started to look at that part of my code.

In the original Data::Accessor a 'GROUP BY' and 'HAVING' looked like this


{ …

Baby Moose Link

Its link day here in the Moose-Pen

Well seeing as my elements/fields and conditions/Where are working quite well I think it is time to move on to the next attribute in Accessor.pm Links.

In SQL joins are the same as Database::Accessor Links so given this SQL;


SELECT people.first_name, people.last_name, people.id, address.street FROM people LEFT JOIN address ON people.id = address.user_id WHERE people.first_name = ?


the

LEFT JOIN address ON people.id = address.…

Baby Moose Where?

Its where day in the Moos-Pen

Today I am going to expand on the '20_where_basic.t' test case going from a simple one level Element to Param 'where clause' such as


SELECT people.first_name, people.last_name, people.user_id FROM people WHERE ( people.first_name = ? AND people.last_name = ?


to the much more complex Function, Expression, nested and mixed clauses that I was using in the last few posts.

First I decided to re-factor my tests from the start and using the 'element_sql_ok' sub from this post I re-fact…

Back to Momma Moose

Just another quick test postette day here in the Moose Pen.

As we seen in this post I found a bug where I was not coercing correctly on deeply nested Element Attributes. So that means back into the test suite of Database::Accessor I go to cover that bug and the new recusion functionality I have added recently.

Checking the current state of the test suite I see that I never did go deeper than one level of elements, though I do check to ensure that the View on elements are correct and the correct …

Matureing Baby Moose

Its re-factor test postette day in the Moose-Pen

Over the past few days I have made up quite a few tests and they where all the same pattern

  • Base hash
  • add function/expression element
  • create DA
  • run select/retrieve
  • check SQL
  • check parms
so a little re-factoring is in order me thinks., Though there is a school of thought that it is a waste of resources to re-factor working test. Fortunately I do not ascribe to that thought so here we go.

The re-factoring was quite simple, I took my test;

/users/byterock/2018/06/index.html

Baby Fancy Moose

Its get fancy day here in the Moose-Pen

Now that I have 'Functions' nicely working I am going to move on to the next logical field and that is an 'Expression'. In SQL (and 99.9% of other languages) an expression is just a predicate that can be evaluated. So an SQL like this


SELECT user.username, user.salary + 10 FROM users WHERE username='BOB'


In Database::Accessor I have an Expression class for this and it works 90% the same as the Function class I just finished. Thus this expression;
="pre…

Baby Moose Recursion Dance

It carry on with recursion day here in the Moose-Pen

Carrying on from where I left off in yesterday's post I was about to add in this new test;


$in_hash->{elements}->[0] = { function => 'substr',
left => { name => 'username' },
right => [{ param =>3},{ param =>5}] };
my $da = Database::Accessor->new($in_hash);
$da->retrieve( $utils->connect() );
ok(
$da…

Ambitious Baby Moose

Its get back into Driver::DBI day today here in the Moose-Pen

I decided to get a little more ambitious and see it I can get Driver::DBI to handle a function call in an SQL select, like this;


SELECT user.username,
left(user.username,11),
user.address
FROM user
WHERE user.username = 'Bill'


The way I have planned to do this is Database::Accessor with the 'Function' class, which has a simple string attribute for the function name and it is used with 'Comparator' role…

Baby Moose Clean Up

It is test catch up day here in the Moose-pen.

I figured it is a good thing to review the state of the test suites for both Database::Accessor and Driver::DBI and starting with Accessor.pm I get this;


t/20_dad_load.t (Wstat: 1024 Tests: 53 Failed: 7)
Failed tests: 6, 12, 18, 24, 51-53
Parse errors: Bad plan. You planned 50 tests but ran 53.
t/30_view.t (Wstat: 256 Tests: 9 Failed: 1)
Failed test: 5
Parse errors: Bad plan. You planned 10 tests but ran 9.
t/31_elements.t …

Baby Moose in the Field

Back to the Field day here in the Moose-Pen

Today I am going to give params and containers a miss and move back into the '30_fields.t' test that I left alone so long ago. One of the planned concepts in Database::Accessor it the ability to have static data as part of the elements array. This is accomplished by using the 'Param' class in place of the “Element' class so you could do an SQL like this


SELECT 'User Name:', username, 'Address:', address FROM user


Why one wold want to do that I am not 100% sure on thou…

Happy Sunny Moose Day

Quick postette day here in the Moose-Pen.

So yesterday I had left over SQL error that I wanted to have a look at. The error was


FROM locations WHERE *>.city =


so I had no view in the where predicate;

$new_da->add_condition({left =>{ name => 'city',
},
right =>{ value => $other_user}
});

Baby Moose Proof

Just prove it worked day here in the Moose-pen

So yesterday I left off with my SQL looking correct but my query failing on the DBD::DBM so to-day I though I better just do a quick postette just to prove to my many readers that my code actually works.

So I all did was write up this quick little script


#!perl
use DBI;
use Data::Dumper;
use Database::Accessor;
my $dbh = DBI->connect("DBI:Oracle:",
"a user id" ,
"a password");

my $new_da = Database::Accessor->new({view=>{name=>…

Baby Moose Takes Charge

Its get very ambitious day here in the Moose-pen.

As things went just a little to smoothly over the past few post I though it would be a good day to try something that I know is going to cause me grief. In the vain I added this test;


use Database::Accessor;
my $is_bill = Database::Accessor->new({view=>{name=>'user'},
elements=>[{name=>'username'}],
conditions=>{left =>{ name => 'username',
view => 'us…

Another Baby Moose Break

Its still param day here in the Moose-Pen

Carrying on from yesterday's post I, today I added in one more test;


ok($user->update( $utils->connect(),$container),"update with present container");
$user->reset_conditions();
$container = [{address =>'MNO'},
{address =>'PQR'},
{address =>'STU'},
];
$user->add_condition({left =>{ name => 'username',
vie…

Baby Moose Break

It playing with update and container day here in the Moose-pen.

Now that I have the 'create' function working so well with execute_array I figured the next logical step would be to do 'update' function but I have one small problem. When I attempt to do this;


$container = [Test::User->new({username=>'Bill',address =>'ABC'}),
{username=>'Jane',address =>'DEF'},
Test::User->new({username=>'John',address =>'HIJ'}),
{username=>'Joe',address =>'KLM'},
];
$user-…

Baby Moose struts his stuff

Well is still container day here in the Moose-pen.

So now that I have the 'execute_array' all fixed up and working I think I will carry on the same past and get the container to work with an array of 'classes'. In that end I created this little class;


package Test::User;
use Moose;
has username => ( is => 'rw',
isa => 'Str',);
has address => ( is => 'rw',
isa => 'Str',);
1;


Now the next thing I needed to do was make a test out of what I fixed yest…

Yes Baby Moose had a Bug.

Well it is look at another module day here in the Moose-Pen.

So yesterday I ran into this problem;


DBD::DBM::st execute_array failed: 4 bind values supplied but 2 expected [for Statement "INSERT INTO user ( user.address, user.username ) VALUES( ?, ? )"] at …

Which rather peeved me as I tried the same code on two other DBs and the both ran. So it it just me? I took a look at example in the DBI POD;

$dbh->{RaiseError} =…

Baby Moose Has a Bug?

Well it get lucky postette day here in the Moose-Pen.

Well I left off yesterday a little worried that I was only testing half of the execute_array as I never actually got down into the DBI code of things. So I decided lets give it a try on that pre-installed 'DBD::DBM' that I used in my '10_crud_basic.t' test case as according to the DBI docs there shold be a defult implimentsion of 'execute_array''

Well I opened that sucker up and added this in


An Array of Baby Moose

Its a little harder day here in the Moose-Pen.

Carrying on with adding to the '32_params.t' case I though today I would tackle one of the harder parts of prams and that is passing an array of params or in my case containers into a query statement.

So in my test I could have this;


$container = [{first_name=>'Bill',last_name =>'Bloggings'},
{first_name=>'Jane',last_name =>'Doe'},
{first_name=>'John',last_name =>'Doe'},
{first_name=>'Joe',last_name =>'Blow'},

Baby Moose Makes a Stand

Its fix typo and a little programming day here in the Moose-Pen.

Before I get back on track and start working on test case '32_params.t' but before that I had to clean-up in my code. Seems I had 'parenthes' all over the place when it should really be 'parentheses' so the last thin I did last night was clean all those up. Thank goodness for Padre and it search and replace functions.

Anyway on to '32_params.t' and the fist thing I did was cut out some tests from other places and put them in there as it made a little more logical sense. From 20_where_basic.t I striped out al…

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations