RAA - safequery/2.2005.8.15

safequery / 2.2005.8.15

Short description: Builds safe SQL query. Covers almost all common operations.
Category: Library/Database
Status: stable
Created: 2005-08-15 15:58:56 GMT
Last update: 2005-08-15 16:43:34 GMT
Owner: Jan Molič (Projects of this owner)
Homepage: http://simplypowerful.1984.cz/safequery/doc/index.html
Download: http://simplypowerful.1984.cz/safequery/safequery.tgz
License: Ruby's
Dependency:
None
Description:
# = SafeQuery
#
# == Version
# 1.2005.8.8 (change of the first value means Big Change)
#
# == Description
# Build sql query from a template and a data hash.
#
# == Features
# * covers almost all common sql problems:
#   * just escape string (table name, etc.)
#   * key lists: INSERT INTO table(a,b,c)
#   * value lists: VALUES('a','b','c')
#   * joined lists: a = 'aaa'
#   * joined lists: a LIKE 'aaa'
#   * list separators: a = 'aaa', b = 'bbb', c = 'ccc'
#   * list separators: a LIKE 'aaa' OR b LIKE 'bbb' OR c LIKE 'ccc'
# * parameters for filtering lists: "not empty", "not null" and "not false"
# * both keys and values are escaped
# * nil, false and true values aren't placed between ''
# * false is converted into not(key) instead of key='false'
#
# == Usage
# Simply run safequery.rb and see the output.
# Look at examples below. Okay, an example:
#
# 1. Create a template query.
#       safequery = 'UPDATE TABLE #foo# (#mydata keys not null#) VALUES (#mydata values not null#)'
#
# 2. Create a data hash.
#       hsh = {
#               'foo' => 'my_foo_table',
#               'mydata' => {
#                       'a' => 'AAA',
#                       'b' => '',
#                       'c' => nil,
#                       'd' => 'DDD',
#                       'e' => false
#       }
#
# 3. Get result (FooDB is used because of 'escape' method. You can specify another name of the method as the second parameter).
#
#       sq = SafeQuery.new( FooDB.new )
#       p sq.get( q, hsh )
#
# 4. The result should be:
#
#       UPDATE TABLE my_foo_table (a,b,d,e) VALUES ('AAA','','DDD',false)
#
# == Author
# jan molic /mig/at_sign/1984/dot/cz/
# Please send comments if your database doesn't accept
# slashed numbers, "key=true", etc. I use safequery with mysql 4.1.x.
#
# == Licence
# You can redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.
#
#=end
Versions: [4.2006.05.26 (2006-05-26)] [4.2006.04.19 (2006-05-25)] [4.2006.03.23 (2006-03-23)] [4.2006.03.15 (2006-03-15)] [4.2006.03.14 (2006-03-14)] [3.2005.8.28 (2005-08-30)] [2.2005.8.16 (2005-08-16)] [2.2005.8.15 (2005-08-15)] [1.2005.8.8 (2005-08-15)] [2.2005.8.8 (2005-08-15)]

Edit this project (for project owner)

back to RAA top