how to use ODBC binding for Dart -


i wanted use odbc binding dart this one in app, i'm using oracle xe database, did not how set up, though read basic example in read me :(

attached print screen of oracle xe odb setup, suceed connection, , simple sql statement,

appreciate know following: 1. hoe set-up odbc in dart, 2. how same sql statement executed.

i wrote below:

void main() {   // allocate environment handle.  var henv = new sqlhandle();     sqlallochandle(sql_handle_env, null, henv);      // set odbc version used.  var version = new sqlpointer()..value = sql_ov_odbc3;      sqlsetenvattr(henv, sql_attr_odbc_version, version, 0);      // allocate connection handle.  var hconn = new sqlhandle();  sqlallochandle(sql_handle_dbc, henv, hconn);  // connect. sqlconnect(hconn, "xe", sql_nts, "system", sql_nts, "mypasswords", sql_nts);  // so, need change data only!  // allocate statement handle. var hstmt = new sqlhandle();  sqlallochandle(sql_handle_stmt, hconn, hstmt);  // prepare statement. sqlprepare(hstmt, "select * vendors", sql_nts);   // need print output of sql!!  // execute , fetch data. sqlexecute(hstmt);  sqlfetch(hstmt);   // free statement handle. sqlfreehandle(sql_handle_stmt, hstmt);  // disconnect. sqldisconnect(hconn);  // free connection handle. sqlfreehandle(sql_handle_dbc, hconn);  // free environment handle. sqlfreehandle(sql_handle_env, henv);   } 

thanks

enter image description here

thanks juan, pub author. mistake was, i'm using windows x64, , defined odbc using std odbc, did not notice, pub 32 bit, , i've define odbc using:

(your window directory)\syswow64\odbcad32.exe

enter image description here

the below code worked perfectly

import 'package:odbc/odbc.dart';  void main() {      var henv = new sqlhandle();      sqlallochandle(sql_handle_env, null, henv);       var version = new sqlpointer()..value = sql_ov_odbc3;     sqlsetenvattr(henv, sql_attr_odbc_version, version, 0);      var hconn = new sqlhandle();     sqlallochandle(sql_handle_dbc, henv, hconn);      sqlconnect(hconn, "<dsn>", sql_nts, "<user>", sql_nts, "<pass>", sql_nts);      var hstmt = new sqlhandle();      sqlallochandle(sql_handle_stmt, hconn, hstmt);      sqlprepare(hstmt, "select * vendors", sql_nts);      var col1 = new sqllongbuffer();     var flags1 = new sqlintbuffer();     sqlbindcol(hstmt, 1, col1.ctype(), col1.address(), 0, flags1.address());      var col2 = new sqllongbuffer();     var flags2 = new sqlintbuffer();     sqlbindcol(hstmt, 2, col2.ctype(), col2.address(), 0, flags2.address());      var col3 = new sqlstringbuffer(255);     var flags3 = new sqlintbuffer();     sqlbindcol(hstmt, 3, col3.ctype(), col3.address(), col3.length(), flags3.address());      var col4 = new sqlstringbuffer(255);     var flags4 = new sqlintbuffer();     sqlbindcol(hstmt, 4, col4.ctype(), col4.address(), col4.length(), flags4.address());      sqlexecute(hstmt);      while (sqlfetch(hstmt) != sql_no_data_found) {           print("${col1.peek()} ${col2.peek()} ${col3.peek()} ${col4.peek()} ");      }     sqlfreehandle(sql_handle_stmt, hstmt);     sqldisconnect(hconn);     sqlfreehandle(sql_handle_dbc, hconn);     sqlfreehandle(sql_handle_env, henv); } 

table created:

      create table vendors (              vendor_id number,              vcode number,              vname varchar(255),              vemail varchar(255),              primary key (vendor_id)); 

input data:

 insert vendors values(1, 111, 'one', 'one@vendors.com')  insert vendors values(2, 222, 'two', 'two@vendors.com');  insert vendors values(3, 33, 'three', 'three@vendors.com'); 

console output:

     observatory listening on http://127.0.0.1:49433  1 111 1 one@vendors.com   2 222 2 two@vendors.com   3 33 3 three@vendors.com  

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -