Avoid complaining from strlen

`
This commit is contained in:
Vítor Santos Costa
2015-09-21 17:05:36 -05:00
parent 880a9989c3
commit 4336b2ba88
469 changed files with 207364 additions and 9193 deletions

View File

@@ -0,0 +1,104 @@
:- ensure_loaded( library(prosqlite) ).
:- ensure_loaded( library(debug) ).
predicated :-
Sfile = 'phones.sqlite',
does_not_exist( Sfile ),
create_db,
interrogate,
write( 'Deleting database file (phones.sqlite).' ), nl,
delete_file( Sfile ),
write( 'Trying to access expired predicate...' ), nl,
end_bit,
nodebug( sqlite ),
write( 'All done.' ), nl.
end_bit :-
catch(phones(name=naku,telephone=T),Excp,(write(caught(Excp)),nl,fail)),
!,
write( not_really(T) ), nl.
end_bit.
create_db :-
sqlite_connect( phones, phones_db, exists(false) ),
create( C ),
sqlite_query( phones_db, C, _AffC ),
% move to dbf example
% sqlite_create( phones_db, phones(name+text,telephone-text,address-text) ),
close_db.
interrogate :-
write( 'Testing arity(arity) option (as default).' ), nl,
sqlite_connect( phones, phones_db, as_predicates(true) ),
forall( insert(I), (sqlite_query(phones_db,I,Row),write(Row),nl) ),
report_phones_db,
findall( U-T, phones(U,T,_), UTs ), write( uts(UTs) ), nl,
findall( T, phones(naku,T,_), Ts ), write( naku(Ts) ), nl,
close_db,
write( 'Testing arity(both) option.' ), nl,
Opts1 = [as_predicates(true),arity(both)],
sqlite_connect( phones, phones_db, Opts1 ),
findall( U-T, phones(U,T,_), UT1s ), write( uts(UT1s) ), nl,
findall( T, phones(naku,T,_), T1s ), write( naku(T1s) ), nl,
findall( U-T, phones([name=U,telephone=T]), UT2s ),
write( uts_unary(UT2s) ), nl,
findall( T, phones([name=naku,telephone=T]), T2s ),
write( naku_unary(T2s) ), nl,
close_db,
write( 'Trying to map to another predicate name.' ), nl,
Opts2 = [as_predicates(true),table_as(phones,catalog,unary)],
sqlite_connect( phones, phones_db, Opts2 ),
findall( U-T, catalog([name=U,telephone=T]), UT2s ),
write( uts_catalog(UT2s) ), nl,
findall( T, catalog([name=naku,telephone=T]), T2s ),
write( naku_cataloh(T2s) ), nl,
close_db,
Mess3='Testing palette value of sqlite_connect/3\'s arity() option.',
write( Mess3 ), nl,
Opts3 = [as_predicates(true),arity(palette)],
sqlite_connect( phones, phones_db, Opts3 ),
findall( U-T, phones( name=U,telephone=T ), UT4s ),
write( uts_binary(UT4s) ), nl,
findall( U-T, phones([name=U,telephone=T]), UT3s ),
write( uts_unary_list(UT3s) ), nl,
findall( T, phones([name=naku,telephone=T]), T3s ),
write( naku_unary_list(T3s) ), nl,
findall( T, phones( name=naku,telephone=T ), T4s ),
write( naku_binary(T4s) ), nl,
report_phones_db,
sqlite_disconnect( phones_db ),
write( 'Closed database.' ), nl, nl.
report_phones_db :-
write( 'Select * from phones : ' ), nl,
write( '---' ), nl,
findall( Row, (sqlite_query(phones_db,'Select * from phones;',Row),write(Row),nl), _ ),
write( '---' ), nl.
create( C ) :-
C = 'CREATE TABLE phones (name text, telephone text, address text, Primary Key (name) );'.
insert( I ) :-
I = 'Insert into phones (name, telephone, address) values ("naku","0044","uk");'.
insert( I ) :-
I = 'Insert into phones (name, telephone, address) values ("άμπελος","0090","turkey");'.
% I = 'Insert into phones (name, telephone, address) values ("ozzy","0090","turkey");'.
close_db :-
sqlite_disconnect( phones_db ),
write( 'Closed database, for now.' ), nl, nl.
does_not_exist( Sfile ) :-
exists_file( Sfile ),
!,
write( 'Delete file "' ),
write( Sfile ),
write( '" to proceed with this example.' ), nl,
fail.
does_not_exist( _Sfile ).
del :- delete_file('phones.sqlite').

View File

@@ -0,0 +1,59 @@
:- use_module( library(prosqlite) ).
/** simple.
==
?- simple.
Using database at: simple.sqlite
create_res(row(0))
i1(Insert into cited_by (pubmed_id,ret_date,citer) values (123, "2012/10/6", 321);)
insert1_res(row(1))
i2(Insert into cited_by (pubmed_id,ret_date,citer) values (120, "2012/10/6", 321);)
insert2_res(row(1))
sel(Select * from cited_by)
sel:row(123,2012/10/6,321)
sel:row(120,2012/10/6,321)
d(Delete From cited_by Where pubmed_id = 120;)
del_row(row(1))
sel:row(123,2012/10/6,321)
true.
?-
==
*/
:- multifile user:message_poperty/2.
message_property(debug(sqlite), color([fg(yellow)])).
simple :-
write( deleting_file('simple.sqlite') ), nl,
catch( delete_file('simple.sqlite'), _, true ),
debug( sqlite ),
sqlite_connect( simple, simple, exists(false) ),
C = 'CREATE TABLE cited_by (pubmed_id bigint(20), ret_date date, citer bigint(20), Primary Key (pubmed_id,citer) );',
sqlite_query( simple, C, Row ),
write( create_res(Row) ), nl,
I1 = 'Insert into cited_by (pubmed_id,ret_date,citer) values (123, "2012/10/6", 321);',
write( i1(I1) ), nl,
sqlite_query( simple, I1, RowI1 ),
write( insert1_res(RowI1) ), nl,
Date = date(2012,10,06),
Pfx2 = 'Insert into cited_by (pubmed_id,ret_date,citer) values (120, ',
sqlite_date_sql_atom( Date, SDate ),
atomic_list_concat( [Pfx2,SDate,', 321);'], I2 ),
write( i2(I2) ), nl,
sqlite_query( simple, I2, RowI2 ),
write( insert2_res(RowI2) ), nl,
Sel = 'Select * from cited_by',
write( sel(Sel) ), nl,
findall( _, (sqlite_query(simple,Sel,FRow),write(sel:FRow),nl), _ ),
D = 'Delete From cited_by Where pubmed_id = 120;',
write( d(D) ), nl,
sqlite_query( simple, D, DRow ),
write( del_row(DRow) ), nl,
findall( _, (sqlite_query(simple,Sel,FRow),write(sel:FRow),nl), _ ),
sqlite_disconnect( simple ).

View File

@@ -0,0 +1,152 @@
:- module( uniprot, [uniprot/0] ).
:- nl, nl, nl.
:- write( 'To get the example database used in this examples do:' ), nl.
:- write( 'wget http://stoics.org.uk/~nicos/sware/sqlite/uniprot.sqlite' ), nl.
:- nl, nl.
:- use_module( library(prosqlite) ).
/** <module> uniprot: A complete example for proSQLite.
Look at the sources for the difference predicate calls.
You need the test database from
http://stoics.org.uk/~nicos/sware/sqlite/uniprot.sqlite
The output should look like:
==
άμπελος;lib/db% swipl -f none
?- uniprot.
Running on :date(2012,10,17)
Using database at: uniprot.sqlite
table:secondary_accessions
table:identifier_mapping
secondary_accessions/secondary_accession
secondary_accessions/primary_accession
identifier_mapping/uniprot_accession
identifier_mapping/identifier_type
identifier_mapping/target_identifier
secondary_accessions:286525
identifier_mapping:3044651
secondary_accessions+286525
identifier_mapping+3044651
[A0A111,Q10706]-_G309
rows_for(_G309):[row(A0A111),row(Q10706)]
by_findall(P64943,[A0A111,Q10706])
Caution! Deleting db entries for-P64943
Affected rows:row(2)
now(P64943,[])
Not to worry! Adding back the db entries for-P64943
affected_two(row(1),row(1))
finally(P64943,[A0A111,Q10706])
v:0:1:0
vd:date(2012,10,17)
citation
Exploring file based databases via an Sqlite interface.
Canisius Sander, Nicos Angelopoulos and Lodewyk Wessels
In the ICLP Workshop on Logic-based methods in Programming Environments (WLPE'12),
p.2-9, 2012. Budapest, Hungary.
true.
?-
==
@version 0.1.2, 2013/11/1
@see latest version at http://stoics.org.uk/~nicos/sware/prosqlite/uniprot.pl
@see also http://stoics.org.uk/~nicos/sware/sqlite/uniprot.sqlite (184Mb)
*/
/** uniprot.
Test predicate for prosqlite. Tests all components.
You need the test database from
http://stoics.org.uk/~nicos/sware/sqlite/uniprot.sqlite
*/
uniprot :-
date( Date ),
write( 'Running on ':Date ), nl,
sqlite_connect('uniprot.sqlite',uniprot, as_predicates(true) ), % connect the database
nl,
show_tables,
show_columns,
show_counts,
findall_counts,
Id = 'P64943',
findall( A, secondary_accessions(A,Id), As ),
write( As-Id ), nl,
Q = 'Select secondary_accession From secondary_accessions Where primary_accession="~w"',
findall( Row, sqlite_format_query( uniprot, Q-'P64943', Row ), Rows ),
write(rows_for(Id):Rows), nl, nl,
findall( S, secondary_accessions(S,Id), SetBef ),
write( by_findall(Id,SetBef) ), nl,
write( 'Caution! Deleting db entries for'-Id ), nl,
sqlite_query( uniprot, 'Delete from secondary_accessions where primary_accession="P64943";', Aff ),
write( 'Affected rows':Aff ), nl,
findall( S, secondary_accessions(S,Id), SetAft ),
write( now(Id,SetAft) ), nl, nl,
write( 'Not to worry! Adding back the db entries for'-Id ), nl,
sqlite_query( uniprot, 'Insert into secondary_accessions (primary_accession,secondary_accession) Values ("P64943","A0A111");', Aff1 ),
sqlite_query( uniprot, 'Insert into secondary_accessions (secondary_accession,primary_accession) Values ("Q10706","P64943");', Aff2 ),
write( affected_two( Aff1, Aff2 ) ), nl,
findall( S, secondary_accessions(S,Id), SetFin ),
write( finally(Id,SetFin) ), nl, nl,
sqlite_version( Ver, VerDate ),
write( v:Ver ), nl,
write( vd:VerDate ), nl, nl,
sqlite_citation( AtmCite, _B ),
write( citation ), nl,
write( AtmCite ), nl.
show_tables :-
sqlite_current_table( uniprot, Table ),
write( table:Table ), nl,
fail.
show_tables :-
nl.
show_columns :-
sqlite_table_column( uniprot, Table, Col ),
write( Table/Col ), nl,
fail.
show_columns :-
nl.
show_counts :-
sqlite_current_table(uniprot, Table),
sqlite_table_count(uniprot, Table, Count),
write(Table:Count), nl,
fail.
show_counts :-
nl.
findall_counts :-
sqlite_current_table(uniprot, Table, arity(Arity) ),
length(List, Arity),
Pred =.. [Table|List],
findall(1, Pred, Ones),
length(Ones, Count),
write( Table+Count ), nl,
fail.
findall_counts :-
nl.