ODBC - Can use file DSN in Rev?

viktoras d. viktoras at ekoinf.net
Tue May 19 08:28:44 EDT 2009


a few years ago, before I learned Revolution, I did database 
applications for Windows in hta/javascript. It used dsn-less connection 
via ActiveX ADODB to a database where all tables were stored in plain 
text files. It could use Access files as well.

For plain text databases it was necessary to specify schema.ini file 
which needs to be put into the same folder with database tables. Here is 
an example of schema.ini contents:
[JoinedAquatics.csv]
ColNameHeader=True
MaxScanRows=0
Format=Delimited(;)
col1 = MasterID Long
col2 = CountryID Short
col3 = SpeciesID Text
col4 = EnvGroupID Text
col5 = FirstDate Short
col6 = SecondDate Short
col7 = VectorID Text
col8 = Vector2ID Text
col9 = ExpertID Text
col10 = VerifiedBy Text
col11 = Comments Text
[SpeciesData.csv]
ColNameHeader=True
MaxScanRows=0
Format=Delimited(;)
Col1=SpeciesID Text
Col2=Authority Text
Col3=CommonName Text
Col4=Taxon Text
Col5=Family Text
Col6=NativeHabitat Text
Col7=EcofunctionalGroup Text
Col8=NativeRangeTDWG2 Text
Col9=NativeRangeDetailsTDWG4 Text
Col10=NativeRangeInland Text
Col11=NativeRangeMarine Text
[SpSynonyms.csv]
ColNameHeader=True
MaxScanRows=0
Format=Delimited(;)
Col1=SpeciesID Text
Col2=Synonyms Text
[Countries.csv]
ColNameHeader=True

Here is the code snippet with some comments, database (folder with 
files) here is called "joined". Unfortunately I have never tried 
replicating this in Rev :-(:

function Dat_Q() {
MasterID = new Array;
CountryID = new Array;
Country = new Array;
SpeciesID = new Array;

<-snipping lots of variable declarations here->

// Create ADO Recordset
dbrcd = new ActiveXObject( "ADODB.Recordset" );

//Create the connection string
//this is how you would use Access databases:
//cString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=Tables.mdb";

//and here is the actual code for text tables:
//cString = "Driver={Microsoft Text Driver (*.txt; 
*.csv)};Dbq=joined;Extensions=asc,csv,tab,txt;";

// Create SQL Statement
//sql = "SELECT habitat from tbTest";

if (sql) {sql=sql;}
else {sql = "SELECT COUNT('SpeciesID') FROM JoinedAquatics.csv"; 
QQ.SQLsent.value=sql;}

// Open connection to database
dbrcd.Open( sql, cString, 1, 3);
//dbrcd.Execute(sql);

// variable to store data
 record = "";
// Loop through all the records found

while( !dbrcd.EOF )
{
       // Loop through each field in this record
       // and add contents to variable
       for( i = 0; i < dbrcd.Fields.Count; i++ )
        {
             record+= dbrcd(i) + "    ";
             switch (i)
             {

case 0 : MasterID[sz]=""+dbrcd(i); break;
case 1 : CountryID[sz]="C"+dbrcd(i); break;
case 2 : Country[sz]=""+dbrcd(i); break;
case 3 : SpeciesID[sz]=""+dbrcd(i); break;
case 4 : Taxon[sz]=""+dbrcd(i); break;
case 5 : EnvGroupID[sz]=""+dbrcd(i); break;
case 6 : FirstDate[sz]=""+dbrcd(i); break;
case 7 : SecondDate[sz]=""+dbrcd(i); break;
case 8 : VectorID[sz]=""+dbrcd(i) ; break;
case 9 : Vector2ID[sz]=""+dbrcd(i) ; break;
case 10: PathwayID[sz]=""+dbrcd(i) ; break;
case 11: AlienHabitatID[sz]=""+dbrcd(i) ; break;
case 12: SpStatusID[sz]=""+dbrcd(i) ; break;
case 13: PopStatus2ID[sz]=""+dbrcd(i) ; break;
case 14: PopStatusID[sz]=""+dbrcd(i) ; break;
case 15: EcolImpactID[sz]=""+dbrcd(i) ; break;
case 16: ImpactOnUsesID[sz]=""+dbrcd(i) ; break;
case 17: InvHistoryID[sz]=""+dbrcd(i) ; break;
case 18: DonorArea[sz]=""+dbrcd(i) ; break;
case 19: NativeRangeMarine[sz]=""+dbrcd(i) ; break;
case 20: Reference[sz] =""+dbrcd(i) ; break;
case 21: Comments[sz]=""+dbrcd(i) ; break;
             }
        }
       
       
       // Display the contents in Textfield
      
       //Move to the next record and loop
       dbrcd.MoveNext();
       record+="\n";
      sz++;
}

return (record);
}

function SQL_Q() {
sql=QQ.SQLsent.value;
QQ.QRez.value=Dat_Q();
}

In principle using this you could write database communicator ir jscript 
and communicate to it from within Revolution...

Best wishes
Viktoras



More information about the use-livecode mailing list