/[eiffelstudio]/trunk/Src/framework/sqlite3/sqlite_query_statement.e
ViewVC logotype

Contents of /trunk/Src/framework/sqlite3/sqlite_query_statement.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 85923 - (show annotations)
Fri Mar 18 15:53:01 2011 UTC (8 years, 8 months ago) by jfiat
File size: 6642 byte(s)
Fixed void-safety issue with sqlite3 library
1 note
2 description: "[
3 An SQLite statement specific for making queries to the database.
4 ]"
5 legal: "See notice at end of class."
6 status: "See notice at end of class."
7 date: "$Date$"
8 revision: "$Revision$"
9
10 class
11 SQLITE_QUERY_STATEMENT
12
13 inherit
14 SQLITE_STATEMENT
15 redefine
16 reset
17 end
18
19 create
20 make
21
22 feature -- Meansurement
23
24 column_count: NATURAL
25 -- The number of columns found in the compiled statement.
26 require
27 is_sqlite_available: is_sqlite_available
28 is_interface_usable: is_interface_usable
29 is_compiled: is_compiled
30 is_connected: is_connected
31 is_accessible: is_accessible
32 do
33 Result := sqlite3_column_count (sqlite_api, internal_stmt).as_natural_32
34 end
35
36 feature -- Query
37
38 column_name (a_column: NATURAL): IMMUTABLE_STRING_8
39 -- Retrieve the name of a column in a statement.
40 --
41 -- `a_column': The column index to retrieve a name for.
42 -- `Result': A column name, or an
43 require
44 is_sqlite_available: is_sqlite_available
45 is_interface_usable: is_interface_usable
46 is_compiled: is_compiled
47 is_connected: is_connected
48 is_accessible: is_accessible
49 a_column_positive: a_column > 0
50 a_column_small_enough: a_column <= column_count
51 local
52 p: POINTER
53 l_names: like internal_column_names
54 l_column: INTEGER
55 do
56 if attached internal_column_names as l_internal_names then
57 l_names := l_internal_names
58 else
59 create l_names.make_filled (Void, 1, column_count.as_integer_32)
60 internal_column_names := l_names
61 end
62
63 l_column := a_column.as_integer_32
64
65 if attached l_names[l_column] as l_result then
66 Result := l_result
67 else
68 p := sqlite3_column_name (sqlite_api, internal_stmt, l_column - 1)
69 if p = default_pointer then
70 create Result.make_empty
71 else
72 create Result.make_from_c (p)
73 end
74 l_names[l_column] := Result
75 end
76 ensure
77 result_attached: attached Result
78 internal_column_names_attached: attached internal_column_names
79 internal_column_names_big_enough: (attached internal_column_names as l_names2) implies
80 l_names2.count.as_natural_32 = column_count
81 internal_column_names_item_set: (attached internal_column_names as l_names2) implies
82 attached l_names2[a_column.as_integer_32]
83 end
84
85 feature -- Basic operations
86
87 frozen execute (a_callback: FUNCTION [ANY, TUPLE [row: SQLITE_RESULT_ROW], BOOLEAN])
88 -- Executes the SQLite query statement and calls back a routine with a result row.
89 --
90 -- `a_callback': A callback function accepting a result row as its argument.
91 -- Return True from the function to abort further calls when there is more result data.
92 -- Note: The row does not change between calls and values must be queried
93 -- immediately.
94 require
95 is_sqlite_available: is_sqlite_available
96 is_interface_usable: is_interface_usable
97 is_compiled: is_compiled
98 is_connected: is_connected
99 not_is_executing: not is_executing
100 is_accessible: is_accessible
101 database_is_readable: database.is_readable
102 a_callback_attached: attached a_callback
103 do
104 execute_internal (a_callback, Void)
105 ensure
106 not_is_executing: not is_executing
107 end
108
109 frozen execute_with_arguments (a_callback: FUNCTION [ANY, TUPLE [row: SQLITE_RESULT_ROW], BOOLEAN]; a_arguments: TUPLE)
110 -- Executes the SQLite query statement with arguments and calls back a routine with a result row.
111 --
112 -- `a_callback': A callback routine accepting a result row as its argument.
113 -- Return True from the function to abort further calls when there is more result data.
114 -- Note: The row does not change between calls and values must be queried
115 -- immediately.
116 -- `a_arguments': The bound arguments to call the SQLite query statement with.
117 -- Valid arguments are those that descent {SQLITE_BIND_ARG} or
118 -- {READABLE_STRING_8}, or of type {INTEGER_*}, {NATURAL_*} (with the expection
119 -- of {NATURAL_64}), or {MANAGED_POINTER} (for blobs).
120 -- Note: If *not* using {SQLITE_BIND_ARG}, the SQLite statement should use ?NNN
121 -- arguments and not named arguments.
122 -- see http://sqlite.org/c3ref/bind_blob.html
123 require
124 is_sqlite_available: is_sqlite_available
125 is_interface_usable: is_interface_usable
126 is_compiled: is_compiled
127 is_connected: is_connected
128 not_is_executing: not is_executing
129 is_accessible: is_accessible
130 database_is_readable: database.is_readable
131 has_arguments: has_arguments
132 a_callback_attached: attached a_callback
133 a_arguments_attached: attached a_arguments
134 a_arguments_count_correct: a_arguments.count.as_natural_32 = arguments_count
135 a_arguments_is_valid_arguments: is_valid_arguments (a_arguments)
136 do
137 execute_internal (a_callback, new_binding_argument_array (a_arguments))
138 ensure
139 not_is_executing: not is_executing
140 end
141
142 feature {NONE} -- Basic operations
143
144 reset
145 -- <Precursor>
146 do
147 internal_column_names := Void
148 Precursor
149 ensure then
150 internal_column_names_detached: not attached internal_column_names
151 end
152
153 feature {NONE} -- Implementation
154
155 internal_column_names: detachable ARRAY [detachable IMMUTABLE_STRING_8]
156 -- Cached column names for the query `column_name'.
157
158 ;note
159 copyright: "Copyright (c) 1984-2011, Eiffel Software"
160 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
161 licensing_options: "http://www.eiffel.com/licensing"
162 copying: "[
163 This file is part of Eiffel Software's Eiffel Development Environment.
164
165 Eiffel Software's Eiffel Development Environment is free
166 software; you can redistribute it and/or modify it under
167 the terms of the GNU General Public License as published
168 by the Free Software Foundation, version 2 of the License
169 (available at the URL listed under "license" above).
170
171 Eiffel Software's Eiffel Development Environment is
172 distributed in the hope that it will be useful, but
173 WITHOUT ANY WARRANTY; without even the implied warranty
174 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
175 See the GNU General Public License for more details.
176
177 You should have received a copy of the GNU General Public
178 License along with Eiffel Software's Eiffel Development
179 Environment; if not, write to the Free Software Foundation,
180 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
181 ]"
182 source: "[
183 Eiffel Software
184 5949 Hollister Ave., Goleta, CA 93117 USA
185 Telephone 805-685-1006, Fax 805-685-6869
186 Website http://www.eiffel.com
187 Customer support http://support.eiffel.com
188 ]"
189
190 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23