Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 30.068.698 Times

Test::DatabaseRow 1.04

Company: Mark Fowler
Date Added: June 13, 2013  |  Visits: 258


Report Broken Link
Printer Friendly Version

Product Homepage
Download (16 downloads)

This is a simple module for doing very very simple quick tests on a database, primarily designed to test if a row exists with the correct details in a table or not. For more advanced testing (joins, etc) it's probably easier for you to roll your own tests by hand than use this module.<br /><br />Exports one test function row_ok. This tests if the first selected row compares to the passed specification.<br /><br />The row_ok takes named attributes that control which rows in which table it selects, and what tests are carried out on those rows.<br /><br />dbh<br /><br /> The database handle that the test should use. In lieu of this attribute being passed the test will use whatever handle is set in the $Test::DatabaseRow::dbh global variable.<br />sql<br /><br /> The sql to select the rows you want to check. Some people may prefer to use the table and where arguments (see below) to have the function build their SQL dynamically for them. This can either be just a plain string, or it can be an array ref of which the first element should contain the SQL with placeholders and the remaining elements will be considered bind variables<br /><br /> # using the plain string version<br /> row_ok(sql => "SELECT * FROM contacts WHERE cid = '123'",<br /> tests => [ name => "Trelane" ]);<br /><br /> # using placeholders and bind variables<br /> row_ok(sql => [ "SELECT * FROM contacts WHERE cid = ?", 123 ],<br /> tests => [ name => "Trelane" ]);<br /><br />table<br /><br /> If you're not using the sql option, then the name of the table the select should be carried out on.<br />where<br /><br /> If you're not using the sql option, then a collection of things that you want combined into a WHERE clause in order to select the row that you want to test.<br /><br /> This is normally a hash of hashes. It's a hashref keyed by SQL comparison operators that has in turn values that are further hashrefs of column name and values pairs. This sounds really complicated, but is quite simple once you've been shown an example. If we could get get the data to test with a SQL like so:<br /><br /> SELECT * FROM foo<br /> WHERE foo = 'bar' AND<br /> baz = 23 AND<br /> fred LIKE 'wilma%' AND<br /> age >= 18<br /><br /> Then we could have the function build that SQL like so:<br /><br /> row_ok(table => "tablename",<br /> where => { '=' => { foo => "bar",<br /> baz => 23, },<br /> 'LIKE' => { fred => 'wimla%', },<br /> '>=' => { age => '18', },});<br /><br /> Note how each different type of comparison has it's own little hashref containing the column name and the value for that column that the associated operator SQL should search for.<br /><br /> This syntax is quite flexible, but can be overkill for simple tests. In order to make this simpler, if you are only using '=' tests you may just pass an arrayref of the columnnames / values. For example, just to test<br /><br /> SELECT * FROM tablename<br /> WHERE foo = bar AND<br /> baz = 23;<br /><br /> You can simply pass<br /><br /> row_ok(table => "tablename",<br /> where => [ foo => "bar",<br /> baz => 23, ]);<br /><br /> Which, in a lot of cases, makes things a lot quicker and simpler to write.<br /><br /> NULL values can confuse things in SQL. All you need to remember is that when building SQL statements use undef whenever you want to use a NULL value. Don't use the string "NULL" as that'll be interpreted as the literal string made up of a N, a U and two Ls.<br /><br /> As a special case, using undef either in a = or in the short arrayref form will cause a "IS" test to be used instead of a = test. This means the statements:<br /><br /> row_ok(table => "tablename",<br /> where => [ foo => undef ],)<br /><br /> Will produce:<br /><br /> SELECT * FROM tablename<br /> WHERE foo IS NULL<br /><br />tests<br /><br /> The comparisons that you want to run between the expected data and the data in the first line returned from the database. If you do not specify any tests then the test will simply check if any row is returned from the database.<br /><br /> Normally this is a hash of hashes in a similar vein to where. This time the outer hash is keyed by Perl comparison operators, and the inner hashes contain column names and the expected values for these columns. For example:<br /><br /> row_ok(sql => $sql,<br /> tests => { "eq" => { wibble => "wobble",<br /> fish => "fosh", },<br /> "==" => { bob => 4077 },<br /> "=~" => { fred => qr/barney/ },},);<br /><br /> This checks that the column wibble is the string "wobble", column fish is the string "fosh", column bob is equal numerically to 4077, and that fred contains the text "barney". You may use any infix comparison operator (e.g. "<", ">", "&&", etc, etc) as a test key.<br /><br /> The first comparison to fail (to return false) will cause the whole test to fail, and debug information will be printed out on that comparison.<br /><br /> In a similar fashion to where you can also pass a arrayref for simple comparisons. The function will try and Do The Right Thing with regard to the expected value for that comparison. Any expected value that looks like a number will be compared numerically, a regular expression will be compared with the =~ operator, and anything else will undergo string comparison. The above example therefore could be rewritten:<br /><br /> row_ok(sql => $sql,<br /> tests => [ wibble => "wobble",<br /> fish => "fosh",<br /> bob => 4077,<br /> fred => qr/barney/ ]);<br /><br />verbose<br /><br /> Setting this option to a true value will cause verbose diagnostics to be printed out during any failing tests. You may also enable this feature by setting either $Test::DatabaseRow::verbose variable the TEST_DBROW_VERBOSE environmental variable to a true value.<br />store_rows<br /><br /> Sometimes, it's not enough to just use the simple tests that Test::DatabaseRow offers you. In this situation you can use the store_rows function to get at the results that row_ok has extacted from the database. You should pass a reference to an array for the results to be stored in; After the call to row_ok this array will be populated with one hashref per row returned from the database, keyed by column names.<br /><br /> row_ok(sql => "SELECT * FROM contact WHERE name = 'Trelane'",<br /> store_rows => @rows);<br /><br /> ok(Email::Valid->address($rows[0]{'email'}));<br /><br />store_row<br /><br /> The same as store_rows, but only the stores the first row returned in the variable. Instead of passing in an array reference you should pass in either a reference to a hash...<br /><br /> row_ok(sql => "SELECT * FROM contact WHERE name = 'Trelane'",<br /> store_rows => %row);<br /><br /> ok(Email::Valid->address($row{'email'}));<br /><br /> ...or a reference to a scalar which should be populated with a hashref...<br /><br /> row_ok(sql => "SELECT * FROM contact WHERE name = 'Trelane'",<br /> store_rows => $row);<br /><br /> ok(Email::Valid->address($row->{'email'}));

