12 integer,
parameter,
private ::
real32 = selected_real_kind(6)
13 integer,
parameter,
private ::
real64 = selected_real_kind(15)
21 use odbql_wrappers,
only: &
32 use,
intrinsic :: iso_c_binding, only: &
36 character(len=*),
intent(in) :: filename
37 character(len=*),
intent(in) :: query
38 integer,
intent(out) :: num_results
41 integer(kind=c_int) :: errstat
42 character(len=500) :: message
43 character(len=*),
parameter :: myname =
"count_query_results" 44 type(odbql_stmt) :: stmt
45 character(len=1000) :: unparsed_sql
48 call odbql_open (trim(filename) // c_null_char, &
52 if (errstat /= 0)
then 53 write (message,
'(a,i0)') myname //
": failure in odbql_open when counting for input file " // &
54 trim(filename) //
", errstat = ", errstat
55 call abor1_ftn (message)
58 call odbql_prepare_v2 (db, &
65 if (errstat /= 0)
then 66 write (message,
'(a,i0)') myname //
": failure in odbql_prepare_v2 when counting for input file " // &
67 trim(filename) //
", errstat = ", errstat
68 call abor1_ftn (message)
73 call odbql_step (stmt, &
79 num_results = num_results + 1
81 write(message,
'(a,i0,a,i0)') myname //
": failure in odbql_step when counting for input file " // &
82 trim(filename) //
", errstat = ", errstat,
" row number = ", num_results + 1
83 call abor1_ftn (message)
87 call odbql_finalize(stmt)
97 use odbql_wrappers,
only: &
102 odbql_column_value, &
114 odbql_value_double, &
117 use,
intrinsic :: iso_c_binding, only: &
121 character(len=*),
intent(in) :: filename
122 character(len=*),
intent(in) :: columns(:)
123 character(len=*),
intent(in) :: filter
124 real(kind=real64),
allocatable,
intent(out) :: data(:,:)
127 integer(kind=c_int) :: errstat
128 character(len=500) :: message
129 character(len=*),
parameter :: myname =
"get_vars" 130 external :: abor1_ftn
131 type(odbql_stmt) :: stmt
132 character(len=1000) :: unparsed_sql
133 integer :: num_results, num_columns, i, j, type
134 type(odbql_value) :: val
135 character(len=5000) :: query
136 character(len=30) :: string_val
138 call odbql_open (trim(filename) // c_null_char, &
142 if (errstat /= 0)
then 143 write (message,
'(a,i0)') myname //
": failure in odbql_open when reading for input file " // &
144 trim(filename) //
", errstat = ", errstat
145 call abor1_ftn (message)
148 num_columns =
size(columns)
154 allocate (
data(num_columns,num_results))
156 call odbql_prepare_v2 (db, &
163 if (errstat /= 0)
then 164 write (message,
'(a,i0)') myname //
": failure in odbql_prepare_v2 when reading for input file " // &
165 trim(filename) //
", errstat = ", errstat
166 call abor1_ftn (message)
169 do i = 1, num_results
170 call odbql_step (stmt, &
172 select case (errstat)
176 write(message,
'(a,i0,a,i0)') myname //
": odbql_step exited early reading input file " // &
177 trim(filename) //
" row number = ", i,
" out of ", num_results
178 call abor1_ftn (message)
180 write(message,
'(a,i0,a,i0)') myname //
": failure in odbql_step when reading for input file " // &
181 trim(filename) //
", errstat = ", errstat,
" row number = ", i
182 call abor1_ftn (message)
184 do j = 1, num_columns
185 val = odbql_column_value(stmt, j)
186 select case (odbql_column_type(stmt, j))
188 data(j,i) = odbql_value_double(val)
190 data(j,i) = odbql_value_int(val)
192 call odbql_column_text (stmt, j, string_val)
193 data(j,i) = transfer(string_val(1:8),
data(j,i))
195 write (message,
'(a,i0,a,i0)') myname //
": invalid column type for row ", i,
" and column ", j
196 call abor1_ftn (message)
201 call odbql_finalize(stmt)
213 character(len=*),
intent(in) :: column_names(:)
214 character(len=*),
intent(in) :: filename
215 character(len=*),
intent(in) :: filter
216 character(len=*),
intent(out) :: sql
219 character(len=10000) :: sql_buffer
222 do i = 1,
size (column_names)
223 sql_buffer = column_names(i)
224 if (i <
size (column_names))
then 225 sql_buffer = trim(sql_buffer) //
"," 227 sql = trim(sql) //
" " // sql_buffer
230 sql = trim(sql) //
" from '" // trim(filename) //
"' where " // trim(filter) //
";" 239 use odb_c_binding,
only: &
246 character(len=*),
intent(in) :: column_names(:)
247 integer,
intent(in) :: column_types(:)
248 character(len=*),
intent(in) :: filename
249 character(len=*),
intent(out) :: sql
251 character(len=300) :: messages(3)
253 character(len=10000) :: sql_buffer
255 sql =
"CREATE TABLE odb AS (" 256 do i = 1,
size (column_types)
257 select case (column_types(i))
259 sql_buffer = trim(column_names(i)) //
" INTEGER" 261 sql_buffer = trim(column_names(i)) //
" REAL" 263 sql_buffer = trim(column_names(i)) //
" STRING" 265 if (i <
size (column_types))
then 266 sql_buffer = trim(sql_buffer) //
"," 268 sql = trim(sql) // sql_buffer
270 sql = trim(sql) //
") ON '" // trim(filename) //
"';" 279 character(len=*),
intent(in) :: column_names(:)
280 character(len=*),
intent(out) :: sql
283 character(len=10000) :: sql_buffer
285 sql =
"INSERT INTO odb (" 286 do i = 1,
size (column_names)
287 sql_buffer = column_names(i)
288 if (i <
size (column_names))
then 289 sql_buffer = trim(sql_buffer) //
"," 291 sql = trim(sql) // sql_buffer
293 sql = trim(sql) //
") VALUES (" // repeat(
"?,",
size (column_names) - 1) //
"?);" subroutine insert_into_sql(column_names, sql)
subroutine create_query_sql(column_names, filename, filter, sql)
subroutine count_query_results(filename, query, num_results)
integer, parameter, private real64
Fortran module with ODB API utility routines.
subroutine create_table_sql(column_names, column_types, filename, sql)
integer, parameter, private real32
subroutine get_vars(filename, columns, filter, data)