Re: Matt's ODBC

new topic     » goto parent     » topic index » view thread      » older message » newer message

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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Yes,&nbsp; I'm running your demo w/o =
any changes.=20
mysql shows up in the window, I highlight it and click "connect"&nbsp; =
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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-- odbc.exw<BR>-- Matt Lewis<BR>-- demo =
for=20
odbc.ew</FONT></DIV>
<DIV>&nbsp;</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>&nbsp;</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>&nbsp;&nbsp;&nbsp; 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>&nbsp;</DIV>
<DIV>atom hconn, max_records<BR>sequence query</DIV>
<DIV>&nbsp;</DIV>
<DIV>query =3D {}</DIV>
<DIV>&nbsp;</DIV>
<DIV>procedure connect()<BR>&nbsp;&nbsp;&nbsp; sequence dsn, user,=20
auth<BR>&nbsp;&nbsp;&nbsp; integer ok<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; dsn =3D getLVSelectedText( DSN =
)<BR>&nbsp;&nbsp;&nbsp; dsn=20
=3D dsn[1]<BR>&nbsp;&nbsp;&nbsp; if not length(dsn)=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
return<BR>&nbsp;&nbsp;&nbsp;=20
end if<BR>&nbsp;&nbsp;&nbsp; user =3D getText( UserEdit =
)<BR>&nbsp;&nbsp;&nbsp;=20
auth =3D getText( AuthEdit )<BR>&nbsp;&nbsp;&nbsp; =
trace(1)<BR>&nbsp;&nbsp;&nbsp;=20
hconn =3D openConnectionODBC( dsn, user, auth )<BR>&nbsp;&nbsp;&nbsp; if =
not hconn=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D message_box( =
"Connection=20
Failed","ODBC Error", MB_ICONERROR)<BR>&nbsp;&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D message_box( =
"Connected=20
to: " &amp; dsn, "ODBC Connect", MB_OK )<BR>&nbsp;&nbsp;&nbsp; end =
if<BR>end=20
procedure<BR>onClick[ConnButton] =3D routine_id("connect")</DIV>
<DIV>&nbsp;</DIV>
<DIV>procedure run_query()<BR>&nbsp;&nbsp;&nbsp; atom =
fn<BR>&nbsp;&nbsp;&nbsp;=20
sequence sql<BR>&nbsp;&nbsp;&nbsp; object data<BR>&nbsp;&nbsp;&nbsp;=20
trace(1)<BR>&nbsp;&nbsp;&nbsp; if not hconn=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return =
<BR>&nbsp;&nbsp;&nbsp;=20
end if<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; sql =3D getText( =
SQLEdit=20
)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; if equal( sql, query ) =
and hconn=20
!=3D getCurrentHandle() then =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fn =3D=20
open( "odbc.txt", "a")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
data =3D=20
getData( 0 )<BR>&nbsp;&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; query =3D=20
sql<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
data =3D=20
execDirectODBC( hconn, sql =
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
--freeHandleODBC( 0 )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fn =
=3D open(=20
"odbc.txt", "w")<BR>&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; if sequence( data ) then<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for i =3D 1 to length( =
data )=20
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

print(fn, data[i]) =
puts(fn,"\n")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
end for<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close( fn=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not length( data )=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
fn =3D=20
message_box( "No more records to retrieve",=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
"ODBC Demo",=20
MB_OK)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
query =3D =
{}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

freeHandleODBC( 0 )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
fn =3D=20
message_box( "See odbc.txt for results.",=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
"ODBC Demo", MB_OK=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
if=20
max_records =3D -1 or length(data) &lt; max_records=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
query =3D=20
{}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
freeHandleODBC( 0=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
end=20
if<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end =
if<BR>&nbsp;&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; odbcError( -data=20
)<BR>&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp; <BR>end=20
procedure<BR>onClick[SQLButton] =3D routine_id( "run_query" )</DIV>
<DIV>&nbsp;</DIV>
<DIV>procedure get_dsn()<BR>&nbsp;&nbsp;&nbsp; sequence=20
dsn<BR>&nbsp;&nbsp;&nbsp; integer ok<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; dsn =3D=20
dataSourcesODBC()<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; for i =3D =
1 to=20
length( dsn ) do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D =
addLVItem(=20
DSN, 0, dsn[i])<BR>&nbsp;&nbsp;&nbsp; end for<BR>end =
procedure<BR>onOpen[Main] =3D=20
routine_id("get_dsn")</DIV>
<DIV>&nbsp;</DIV>
<DIV>procedure set_max()<BR>&nbsp;&nbsp;&nbsp; integer =
max<BR>&nbsp;&nbsp;&nbsp;=20
max =3D getNumber( MaxEdit )<BR>&nbsp;&nbsp;&nbsp; if max=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; max_records =3D=20
max<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setMaxRecords( max=20
)<BR>&nbsp;&nbsp;&nbsp; end if<BR>end procedure<BR>onClick[MaxButton] =
=3D=20
routine_id("set_max")</DIV>
<DIV>&nbsp;</DIV>
<DIV>initODBC()</DIV>
<DIV>&nbsp;</DIV>
<DIV>WinMain( Main, Normal )<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>george</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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.&nbsp; Did you call<BR>initODBC()?&nbsp; 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&nbsp; 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--

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu