This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/myddas/sqlite3/sqlitest.yap

111 lines
2.1 KiB
Plaintext
Raw Normal View History

2018-06-30 00:57:41 +01:00
:- use_module(library(lists)).
2018-07-02 16:48:00 +01:00
:- use_module(library(maplist)).
2018-06-22 23:55:50 +01:00
:- use_module(library(myddas)).
2017-11-18 00:04:42 +00:00
main :-
2018-03-19 15:41:06 +00:00
init,
main_,
close.
2017-11-18 00:04:42 +00:00
main_ :-
2018-07-02 16:48:00 +01:00
catch(go,E,writeln(E)),
2017-11-18 00:04:42 +00:00
fail.
main_ .
2018-08-07 17:20:43 +01:00
:- if( yap_flag(android,true) ).
2018-07-31 22:13:30 +01:00
init :-
2018-08-07 17:20:43 +01:00
db_open(sqlite3, '/data/user/0/pt.up.yap/files/chinook.db', _, _),
!,
writeln('chinook has landed').
2017-11-18 00:04:42 +00:00
init :-
2018-08-07 17:20:43 +01:00
catch(db_open(sqlite3,'chinook.db',_,_), _, fail),
2018-06-30 00:57:41 +01:00
% db_open(sqlite3, 'chinook.db', _, _),
2018-06-22 23:55:50 +01:00
writeln('chinook has landed').
2018-07-15 13:46:26 +01:00
:- else.
init :-
db_open(sqlite3, '/data/user/0/pt.up.yap.yapdroid/files/Yap/chinook.db', _, _),
% db_open(sqlite3, 'chinook.db', _, _),
writeln('chinook has landed').
2018-08-07 17:20:43 +01:00
:-endif.
2018-06-18 12:16:36 +01:00
2018-06-22 23:55:50 +01:00
go :-
2018-06-27 23:27:08 +01:00
writeln(('db_import')),
db_import('artists', artists),
writeln(('artist -> artists')),
db_import('albums', albums),
writeln(('albums -> albums')),
db_import('tracks', tracks),
writeln(('tracks -> tracks')).
2017-11-18 00:04:42 +00:00
2018-07-02 16:48:00 +01:00
go :-
% X=1,
artists(X,Y),
writeln(X:Y).
2017-11-18 00:04:42 +00:00
go :-
2018-06-27 23:27:08 +01:00
writeln(db_get_attributes_types),
db_get_attributes_types(albums,Als),
format('~w -> ~w~n',[albums,Als]),
db_get_attributes_types(tracks,Ts),
format('~w -> ~w~n',[tracks,Ts]),
db_get_attributes_types(artists,As),
format('~w -> ~w~n',[artists,As]).
go :-
writeln(db_number_of_fields),
db_number_of_fields(albums,Als),
db_number_of_fields(tracks,Ts),
db_number_of_fields(artists,As),
2017-11-18 00:04:42 +00:00
writeln(As:Als:Ts).
2018-03-19 15:41:06 +00:00
go :-
2018-06-28 01:45:42 +01:00
2018-06-27 23:27:08 +01:00
db_describe(albums, Desc), writeln(albums:Desc).
2018-06-22 23:55:50 +01:00
go :-
2018-06-27 23:27:08 +01:00
db_describe(tracks, Desc), writeln(tracks:Desc).
2018-06-22 23:55:50 +01:00
go :-
2018-06-27 23:27:08 +01:00
db_describe(artists, Desc), writeln(artists:Desc).
2018-03-19 15:41:06 +00:00
go :-
2018-06-22 23:55:50 +01:00
db_show_tables(Desc), writeln(tables:Desc).
2018-03-19 15:41:06 +00:00
go :-
2017-11-18 00:04:42 +00:00
db_show_tables(table(T)),
db_describe(T,tableinfo(FieldID,Type,Null,Primary,Default,'')),
writeln(T:tableinfo(FieldID,Type,Null,Primary,Default,'')).
2018-07-02 16:48:00 +01:00
2018-03-19 15:41:06 +00:00
go :-
2018-06-28 01:45:42 +01:00
writeln(access),
2017-11-18 00:04:42 +00:00
go_cut0.
go :-
%stop_low_level_trace,
2018-06-27 23:27:08 +01:00
findall(X:Y,artists(X,Y),Ls),
2017-11-18 00:04:42 +00:00
length(Ls,Total),
sort(Ls, LLs),
length(LLs, T),
writeln(T:Total).
go :-
go_cut1.
go_cut0 :-
2018-06-27 23:27:08 +01:00
artists(X,Y),
2017-11-18 00:04:42 +00:00
writeln(X:Y),
!.
go_cut1 :-
2018-06-30 14:33:32 +01:00
% X=1,
2018-06-27 23:27:08 +01:00
artists(X,Y),
2017-11-18 00:04:42 +00:00
writeln(X:Y),
!.
close :-
db_close.
2018-03-19 15:41:06 +00:00
2018-06-30 14:33:32 +01:00
:- initialization(main).