ADP
Programming Language ADP

Japanese

Freecode

Sourceforge.net

SourceForge.JP

Loading

DBライブラリのサンプル

コード例(dbsample.p 32ビットWindowsで動作)
+db("Driver={Microsoft Access Driver (*.mdb)}; DBQ=sample.mdb");

# set table quote 
,platform('Unix'),prtn('This program cannot run under Unix.'), exit(1);

#insert / select / sql
,prtn('insert / select')
  ,$rec1 == {"ID"=>1, "col1" => "AAA", "col2" => 10, "col3" => "2010/05/27 17:40:30"}
  ,$rec2 == {"ID"=>2, "col1" => "BBB", "col2" => 20, "col3" => "2010/05/27 17:40:30"}
  ,db.insert( $rec1, "sample_table")
  ,db.insert( $rec2, "sample_table")
  ,db.select@({},'sample_table').prtn,next
  ,db.select@({ 'ID' => 3}, 'sample_table').prtn,next;
  ,db.sql@('select col1, col2 from sample_table where col2 >= ?', { 20 }).prtn.next
  ;
#update / save / select
,prtn('update / save')
  ,$ur1 == {"ID"=>1,  "col1" => "aaa", "col2" => 12, "col3" => "2011/05/27 17:40:30"}
  ,$ur2 == {"ID"=>2,  "col1" => "bbb", "col2" => 22, "col3" => "2011/06/27 17:40:30"}
  ,$ur3 == {"ID"=>4,  "col1" => "ddd", "col2" => 42, "col3" => "2011/07/27 17:40:30"}
  ,db.update( $ur1, "sample_table")
  ,db.save( $ur2, "sample_table")
  ,db.save( $ur3, "sample_table")
  ,db.select@({},'sample_table').prtn,next
  ;

#delete / select
,prtn('delete 2')
  ,db.delete({ "ID" => 2 },'sample_table')
  ,db.select@({},'sample_table').prtn,next
  ;

,prtn('delete all')
  ,db.delete({},'sample_table')
  ,db.select@({},'sample_table').prtn,next
  ;

実行例
D:\sample\lib>adp dbsample.p
insert / select
{ID => 1, col1 => AAA, col2 => 10, col3 => 2010-05-27 17:40:30, col4 => }
{ID => 2, col1 => BBB, col2 => 20, col3 => 2010-05-27 17:40:30, col4 => }
{col1 => BBB, col2 => 20}
update / save
{ID => 1, col1 => aaa, col2 => 12, col3 => 2011-05-27 17:40:30, col4 => }
{ID => 2, col1 => bbb, col2 => 22, col3 => 2011-06-27 17:40:30, col4 => }
{ID => 4, col1 => ddd, col2 => 42, col3 => 2011-07-27 17:40:30, col4 => }
delete 2
{ID => 1, col1 => aaa, col2 => 12, col3 => 2011-05-27 17:40:30, col4 => }
{ID => 4, col1 => ddd, col2 => 42, col3 => 2011-07-27 17:40:30, col4 => }
delete all

Powered by ADP.