% file :	db_store.pl
% but :		stocker dans des bases Mysql/Access via ODBC
% date :	2016 juin


% tests sur pb odbc_query  INSERT
/*  suppose you have in Mysql or Access via ODBC a table :
Table: test_table
Columns: 	PersonID int(11) 
			Name varchar(45) 
			Phone int(11)

*/

open_db:- odbc_connect('mysql_db',Connection,[alias(csv_db)]).				   

query_db(Row):- odbc_query(csv_db,'SELECT * from test_table',Row).
	
insert_1(Res):-
		odbc_query(csv_db,
				'INSERT INTO Test_table (PersonID,Name,Phone) VALUES (1, "jab", 123456)',Res).
insert_2(Res):-
		odbc_query(csv_db,
				'INSERT INTO Test_table (PersonID,Name,Phone) VALUES (~w,"jab2", ~w)'
				- [2,6457],Res).				
insert_3(Res):-
		A=3, B="Patricia",C=12156,
		odbc_query(csv_db,
				'INSERT INTO Test_table (PersonID,Name,Phone) VALUES (~w, ~w, ~w)'
				- [A,B,C],Res).					

insert_4(A,B,C,Res):-
		odbc_query(csv_db,
				'INSERT INTO Test_table (PersonID,Name,Phone) VALUES (~w, ~w, ~w)'
				- [A,B,C],Res).					
		
insert_5(A,B,C,Res):-
		atom_string(B,S),term_to_atom(S,BB),  % a complicated trick ...
		odbc_query(csv_db,
				'INSERT INTO Test_table (PersonID,Name,Phone) VALUES (~w, ~w, ~w)'
				- [A,BB,C],Res).	