Requirements: No special requirements
Platforms: *nix, Linux
Keyword: Column Comparison Database Function Quotselect Row Oksql Simple Store Rows String Table Tests Values
Users rating: 0/10

License: Freeware Size: 10.24 KB
Database Tools  -  Simple Power SQLite class 0.6
Simple Power SQLite class is a simple class written in PHP, useful for standard operation with SQLite: - database creation, - connection, - submit query, - simple transaction mechanism, - decode encode binary file, - extend SQLite function,...
Database Tools  -  ZDB 0.1
ZDB ( DataBase) can be used to maintain simple lists and databases (such as telephone directories, address lists, etc). The project implements mechanisms for basic queries and reporting, and also allows us to join two tables by a...
6.14 KB  
Database Tools  -  Web Based Database Query Tool for Scripts 1.1
Web Based Database Query Tool is a simple free Web based MySql database query tool.Features:- Web based mysql database query tool in php.- Easy to use tool that can be integrated in to any web page.- Dynamically change to any database or host.-...
10 KB  
Libraries  -  Database Schema Reader 1.2.1
Database Schema Reader is a simple, cross-database facade over .Net 2.0 DbProviderFactories to read database metadata. Get Database Schema Reader and take it for a spin to see what it can actually do for you!
Database Tools  -  Web Based Database Query Tool 1.1
Web Based Database Query Tool is a simple free Web based MySql database query tool.Features: - Web based mysql database query tool in php. - Easy to use tool that can be integrated in to any web page. - Dynamically change to any database or host....
Database Tools  -  AGTC - CSV File Upload Script 1.0a
Upload your CVS converted MS Excel or Text files to your Mysql database very easily with this simple little script. You can use it independently or integrate into your existing script.Free to download for non commercial use. Visit our site for...
10 KB  
Libraries  -  Libeval 1.0.7
Libeval provides simple means of evaluating simple arithmetic expressions involving literal numeric values, variables and functions using the addition (+), subtraction (-), multiplication (*), division (/), modulo division (), exponentiation (^),...
27.65 KB  
Book Collection Managers  -  WinDataReflector Free 1.4.1
WinDataReflector is a lightweight file synchronization and backup tool that wraps up fast file comparison and transfer algorithms into a simple and clear interface that offers you visual comparison of files and folders before synchronizing and...
1.69 MB  
Book Collection Managers  -  WinDataReflector Free 64 bit 1.3.3
WinDataReflector is a lightweight file synchronization and backup tool that wraps up fast file comparison and transfer algorithms into a simple and clear interface that offers you visual comparison of files and folders before synchronizing and...
1.94 MB  
Miscellaneous  -  Combining simple and specific property creation 1.0
This script provides a function that will automate simple property creation, while allowing its users to provide specific fget/fset/fdel methods. By default, a simple property with get, set, and delete methods will be created. Optionally, specific...
Linux Software  -  Polling Autodialer Software 3.4
ICTBroadcast Auto Dialer software has a survey campaign for telephone surveys and polls. This auto dialer software automatically dials a list of numbers and asks them a set of questions that they can respond to, by using their telephone keypad....
488 B  
Linux Software  -  Total Video Converter Mac Free 3.5.5
Total Video Converter Mac Free developed by EffectMatrix Ltd is the official legal version of Total Video Converter which was a globally recognized brand since 2006. Total Video Converter Mac Free is a free but powerful all-in-one video...
17.7 MB  
Linux Software  -  Skeith mod_log_sql Analyzer 2.10beta2
Skeith is a php based front end for analyzing logs for Apache using mod_log_sql.
47.5 KB  
Linux Software  -  SLAX 6.0+
Slax is a modern, portable, small and fast Linux operating system with a modular approach and outstanding design. Despite its small size, Slax provides a wide collection of pre-installed software for daily use, including a well organized graphical...
190 KB  
Linux Software  -  GTK+ 2.5
GTK+, which stands for the GIMP Toolkit, is a library for creating graphical user interfaces for the X Window System. It is designed to be small, efficient, and flexible. GTK+ is written in C with a very object-oriented approach. Language bindings...
60 MB  
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by, it is used to describe information about an application such as the name and...
327.68 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB