Using SQLite with Fortran
Here's code
that demonstrates a way to call
SQLite
library functions from Fortran 77.
While not a complete Fortran API by any means, the
sample code is fairly general. The demo does the following:
- Creates a table with integer, floating point, and text fields.
- Populates the table with random data.
- Queries the table and stores the retrieved values in Fortran variables.
After untarring the file, edit Makefile and modify the values of
LIB and INC so they point to your site's SQLite installation.
Then try this:
> make clean ; make ; ./demo abc.db
On one of my computers the result is:
rm -fr demo *.o core
gcc -I/usr/local/sqlite-3.2.0/include -g -Wall -c sqlite_c_to_fortran_wrapper.c
g77 -I/usr/local/sqlite-3.2.0/include -g -Wall -fno-underscoring -c sqlite_demo.f
g77 sqlite_c_to_fortran_wrapper.o sqlite_demo.o -L/usr/local/sqlite-3.2.0/lib -lsqlite3 -o demo
rm -f abc.db
8000 inserts in 0.261 s = 30598.35 inserts/s
Created database abc.db
select avg(y),count(i),city from ixyt group by city order by city;
returned 8 rows of data
row 1: -2.60341689E-02 995 Berlin
row 2: 8.43827333E-03 962 London
row 3: 3.07258427E-01 1044 Los Angeles
row 4: 5.84130228E-01 994 Madrid
row 5: 8.37801635E-01 989 Quito
row 6: 5.91075420E-01 978 Rome
row 7: 1.97814509E-01 1018 St. Petersburg
row 8: -5.57564318E-01 1020 Tokyo
Note: since the data is random your output will have different values.
@
Al Danial gmail <you know the rest> July 2005
.