-
Notifications
You must be signed in to change notification settings - Fork 0
/
marsupial.f90
85 lines (67 loc) · 2.84 KB
/
marsupial.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
! sample model for fortran and SQLite database
! table should already be created
module marsupial
use sqlite
use string_helpers
implicit none
type(SQLITE_DATABASE) :: db
type(SQLITE_STATEMENT) :: stmt
type(SQLITE_COLUMN), dimension(:), pointer :: column
integer :: i
logical :: finished
contains
! subroutine insert(name, latinName, wikiLink, description)
! columns
! character(len=50) :: name, latinName, wikiLink, description
! allocate( column(4) )
! call sqlite3_set_column( column(1), name )
! call sqlite3_set_column( column(2), latinName )
! call sqlite3_set_column( column(3), wikiLink )
! call sqlite3_set_column( column(4), description )
! call sqlite3_insert( db, 'marsupials', column )
! endsubroutine
subroutine getOneMarsupial(query, name, latinName, wikiLink, description)
! columns
character(len=*) :: query
character(len=50) :: name, latinName, wikiLink, description
call sqlite3_open('marsupials.sqlite3', db)
allocate( column(4) )
call sqlite3_column_query( column(1), 'name', SQLITE_CHAR )
call sqlite3_column_query( column(2), 'latinName', SQLITE_CHAR )
call sqlite3_column_query( column(3), 'wikiLink', SQLITE_CHAR )
call sqlite3_column_query( column(4), 'description', SQLITE_CHAR )
call string_replace(query, "'", "_")
call sqlite3_prepare_select( db, 'marsupials', column, stmt, "WHERE LOWER(name) LIKE '%" // trim(query) // "%' LIMIT 4")
i = 1
do
call sqlite3_next_row(stmt, column, finished)
if (finished) exit
call sqlite3_get_column(column(1), name)
call sqlite3_get_column(column(2), latinName)
call sqlite3_get_column(column(3), wikiLink)
call sqlite3_get_column(column(4), description)
exit
end do
endsubroutine
subroutine getAllMarsupials(name, latinName, wikiLink, description)
! columns
character(len=50), dimension(8) :: name, latinName, wikiLink, description
call sqlite3_open('marsupials.sqlite3', db)
allocate( column(4) )
call sqlite3_column_query( column(1), 'name', SQLITE_CHAR )
call sqlite3_column_query( column(2), 'latinName', SQLITE_CHAR )
call sqlite3_column_query( column(3), 'wikiLink', SQLITE_CHAR )
call sqlite3_column_query( column(4), 'description', SQLITE_CHAR )
call sqlite3_prepare_select( db, 'marsupials', column, stmt, "WHERE 1=1 LIMIT 8")
i = 1
do
call sqlite3_next_row(stmt, column, finished)
if (finished) exit
call sqlite3_get_column(column(1), name(i))
call sqlite3_get_column(column(2), latinName(i))
call sqlite3_get_column(column(3), wikiLink(i))
call sqlite3_get_column(column(4), description(i))
i = i + 1
end do
endsubroutine
endmodule