Re: Matt's ODBC
- Posted by George Walters <gwalters at sc.rr.com> Dec 21, 2002
- 543 views
This is a multi-part message in MIME format. ------=_NextPart_000_0046_01C2A788.ECA7B580 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks for the response Matt. Yes, I'm running your demo w/o any changes. mysql shows up in the = window, I highlight it and click "connect" and it says connected but no = sql statement works. I looked at the handle returned (hconn) and it is = -2. Here it is. -- odbc.exw -- Matt Lewis -- demo for odbc.ew include print.e include win32lib.ew include odbc.ew with trace without warning constant Main =3D create( Window, "ODBC Demo", 0, 20, 20, 600, 500, 0), DSN =3D create( ListView, {"DSN","Type"}, Main, 10, 20, 400, 250,=20 LVS_REPORT+LVS_SINGLESEL ), ConnButton =3D create( PushButton, "Connect", Main, 20, 280, 90, 30, 0), SQLButton =3D create( PushButton, "Run SQL", Main, 140, 280, 90, 30, 0), SQLEdit =3D create( MleText, "", Main, 20, 320, 400, 100, 0), UserEdit =3D create( EditText, "User ID", Main, 250, 280, 90, 25, 0), AuthEdit =3D create( EditText, "Password", Main, 350, 280, 90, 25, 0), MaxEdit =3D create( EditText, "-1", Main, 450, 280, 30, 25, 0), MaxButton =3D create( PushButton, "Set Max", Main, 450, 320, 90, 30, 0) atom hconn, max_records sequence query query =3D {} procedure connect() sequence dsn, user, auth integer ok =20 dsn =3D getLVSelectedText( DSN ) dsn =3D dsn[1] if not length(dsn) then return end if user =3D getText( UserEdit ) auth =3D getText( AuthEdit ) trace(1) hconn =3D openConnectionODBC( dsn, user, auth ) if not hconn then ok =3D message_box( "Connection Failed","ODBC Error", = MB_ICONERROR) else ok =3D message_box( "Connected to: " & dsn, "ODBC Connect", = MB_OK ) end if end procedure onClick[ConnButton] =3D routine_id("connect") procedure run_query() atom fn sequence sql object data trace(1) if not hconn then return=20 end if =20 sql =3D getText( SQLEdit ) =20 if equal( sql, query ) and hconn !=3D getCurrentHandle() then=20 fn =3D open( "odbc.txt", "a") data =3D getData( 0 ) else query =3D sql =20 data =3D execDirectODBC( hconn, sql ) --freeHandleODBC( 0 ) fn =3D open( "odbc.txt", "w") end if =20 if sequence( data ) then =20 for i =3D 1 to length( data ) do print(fn, data[i]) puts(fn,"\n") end for =20 close( fn ) =20 if not length( data ) then =20 fn =3D message_box( "No more records to retrieve",=20 "ODBC Demo", MB_OK) query =3D {} freeHandleODBC( 0 ) else =20 fn =3D message_box( "See odbc.txt for results.",=20 "ODBC Demo", MB_OK ) =20 if max_records =3D -1 or length(data) < max_records then query =3D {} freeHandleODBC( 0 ) end if =20 end if else odbcError( -data ) end if =20 end procedure onClick[SQLButton] =3D routine_id( "run_query" ) procedure get_dsn() sequence dsn integer ok =20 =20 dsn =3D dataSourcesODBC() =20 for i =3D 1 to length( dsn ) do ok =3D addLVItem( DSN, 0, dsn[i]) end for end procedure onOpen[Main] =3D routine_id("get_dsn") procedure set_max() integer max max =3D getNumber( MaxEdit ) if max then max_records =3D max setMaxRecords( max ) end if end procedure onClick[MaxButton] =3D routine_id("set_max") initODBC() WinMain( Main, Normal ) george ----- Original Message -----=20 From: Matthew Lewis=20 To: EUforum=20 Sent: Thursday, December 19, 2002 3:47 PM Subject: RE: Matt's ODBC George, This appears to be the error code, SQL_INVALID_HANDLE. Did you call initODBC()? This must be done in order to set some things up. Matt Lewis -----Original Message----- From: George Walters [mailto:gwalters at sc.rr.com] Running Matt's odbc.exw example, I get a handle from = "openConnectionODBC()" of minus 2 (-2). Is this a legitimate handle? If I continue it says = I've conneced, but any sql statement produces an error and the demo blows = up.. ------=_NextPart_000_0046_01C2A788.ECA7B580 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Thanks for the response = Matt.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Yes, I'm running your demo w/o = any changes.=20 mysql shows up in the window, I highlight it and click "connect" = and it=20 says connected but no sql statement works. I looked at the handle = returned=20 (hconn) and it is -2. Here it is.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>-- odbc.exw<BR>-- Matt Lewis<BR>-- demo = for=20 odbc.ew</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>include print.e<BR>include = win32lib.ew<BR>include=20 odbc.ew<BR>with trace<BR>without warning</FONT></DIV> <DIV> </DIV><FONT face=3DArial size=3D2> <DIV><BR>constant<BR>Main =3D create( Window, "ODBC Demo", 0, 20, 20, = 600, 500,=20 0),<BR>DSN =3D create( ListView, {"DSN","Type"}, Main, 10, 20, 400, 250, = <BR> LVS_REPORT+LVS_SINGLESEL ),<BR>ConnButton =3D = create(=20 PushButton, "Connect", Main, 20, 280, 90, 30, 0),<BR>SQLButton =3D = create(=20 PushButton, "Run SQL", Main, 140, 280, 90, 30, 0),<BR>SQLEdit =3D = create( MleText,=20 "", Main, 20, 320, 400, 100, 0),<BR>UserEdit =3D create( EditText, "User = ID",=20 Main, 250, 280, 90, 25, 0),<BR>AuthEdit =3D create( EditText, = "Password", Main,=20 350, 280, 90, 25, 0),<BR>MaxEdit =3D create( EditText, "-1", Main, 450, = 280, 30,=20 25, 0),<BR>MaxButton =3D create( PushButton, "Set Max", Main, 450, 320, = 90, 30,=20 0)</DIV> <DIV> </DIV> <DIV>atom hconn, max_records<BR>sequence query</DIV> <DIV> </DIV> <DIV>query =3D {}</DIV> <DIV> </DIV> <DIV>procedure connect()<BR> sequence dsn, user,=20 auth<BR> integer ok<BR> =20 <BR> dsn =3D getLVSelectedText( DSN = )<BR> dsn=20 =3D dsn[1]<BR> if not length(dsn)=20 then<BR> = return<BR> =20 end if<BR> user =3D getText( UserEdit = )<BR> =20 auth =3D getText( AuthEdit )<BR> = trace(1)<BR> =20 hconn =3D openConnectionODBC( dsn, user, auth )<BR> if = not hconn=20 then<BR> ok =3D message_box( = "Connection=20 Failed","ODBC Error", MB_ICONERROR)<BR> =20 else<BR> ok =3D message_box( = "Connected=20 to: " & dsn, "ODBC Connect", MB_OK )<BR> end = if<BR>end=20 procedure<BR>onClick[ConnButton] =3D routine_id("connect")</DIV> <DIV> </DIV> <DIV>procedure run_query()<BR> atom = fn<BR> =20 sequence sql<BR> object data<BR> =20 trace(1)<BR> if not hconn=20 then<BR> return = <BR> =20 end if<BR> <BR> sql =3D getText( = SQLEdit=20 )<BR> <BR> if equal( sql, query ) = and hconn=20 !=3D getCurrentHandle() then = <BR> fn =3D=20 open( "odbc.txt", "a")<BR> = data =3D=20 getData( 0 )<BR> =20 else<BR> query =3D=20 sql<BR> <BR> = data =3D=20 execDirectODBC( hconn, sql = )<BR> =20 --freeHandleODBC( 0 )<BR> fn = =3D open(=20 "odbc.txt", "w")<BR> end if<BR> =20 <BR> if sequence( data ) then<BR> =20 <BR> for i =3D 1 to length( = data )=20 do<BR> = print(fn, data[i]) = puts(fn,"\n")<BR> =20 end for<BR> =20 <BR> close( fn=20 )<BR> =20 <BR> if not length( data )=20 then<BR>  = ;=20 <BR> = fn =3D=20 message_box( "No more records to retrieve",=20 <BR> &nb= sp; =20 "ODBC Demo",=20 MB_OK)<BR> &nb= sp;=20 query =3D = {}<BR> = freeHandleODBC( 0 )<BR> =20 else<BR> =20 <BR> = fn =3D=20 message_box( "See odbc.txt for results.",=20 <BR> &nb= sp; =20 "ODBC Demo", MB_OK=20 )<BR> =20 <BR> = if=20 max_records =3D -1 or length(data) < max_records=20 then<BR>  = ; =20 query =3D=20 {}<BR> &= nbsp; =20 freeHandleODBC( 0=20 )<BR> = end=20 if<BR> = <BR> end = if<BR> =20 else<BR> odbcError( -data=20 )<BR> end if<BR> <BR>end=20 procedure<BR>onClick[SQLButton] =3D routine_id( "run_query" )</DIV> <DIV> </DIV> <DIV>procedure get_dsn()<BR> sequence=20 dsn<BR> integer ok<BR> =20 <BR> <BR> dsn =3D=20 dataSourcesODBC()<BR> <BR> for i =3D = 1 to=20 length( dsn ) do<BR> ok =3D = addLVItem(=20 DSN, 0, dsn[i])<BR> end for<BR>end = procedure<BR>onOpen[Main] =3D=20 routine_id("get_dsn")</DIV> <DIV> </DIV> <DIV>procedure set_max()<BR> integer = max<BR> =20 max =3D getNumber( MaxEdit )<BR> if max=20 then<BR> max_records =3D=20 max<BR> setMaxRecords( max=20 )<BR> end if<BR>end procedure<BR>onClick[MaxButton] = =3D=20 routine_id("set_max")</DIV> <DIV> </DIV> <DIV>initODBC()</DIV> <DIV> </DIV> <DIV>WinMain( Main, Normal )<BR></FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>george</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV style=3D"FONT: 10pt arial">----- Original Message -----=20 <DIV style=3D"BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> <A=20 title=3Dmatthewwalkerlewis at YAHOO.COM=20 href=3D"mailto:matthewwalkerlewis at YAHOO.COM">Matthew Lewis</A> </DIV> <DIV><B>To:</B> <A title=3DEUforum at topica.com=20 href=3D"mailto:EUforum at topica.com">EUforum</A> </DIV> <DIV><B>Sent:</B> Thursday, December 19, 2002 3:47 PM</DIV> <DIV><B>Subject:</B> RE: Matt's ODBC</DIV></DIV> <DIV><BR></DIV>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The Euphoria Mailing = List =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20 <BR><BR>George,<BR><BR>This appears to be the error code,=20 SQL_INVALID_HANDLE. Did you call<BR>initODBC()? This must be = done in=20 order to set some things up.<BR><BR>Matt Lewis<BR><BR>-----Original=20 Message-----<BR>From: George Walters=20 [mailto:gwalters at sc.rr.com]<BR><BR><BR>Running Matt's odbc.exw example, = I get a=20 handle from "openConnectionODBC()"<BR>of minus 2 (-2). Is this a=20 legitimate handle? If I continue it says I've<BR>conneced, but any sql = statement=20 produces an error and the demo blows=20 up..<BR><BR>=3D=3D^=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<BR>This=20 email was sent to: <A=20 href=3D"mailto:gwalters at sc.rr.com">gwalters at sc.rr.com</A><BR><BR>EASY = UNSUBSCRIBE=20 click here: <A=20 href=3D"http://topica.com/u/?b1dd66.b2Shsm.Z3dhbHRl">http://topica.com/u/= ?b1dd66.b2Shsm.Z3dhbHRl</A><BR>Or=20 send an email to: <A=20 href=3D"mailto:EUforum-unsubscribe at topica.com">EUforum-unsubscribe@topica= .com</A><BR><BR>T=20 O P I C A -- Register now to manage your mail!<BR><A=20 href=3D"http://www.topica.com/partner/tag02/register">http://www.topica.c= om/partner/tag02/register</A><BR>=3D=3D^=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= ------=_NextPart_000_0046_01C2A788.ECA7B580--