Forum Discussion

YagoDaniel92's avatar
YagoDaniel92
Occasional Contributor
2 years ago

Problems connecting to ADODB using Javascript and Firebird

I'm trying to connect to a FireBird database using getActiveXObject("ADODB.Connection") in Java Script, but the function is not returning the result of the query

 

function executeQuery(){
  var withHeader = null  
  
  if (withHeader == null){
    withHeader = false;
  }  
   
  //Variáveis de conexão
  var connection      = getActiveXObject("ADODB.Connection");
  connection.CommandTimeout = 2400;
  var stringConnection   = "DRIVER=Firebird/InterBase(r) driver;DBNAME=C:\\Resulth\\Banco\\RESULTH.FB;UID=sysdba;PWD=masterkey;DIALECT=3;";
  var rs              = getActiveXObject("ADODB.Recordset");
  var result          = new Array();
  var i               = 0;
 
  for (i = 0; i <= 5; i++) {
    try {
        connection.Open(stringConnection);
        rs.Open("select  cidade, estado, codmunicipio from cidades where codcidade = '00001'", connection);
    }
    catch (e) {
        Log.Message(e);
    }
    if (connection.State == 1) {
        Log.Message("Query executada com sucesso!", "select  cidade, estado, codmunicipio from cidades where codcidade = '00001'");
        break;
    }
    else if (connection.State == 0) {
        Log.Message("Query não foi executada com sucesso!", "select  cidade, estado, codmunicipio from cidades where codcidade = '00001'");
        Delay(3000);
    }
}

  if(connection.State == 0){
    Log.Error('Não foi possivel executar a query');
  }
 
   try{
      if (rs.eof){
        resultado = null;
      }
      else{
        while(!rs.eof){
            result[i] = new Array();
            if (withHeader){
              if (i == 0){
                for (var j = 0; j < rs.fields.Count; j++){
                result[i][j] = rs.fields(j).name;
                }
              }else{
                for (var j = 0; j < rs.fields.Count; j++){
                  result[i][j] = rs.fields(j).value;
                }
                rs.MoveNext();
              }
            }else{
              for (var j = 0; j < rs.fields.Count; j++){
                  result[i][j] = rs.fields(j).value;
                }
              rs.MoveNext();
            }
 
           i++;
        }
      }         
    } catch(e){
    result= null;
  }
 
  connection.close; 
 
  return result; 
}

function returnResultQuery(){
  var a;
  a = executeQuery();
  Delay(1);
}

 

Here's an image of the result

 

 

This same code works in JScript if I use "new ActiveXObject("ADODB.Connection");"

Here's the result in JScript

 

I need to run this code in Java Script

 

1 Reply

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I've never used Firebird before, but I have just installed Firebird-4.0.2.2816-0-x64.exe and Firebird_ODBC_2.0.5.156_x64.exe. Created a database, table and inserted some records (from Introduction). Using the example from TC, I'm able to connect and display the values from the table.

     

    I suggest you write a simple query (like above) to see if it works. Also, should your file name have the extension .fdb?