| 1 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // FILE : test.tol |
|---|
| 3 | // PURPOSE: test of database handling with TOL |
|---|
| 4 | // requieres an active database connection |
|---|
| 5 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 6 | |
|---|
| 7 | Text email_ = "vdebuen@tol-project.org"; |
|---|
| 8 | Text link_ = ""; |
|---|
| 9 | Text summary_ = "Creates and drops a table with time series"; |
|---|
| 10 | |
|---|
| 11 | //Write here the initial test TOL code if needed |
|---|
| 12 | |
|---|
| 13 | Real numErrIni = Copy(NError); //Initial number of errors |
|---|
| 14 | |
|---|
| 15 | Write("Checking if therea are active databases ... "); |
|---|
| 16 | Set dbConns = DBGetOpened(""); |
|---|
| 17 | Real ok0 = Card(dbConns)>0; |
|---|
| 18 | WriteLn(If(ok0,"OK","FAIL")); |
|---|
| 19 | |
|---|
| 20 | Real execQueryDrop1_1 = DBExecQuery("drop table ser1"); |
|---|
| 21 | Serie ser1 = SubSer(Gaussian(0,1,Diario), y2005m1d1, y2005m12d31); |
|---|
| 22 | Real createSeriesTable1 = DBCreateSeriesTable("ser1", SetOfSerie(ser1)); |
|---|
| 23 | //-- |
|---|
| 24 | Real execQueryDrop2_1 = DBExecQuery("drop table series"); |
|---|
| 25 | Serie ser2 = SubSer(Gaussian(0,1,Diario), y2005m7d1, y2006m6d30); |
|---|
| 26 | Real createSeriesTable2 = DBCreateSeriesTable("series", SetOfSerie(ser1,ser2)); |
|---|
| 27 | //-- |
|---|
| 28 | Set setSeries1 = DBSeries("select * from series", Diario, SetOfText("ser1a","ser1b")); |
|---|
| 29 | //-- |
|---|
| 30 | Text getSer1SQL = "select 'serie1', Date, ser1" + |
|---|
| 31 | " from series" + |
|---|
| 32 | " where ser1 IS NOT NULL"; |
|---|
| 33 | Set setSeries2 = DBSeriesColumn(getSer1SQL, Diario); |
|---|
| 34 | //-- |
|---|
| 35 | Text getSeriesSQL = "select 'ser', Date, ser1, ser2 from series"; |
|---|
| 36 | Set setSeries3 = DBSeriesTable(getSeriesSQL, Diario, SetOfText("Data1", "Data2")); |
|---|
| 37 | //-- |
|---|
| 38 | Set setSeries4 = DBTable("Select * from series"); |
|---|
| 39 | //-- |
|---|
| 40 | Text getMatrixSQL = "Select ser1, ser2 " + |
|---|
| 41 | " from series " + |
|---|
| 42 | " where ser1 is not NULL and ser2 is not NULL"; |
|---|
| 43 | Matrix mat = DBMatrix(getMatrixSQL); |
|---|
| 44 | |
|---|
| 45 | Real execQueryDrop1_2 = DBExecQuery("drop table ser1"); |
|---|
| 46 | Real execQueryDrop2_2 = DBExecQuery("drop table series"); |
|---|
| 47 | |
|---|
| 48 | Real numErrorEnd = Copy(NError); //Final number of errors |
|---|
| 49 | |
|---|
| 50 | //Expected number of errors is numErrIni+3 if no database connection is |
|---|
| 51 | //active. Else, if a_simple_table not exists execQuery1 will be -1 and an |
|---|
| 52 | //error will be sent. |
|---|
| 53 | Real numErrorExpected = If(ok0, numErrIni, numErrIni+16)+ |
|---|
| 54 | 2*(execQueryDrop1_1<0)+ |
|---|
| 55 | 2*(execQueryDrop2_1<0); |
|---|
| 56 | |
|---|
| 57 | //Extented information about test behaviour |
|---|
| 58 | Set partialResults_ = |
|---|
| 59 | [[ |
|---|
| 60 | numErrIni, numErrorEnd, numErrorExpected, |
|---|
| 61 | createSeriesTable1, |
|---|
| 62 | createSeriesTable2, |
|---|
| 63 | Real numSer1 = Card(setSeries1), Real ok1 = numSer1==If(!ok0,0,2), |
|---|
| 64 | Real numSer2 = Card(setSeries2), Real ok2 = numSer2==If(!ok0,0,1), |
|---|
| 65 | Real numSer3 = Card(setSeries3), Real ok3 = numSer3==If(!ok0,0,1), |
|---|
| 66 | Real numSer4 = Card(setSeries4), Real ok4 = numSer4==If(!ok0,0,546), |
|---|
| 67 | Real numRows = Rows(mat), Real ok5 = numRows==If(!ok0,0,184), |
|---|
| 68 | Real numCols = Columns(mat), Real ok6 = numCols==If(!ok0,0,2), |
|---|
| 69 | Real okQry = And(ok1,ok2,ok3,ok4,ok5, |
|---|
| 70 | execQueryDrop1_2==0, |
|---|
| 71 | execQueryDrop2_2==0) |
|---|
| 72 | ]]; |
|---|
| 73 | |
|---|
| 74 | Real quality_ = If(ok0, okQry, If(okQry, ?, false)); |
|---|
| 75 | |
|---|
| 76 | Real Dbt.Exists = ObjectExist("Set","Dbt.Connect"); |
|---|
| 77 | //Return the results |
|---|
| 78 | Set resultStr_ = @strTestStatus(summary_, link_, quality_, |
|---|
| 79 | "Partial results = "<<partialResults_, |
|---|
| 80 | If(Dbt.Exists,Dbt.Connect->engine_, ""), |
|---|
| 81 | If(Dbt.Exists,Dbt.Connect->host_, ""), |
|---|
| 82 | If(Dbt.Exists,Dbt.Connect->alias_, ""), |
|---|
| 83 | email_); |
|---|
| 84 | WriteLn(""<<resultStr_); |
|---|
| 85 | resultStr_ |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | /* */ |
|---|