1SQL::Library(3) User Contributed Perl Documentation SQL::Library(3)
2
3
4
6 SQL::Library - A module for managing simple SQL libraries stored in
7 INI-like files.
8
10 This document refers to version 0.0.3 of SQL::Library.
11
13 use SQL::Library;
14
15 my $sql = new SQL::Library { lib => 'sql.lib' };
16 # or { lib => [ <FH> ] };
17 # or { lib => [ $string ] };
18
19 ## Ask for a library entry by name...
20 my $query = $sql->retr( 'some_sql_query' );
21
22 ## Add or update an entry...
23 $sql->set( 'yet_another_query', <<'END' );
24 SELECT foo
25 FROM bar
26 WHERE zoot = 1
27 END
28
29 ## Remove an entry from the library...
30 $sql->drop( 'one_more_query' );
31
32 ## List the entries in the library...
33 print join( ' : ', $sql->elements ), "\n";
34
35 ## Dump the contents of the library to a string...
36 my $lib_str = $sql->dump;
37
38 ## Write the library to disk...
39 $sql->write;
40
42 The format for the library files looks a little like an INI file. How‐
43 ever, unlike an INI file, it does not handle key=value pairs which are
44 divided into sections. Library entry names are on a line by them‐
45 selves, enclosed in square brackets. Whatever occurs until the next
46 title tag is the value of the library entry. Blank lines, pound signs
47 (#) and C++ style comments (//) are all discarded.
48
49 A sample library file might look like this:
50
51 ## A sample library file
52
53 [get_survey_questions]
54 select question_no,
55 question_text
56 from question
57 where survey_id = ?
58 order by question_no
59
60 [get_survey_info]
61 select title,
62 date_format( open_date, '%Y%m%d' ) as open_date,
63 date_format( close_date, '%Y%m%d' ) as close_date,
64 template_file
65 from survey
66 where survey_id = ?
67
69 PACKAGE->new( HASHREF )
70 Create a new library handle. Currently, the only argument sup‐
71 ported in the hashref is "lib", which refers to the file containing
72 the SQL library.
73
74 $OBJ->retr( NAME )
75 Returns the library entry referenced by NAME.
76
77 $OBJ->set( NAME, VALUE )
78 Sets the library entry NAME to VALUE. This is used both to create
79 new library entries and to update existing ones.
80
81 $OBJ->drop( NAME )
82 Drops entry NAME form the library.
83
84 $OBJ->elements
85 Returns a list of all entry names in the library.
86
87 $OBJ->dump
88 Returns a string containing the library contents in the same INI
89 format that the module reads from.
90
91 $OBJ->write
92 Writes the library to the file named in "lib".
93
95 Doug Gorley <douggorley@shaw.ca>
96
98 · write() should write to a string, if it was so called.
99
101 · Complete test suite
102
104 Copyright (C) 2004 by Doug Gorley.
105
106 This library is free software; you can redistribute it and/or modify it
107 under the same terms as Perl itself, either Perl version 5.8.2 or, at
108 your option, any later version of Perl 5 you may have available.
109
110
111
112perl v5.8.8 2004-03-17 SQL::Library(3)