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.5 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.
43 However, unlike an INI file, it does not handle key=value pairs which
44 are divided into sections. Library entry names are on a line by
45 themselves, enclosed in square brackets. Whatever occurs until the
46 next title tag is the value of the library entry. Blank lines, pound
47 signs (#) 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
71 supported in the hashref is "lib", which refers to the file
72 containing 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 · write() should write to a string, if it was so called.
96
98 · Complete test suite
99
101 Doug Gorley <douggorley@shaw.ca>
102
104 Chris Vertonghen <chrisv@cpan.org> (post-0.0.3)
105
107 Copyright (C) 2004 by Doug Gorley.
108
109 This library is free software; you can redistribute it and/or modify it
110 under the same terms as Perl itself, either Perl version 5.8.2 or, at
111 your option, any later version of Perl 5 you may have available.
112
113
114
115perl v5.28.1 2012-06-05 SQL::Library(3)