Result database connection HP_Omistaja 9. maata 2008 10:42 jtue 18. heita 2008 14:56 48,24 1,0,0,1,1,1,0,,0, 1,6,6,830,536,17 Arial, 15 0,Linkmodule Result_database_conn,2,2,0,1,N:\YEP\users\JuhaV\Projektit\Result Database\Analytica\RDB_connection.ANA 100,1,1,1,2,9,2970,2100,15,0 Write index 1 400,416,1 128,16 1,0,0,1,0,0,0,72,0,1 65535,45873,39321 Write_index Write dimension 1 400,344,1 128,16 1,0,0,1,0,0,0,72,0,1 65535,45873,39321 Write_dimension Write result 1 400,240,1 128,16 1,0,0,1,0,0,0,72,0,1 65535,45873,39321 Write_result Write var 1 400,168,1 128,16 1,0,0,1,0,0,0,72,0,1 65535,45873,39321 Write_var Write run 1 400,272,1 128,16 1,0,0,1,0,0,0,72,0,1 65535,45873,39321 Write_run Inp_ind 0 144,416,1 128,16 1,0,0,1,0,0,0,72,0,1 52425,39321,65535 Inp_ind Inp dim 0 144,344,1 128,16 1,0,0,1,0,0,0,72,0,1 52425,39321,65535 Inp_dim Locs 0 144,448,1 128,16 1,0,0,1,0,0,0,72,0,1 52425,39321,65535 Locs Inp run 0 144,272,1 128,16 1,0,0,1,0,0,0,72,0,1 52425,39321,65535 Inp_run Inp var 0 144,168,1 128,16 1,0,0,1,0,0,0,72,0,1 52425,39321,65535 Inp_var Var for rdb 0 144,240,1 128,16 1,0,0,1,0,0,0,72,0,1 52425,39321,65535 Var_for_rdb Details jtue 18. heita 2008 10:14 48,24 744,288,1 48,24 1,634,13,631,508,17 Concatenation UDFs This library contains functions to make various instances of concatenation more convenient. Concat3 thru Concat10 are generalizations of the built-in Concat function which concatenate from 3 to 10 arrays in a single call (while the built-in Concat concatenates two arrays). ConcatRows concatenates all the rows of a single array. David Kendall & Lonnie Chrisman Mon, Jan 26, 2004 8:49 AM Lonnie Wed, Sep 05, 2007 3:23 PM 48,24 512,696,1 68,24 1,0,0,1,1,1,0,0,0,0 1,39,36,798,452,23 (A1, A2, A3: ArrayType; I1, I2, I3, J: IndexType ) Concat3 Concatenates three arrays, A1, A2, and A3. I1, I2, and I3 are the indexes that are joined; J is the index of the new array; J usually is the concatenation of I1, I2, and I3 Index I12 := Concat(I1,I2); Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, J ) 88,64,1 48,26 2,56,56,986,596 A1,A2,A3,I1,I2,I3,J (A1, A2, A3, A4: ArrayType; I1, I2, I3, I4, J: IndexType ) Concat4 Concatenates four arrays, A1, A2, A3, and A4. I1, I2, I3, and I4 are the indexes that are joined; J is the index of the new array; J usually is the concatenation of I1, I2, I3, and I4. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, J); 192,64,1 48,24 2,30,30,986,596 A1,A2,A3,A4,I1,I2,I3,I4,J 0 (A1, A2, A3, A4, A5, A6, A7, A8, A9: ArrayType; I1, I2, I3, I4, I5, I6, I7, I8, I9, J: IndexType) Concat9 Concatenates nine arrays, A1, ..., A9. I1, ..., I9 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I9. Index I12 := Concat(I1,I2); Index I123 := Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Index I123456 := Concat(I12345, I6); Index I1234567 := Concat(I123456, I7); Index I12345678 := Concat(I1234567, I8); Concat( Concat( Concat( Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, I123456), A7, I123456, I7, I1234567), A8, I1234567, I8, I12345678), A9, I12345678, I9, J); 88,232,1 48,24 2,27,120,469,638 A1,A2,A3,A4,A5,A6,A7,A8,A9,I1,I2,I3,I4,I5,I6,I7,I8,I9,J 0 (A1, A2, A3, A4, A5: ArrayType; I1, I2, I3, I4, I5, J: IndexType ) Concat5 Concatenates five arrays, A1, ..., A5. I1, ..., I5 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I5. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Index I1234 := Concat(I123, I4); Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, J); 88,120,1 48,24 2,160,160,986,596 A1,A2,A3,A4,A5,I1,I2,I3,I4,I5,J (A1, A2, A3, A4, A5, A6: ArrayType; I1, I2, I3, I4, I5, I6, J: IndexType ) Concat6 Concatenates six arrays, A1, ..., A6. I1, ..., I6 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I6. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, J); 192,120,1 48,24 2,644,94,602,712 A1,A2,A3,A4,A5,A6,I1,I2,I3,I4,I5,I6,J 0 (A1, A2, A3, A4, A5, A6, A7: ArrayType; I1, I2, I3, I4, I5, I6, I7, J: IndexType ) Concat7 Concatenates seven arrays, A1, ..., A7. I1, ..., I7 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I7. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Index I123456 := Concat(I12345, I6); Concat( Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, I123456), A7, I123456, I7, J); 88,176,1 48,24 2,580,98,551,565 A1,A2,A3,A4,A5,A6,A7,I1,I2,I3,I4,I5,I6,I7,J (A1, A2, A3, A4, A5, A6, A7, A8: ArrayType; I1, I2, I3, I4, I5, I6, I7, I8, J: IndexType ) Concat8 Concatenates eight arrays, A1, ..., A8. I1, ..., I8 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I8. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Index I123456 := Concat(I12345, I6); Index I1234567 := Concat(I123456, I7); Concat( Concat( Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, I123456), A7, I123456, I7, I1234567), A8, I1234567, I8, J); 192,176,1 48,24 2,12,98,561,737 A1,A2,A3,A4,A5,A6,A7,A8,I1,I2,I3,I4,I5,I6,I7,I8,J 0 (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10: ArrayType; I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, J: IndexType) Concat10 Concatenates ten arrays, A1, ..., A10. I1, ..., I10 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I10. Index I12 := Concat(I1,I2); Index I123 := Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Index I123456 := Concat(I12345, I6); Index I1234567 := Concat(I123456, I7); Index I12345678 := Concat(I1234567, I8); Index I123456789 := Concat(I12345678, I9); Concat( Concat( Concat( Concat( Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, I123456), A7, I123456, I7, I1234567), A8, I1234567, I8, I12345678), A9, I12345678, I9, I123456789), A10, I123456789, I10, J); 192,232,1 48,24 2,542,93,632,744 A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,J 0 (A : ArrayType ; RowIndex,ColIndex,ResultIndex : IndexType) ConcatRows (A,I,J,K) Takes an array, A indexed by RowIndex & ColIndex, and concatenates each row, henceforth flattening the array by one dimension. The result is indexed by ResultIndex, which must be an index with size(RowIndex) * size(ColIndex) elements. index L := [ identifier of RowIndex, identifier of ColIndex, "val"]; slice(Mdarraytotable(A,ResultIndex,L),L,3) 320,64,1 64,24 2,30,320,478,348 A,RowIndex,ColIndex,ResultIndex Var for rdb 'Add variable name'; Test_variable 216,112,1 48,24 1,1,1,1,1,1,0,0,0,0 2,840,465,416,303,0,MIDM [Formnode Var_for_rdb1] 52425,39321,65535 [Cause_of_death_2,Alternative_strategi] [Cause_of_death_2,Cause_of_death_1] [Sys_localindex('I'),1,Sys_localindex('F'),1,Sys_localindex('G'),1] Inp result var a:=sample(Var_for_rdb); {index col:= ['Result_id','Var_id','Result','Sample'];} index endscen:= 1+Card_res..size(Var_for_rdb)+Card_res; index row:= 1..size(endscen)*size(run); index l:= concat(indexnames(Var_for_rdb),['Value']); a:= mdarraytotable(a,endscen,l); a:= a[.l='Value']; a:= if Col1='Result' then a else 0; a:= if Col1='Sample' then run else a; a:= if Col1='Result_id' then endscen else a; a:= if Col1='Var_id' then Variable_cardinality+1 else a; concatrows(a,endscen,run,row) 360,112,1 48,24 2,566,116,528,319 2,855,31,395,516,0,MIDM [Col1,Sys_localindex('ROW')] [Run,1,Sys_localindex('ENDSCEN'),1,Sys_localindex('COL'),1] Variable cardinality max(Results[reslabel='var_id']) 216,32,1 48,24 1,1,1,1,1,1,0,0,0,0 Indices DBTable(Index2, Indexlabel ) 56,440,1 48,23 2,48,126,1024,686,0,MIDM 65535,52427,65534 [Indexlabel,Index2] ['Loc_id','Result_id','Dim_id','Location'] IndexLabel DBlabels(Index2) 56,496,1 48,12 2,102,90,476,353 ['Var_id','Var_name','Var_scope','Var_unit','Validity_date','Run_id','Run_time'] Index DBquery('DSN=resultdatabase','SELECT Rows.Ind_id, Ind_name, row_number, Dimension.Dim_id, Dimension.Dim_name, Location.Loc_id, Location FROM `Dimension`, `Location`, `Rows`, `Index` WHERE Dimension.Dim_id = Location.Dim_id and Location.Loc_id = Rows.Loc_id and `Index`.Ind_id = Rows.Ind_id') 56,472,1 48,12 2,280,290,416,303,0,MIDM [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] Write index dbwrite('DSN=resultdatabase', appendtablesql(inp_row,inp_row.ind,in3,'Rows')); dbwrite('DSN=resultdatabase', appendtablesql(inp_loc,inp_loc.ind,in4,'Location')); dbwrite('DSN=resultdatabase', appendtablesql(inp_ind,inp_ind,in1,'`Index`')); 'Done' 528,520,1 48,24 [Formnode Write_index1] 65535,45873,39321 [] ODBC Library Lonnie Thu, Sep 11, 1997 2:15 PM Lonnie Tue, Feb 05, 2008 10:03 AM 48,24 528,640,1 52,24 1,1,1,1,1,1,0,0,0,0 1,-151,272,499,497,17 Arial, 13 (A:ArrayType;I:IndexType;L:IndexType;row;dbTableName) InsertRecSql Generates the SQL "INSERT INTO" statement for one line of table A. A is a 2-D table indexed by rows I and columns L. L's domain serves as the column names in the database table. dbTableName is the name of the table in the database. The result begins with two semi-colons, since it will be used with an SQL statement preceeding it. (';;INSERT INTO ' & dbTableName & '(' & JoinText(L,L,',') & ') VALUES (' & Vallist(A[I=row],L)) & ')' 184,32,1 52,24 2,235,352,487,423 A,I,L,row,dbTableName (V:ArrayType;I:IndexType) ValList Takes a list of values, and returns a string which the concatenation of each value, separated by commas, and with each value quoted. JoinText( '''' & V & '''', I, ',') 72,32,0 52,24 V,I 1,F,4,14,0,0 (Tabl:ArrayType;RowIndex:IndexType;LabelIndex:IndexType;dbTableName) WriteTableSql(Table,Rows,Labels,dbTableName) Returns the SQL that will write the table to the database table. This can be used as the second argument to DBWrite. This SQL statement replaces the entire contents of an existing table with the new data. 'DELETE FROM '& Dbtablename & JoinText(Insertrecsql(Tabl, Rowindex, Labelindex, Rowindex, Dbtablename),RowIndex) 328,32,1 88,24 2,728,341,510,476 Tabl,RowIndex,LabelIndex,dbTableName (Tabl:ArrayType;RowIndex:IndexType;LabelIndex:IndexType;dbTableName) WriteTableSql(Table,Rows,Labels,dbTableName) Returns the SQL that will write the table to the database table. This can be used as the second argument to DBWrite. This SQL statement replaces the entire contents of an existing table with the new data. JoinText(Insertrecsql(Tabl, Rowindex, Labelindex, Rowindex, Dbtablename),RowIndex) 328,88,1 88,24 2,86,246,510,476 Tabl,RowIndex,LabelIndex,dbTableName Result DBquery('DSN=resultdatabase','SELECT var_name, Restat.*, var_unit, Indices.*, Run.* FROM Variable, Run_list, Run, Loc_of_result, (SELECT var_id, result_id, avg(result) as result, min(result) as minimum, max(result) as maximum, count(sample) as n FROM Result GROUP BY result_id) as Restat, (SELECT Dimension.Dim_id, Dimension.Dim_name, Rows.Ind_id, Ind_name, row_number, Location.Loc_id, Location FROM `Dimension`, `Location`, `Rows`, `Index` WHERE Dimension.Dim_id = Location.Dim_id and Location.Loc_id = Rows.Loc_id and `Index`.Ind_id = Rows.Ind_id) as Indices WHERE Variable.var_id = Restat.var_id and Restat.result_id = Run_list.result_id and Run_list.run_id = Run.run_id and Restat.result_id = Loc_of_result.result_id and Loc_of_result.loc_id = Indices.loc_id ORDER BY run_id DESC, var_id, result_id') 56,224,1 48,13 2,280,290,416,303,0,MIDM [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] Results DBTable(Result1, Reslabel) 56,192,1 48,24 2,17,34,1187,497,0,MIDM 65535,52427,65534 [Reslabel,Result1] ['Loc_id','Result_id','Dim_id','Location'] ResLabel dblabels(Result1) 56,248,1 48,13 2,280,290,416,469,0,MIDM [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] Inp_ind Table(Self,In1)( card_ind+1,'Cause_of_death_2',2 ) ['item 1'] 360,520,1 48,24 [Formnode Inp_ind1] 52425,39321,65535 [In1,Self] [Self,In1] ['Ind_id','Ind_name','Dim_id'] 360,552,1 48,12 ['Ind_id','Ind_name','Dim_id'] Inp dim Table(Self,In2)( card_dim+1,0,0,0,0,0 ) ['item 1'] 360,440,1 48,24 2,360,370,629,303,0,MIDM 2,472,482,416,303,0,MIDM [Formnode Inp_dim1] 52425,39321,65535 [In2,Self] [Self,In2] ['Dim_id','Dim_name','Dim_scope','Dim_unit','Dim_definition','Dim_result'] 360,472,1 48,12 ['Dim_id','Dim_name','Dim_scope','Dim_unit','Dim_definition','Dim_result'] Inp row index ind:= 1..size(locs); var a:= slice(locs, ind); array(in3,[slice(inp_ind[in1='Ind_id'],1),ind,card_loc+ind]) ['item 1'] 360,680,1 48,24 2,250,441,416,303,0,MIDM 2,26,246,404,577,0,MIDM 19661,48336,65535 [In3,Self] [In3,Sys_localindex('IND')] ['item 1'] ['Ind_id','Row_number','Loc_id'] 360,712,1 48,12 Inp loc index ind:= 1..size(locs); var a:= slice(locs, ind); array(in4,[card_loc+ind,slice(inp_dim[in2='Dim_id'],1),a]) ['item 1','item 2','item 3','item 4','item 5','item 6','item 7','item 8','item 9','item 10','item 11','item 12','item 13','item 14','item 15','item 16','item 17','item 18','item 19','item 20','item 21'] 360,600,1 48,24 2,319,169,421,433,0,MIDM 2,31,353,405,433,0,MIDM 19661,48336,65535 [In4,Self] [In4,Sys_localindex('IND')] ['item 1','item 2','item 3','item 4','item 5','item 6','item 7','item 8','item 9','item 10','item 11','item 12','item 13','item 14','item 15','item 16','item 17','item 18','item 19','item 20','item 21'] [Inp_dim,1,In2,1,Locs,9,Sys_localindex('IND'),1,In4,1] ['Loc_id','Dim_id','Location'] 360,632,1 48,12 Card ind max(Indices[Indexlabel='Ind_id']) 216,520,1 48,24 Card dim max(Indices[Indexlabel='Dim_id']) 216,440,1 48,24 Card loc max(Indices[Indexlabel='Loc_id']) 216,600,1 48,24 Locs ['Cardiopulmonary','Lung ca','All others','All causes'] 56,680,1 48,24 [Formnode Locs1] 52425,39321,65535 Write dimension dbwrite('DSN=resultdatabase', appendtablesql(inp_dim,inp_dim,in2,'Dimension')); 'Done' 528,440,1 48,24 [Formnode Write_dimension1] 65535,45873,39321 [] Card res max(Results[reslabel='result_id']) 216,192,1 48,24 Inp loc of result var a:=mid(Var_for_rdb); index h:= indexnames(a); index l:= concat(h,['Value']); index row:= 1..size(a)*size(h); index endscen:= 1+Card_res..size(a)+Card_res; a:= mdarraytotable(a,endscen,l); a:= a[l=h]; var b:= if indices[indexlabel='Ind_name']=h then indices[indexlabel='row_number'] else ''; index d:= 1..max(max(b,index2),h); b:= Positioninindex(b , d, index2 ); b:= indices[index2=b, indexlabel='Loc_id']; var c:= for y:= h do ( index m:= evaluate(y); m:= slice(m,m,d)); a:= if a=c then b else 0; a:= sum(a,a.d); a:= array(col,[endscen,a]); concatrows(a,a.h,endscen,row) 360,192,1 48,24 2,189,75,423,682 2,40,27,416,559,0,MIDM [Col,Sys_localindex('ROW')] [Sys_localindex('H'),1,Sys_localindex('ENDSCEN'),1,Sys_localindex('D'),1] Year_1 1..2 72,88,1 48,13 (1..3)*10 72,112,1 48,12 (1..4)*100 72,136,1 48,12 Test_variable Year_1+Cause_of_death_1+Cause_of_death_2 72,56,1 48,24 2,328,338,416,303,0,MIDM [Cause_of_death_2,Cause_of_death_1] [In5,2,In6,1,In7,1] Write result dbwrite('DSN=resultdatabase', appendtablesql(inp_result,inp_result.row,col1,'Result')); dbwrite('DSN=resultdatabase', appendtablesql(inp_loc_of_result,inp_loc_of_result.row,col,'Loc_of_result')); dbwrite('DSN=resultdatabase', appendtablesql(inp_run_list,inp_run_list.row,in9,'Run_list')); 'Done' 528,192,1 48,24 [Formnode Write_result1] 65535,45873,39321 [] Col1 ['Result_id','Var_id','Result','Sample'] 360,144,1 48,12 Col ['Result_id','Loc_id'] 360,224,1 48,12 Inp run list index endscen:= 1+Card_res..size(Var_for_rdb)+Card_res; array(in9,[endscen,Card_run]) 360,272,1 48,24 2,40,50,372,525,0,MIDM [In9,Sys_localindex('ENDSCEN')] Card run max(Results[reslabel='Run_id']) 216,352,1 48,24 1,1,1,1,1,1,0,0,0,0 ['Result_id','Run_id'] 360,304,0 48,12 1,1,1,1,1,1,0,0,0,0 Inp run Table(Self,In8)( card_run+1,0,0,0 ) ['item 1'] 360,352,1 48,24 2,380,294,629,303,0,MIDM 2,456,466,416,303,0,MIDM [Formnode Inp_run1] 52425,39321,65535 [In8,Self] [Self,In8] 2,D,4,2,0,0,4,0,$,0,"yyyy-mm-dd",0 ['Run_id','Run_date','Run_who','Run_method'] 360,384,1 48,12 ['Run_id','Run_date','Run_who','Run_method'] Inp var Table(Self,In10)( variable_cardinality+1,0,0,0 ) ['item 1'] 360,32,1 48,24 2,0,-23,1272,681 2,510,211,629,303,0,MIDM 2,424,434,416,303,0,MIDM [Formnode Inp_var1] 52425,39321,65535 [In10,Self] [Self,In10] 2,D,4,2,0,0,4,0,$,0,"yyyy-mm-dd",0 ['Var_id','Var_name','Var_scope','Var_definition'] 360,64,1 48,12 ['Var_id','Var_name','Var_scope','Var_definition'] Write var dbwrite('DSN=resultdatabase', appendtablesql(inp_var,inp_var,in10,'Variable')); 'Done' 528,32,1 48,24 [Formnode Write_var1] 65535,45873,39321 [] Write run dbwrite('DSN=resultdatabase', appendtablesql(inp_run,inp_run,in8,'Run')); 'Done' 528,352,1 48,24 [Formnode Write_run1] 65535,45873,39321 [] This module saves model results into the Result Database. You need a password for that. Note that the variables and indexes must exist in the database before you save variables using them. Also, the variable must exist before you can save its results. 256,40,-1 256,40 Variables that should be updated before running the write procedure: 660,100,-1 124,20 Inp var 592,168,-1 56,16 Var for rdb 592,240,-1 56,16 Inp run 592,272,-1 56,16 Inp dim 592,344,-1 56,16 Inp_ind, Locs 592,416,-1 56,16 Note! Currently, you must insert one variable and its results at one time. Variables with no results will cause errors in numbering. 664,40,-1 144,32 Insert a variable 340,160,-6 324,32 1,0,0,1,0,1,0,,0, Te11 Insert a dimension 340,336,-5 324,32 1,0,0,1,0,1,0,,0, Te11 Insert a variable result 340,248,-4 324,48 1,0,0,1,0,1,0,,0, Te11 Insert an index 340,424,-3 324,48 1,0,0,1,0,1,0,,0,