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

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

Serving Software Downloads in 956 Categories, Downloaded 50.477.993 Times

Test::DatabaseRow 1.04

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

Test::DatabaseRow

Report Broken Link
Printer Friendly Version


Product Homepage
Download (38 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
TEST::DATABASEROW RELATED
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....
 
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,...
 
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  
Book Collection Managers  -  WinDataReflector Portable 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...
2.11 MB  
Database Tools  -  PHP Tree Structure stored in MySQL database 1.0
PHP Tree Structure stored in MySQL database is a php script to store and manipulate tree structure in a mysql database, is a free PHP code generator.An example of a typical uses for this would be a web directory. Its important to note that the...
10 KB  
NEW DOWNLOADS IN LINUX SOFTWARE, PROGRAMMING
Linux Software  -  EasyEDA PCB Designer for Linux 2.0.0
EasyEDA, a great web based EDA(Electronics Design Automation) tool, online PCB tool, online PCB software for electronics engineers, educators, students, makers and enthusiasts. Theres no need to install any software. Just open EasyEDA in any...
34.4 MB  
Linux Software  -  wpCache® WordPress HTTP Cache 1.9
wpCache® is a high-performance, distributed object, caching system application, generic in nature, but intended for use in speeding up dynamic web applications, by decreasing database load time. wpCache® decreases dramatically the page...
3.51 MB  
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  
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  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB