Page 2 of 2 <12
Topic Options
#134335 - 2005-02-24 12:10 AM Re: ODBC - DBcommand
Faithfulman Offline
Getting the hang of it

Registered: 2005-02-22
Posts: 68
Just your code by itself get the result of:

"Operation completed succesfully"

But when I put my code back in I still get the error message from before.??

Top
#134336 - 2005-02-24 12:18 AM Re: ODBC - DBcommand
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Now add this:

$rs = $connection.execute("SELECT workst.wSid FROM workst WHERE workst.pcName = '" + @WKSTA + "'")

? @SERROR


watch for those double/single quotes !

Top
#134337 - 2005-02-24 12:19 AM Re: ODBC - DBcommand
Faithfulman Offline
Getting the hang of it

Registered: 2005-02-22
Posts: 68
I have put the following:


Code:
 

$ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=ncives;USER=test;PASSWORD=test;OPTION=3;"


$sql = 'SELECT * FROM workst'
? $sql
sleep 3


$recordset = DBCommand($ConnDSN,$sql)

$connection = createobject("adodb.connection")
?$recordset

$= $connection.open($ConnDSN)

? @SERROR




? 'Error = '+@ERROR+' - '+@SERROR
sleep 1


for $row=0 to ubound($recordset,1)
for $column=0 to ubound($recordset,2)
? 'Field(row='+$row+', column='+$column+') ='+$recordset[$row,$column]
next
next


? "Your workstation ID number is " + $Recordset




And it appears to NOT be erroring out. It says completed sucessfully in two places. ... but never shows any data.
I'm confused!

Top
#134338 - 2005-02-24 12:19 AM Re: ODBC - DBcommand
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
see above
Top
#134339 - 2005-02-24 12:26 AM Re: ODBC - DBcommand
Faithfulman Offline
Getting the hang of it

Registered: 2005-02-22
Posts: 68
Now I get this error:

Script Error: IDispatch pointers not allowed in exrpession.

Top
#134340 - 2005-02-24 12:31 AM Re: ODBC - DBcommand
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Sounds like a typo somewhere, I would just put these debugging statements in a separate script and run it by itself - we're just trying to narrow down where the problem is, getting close - you shouldn't be getting a syntax error.
Top
#134341 - 2005-02-24 12:46 AM Re: ODBC - DBcommand
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
You cannot just print out an array as in Code:

? $Recordset


Alos, why do you create a separate recordset?
Try this:
Code:

$ConnDSN = 'DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=ncives;USER=test;PASSWORD=test;OPTION=3;'

$sql = 'SELECT * FROM workst'
? 'SQL = '+$sql

$recordset = DBCommand($ConnDSN,$sql)
? 'Error '+@ERROR+' - '+@SERROR

for $row=0 to ubound($recordset,1)
for $column=0 to ubound($recordset,2)
? 'Field(row='+$row+', column='+$column+') ='+$recordset[$row,$column]
next
next


Finally, sprinkle the UDF itself with error checks and step through it via DEBUG ON to see why it fails.
_________________________
There are two types of vessels, submarines and targets.

Top
#134342 - 2005-02-24 06:58 PM Re: ODBC - DBcommand
Faithfulman Offline
Getting the hang of it

Registered: 2005-02-22
Posts: 68
Sealepoard ....

Running Through DEBUG ON .... the error shows up when it gets to this:

? 'Error '+@ERROR+' - '+@SERROR


And It is still the same error:

Error = 2147352567 COM exception error "Open" (ADODB.Recordset - The connection cannot be used to perform this operation. It is either closed or invalid in this context.) [-2147352567/80020009]

Top
#134343 - 2005-02-24 07:11 PM Re: ODBC - DBcommand
Faithfulman Offline
Getting the hang of it

Registered: 2005-02-22
Posts: 68
Shawn,

When I remove all of my code out and replace it with just the code you have shown ... it says Operation complete twice ....
and then ... Press any key to conitue.

But still doesn't show any data.

Any other ideas??

Top
#134344 - 2005-02-24 07:37 PM Re: ODBC - DBcommand
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ok, then lets just see if we can get the results of your query ... heres some new code, change the details as required ... then in the rs.EOF loop, try to display-out one of your field names ... this line here:

?"Name=" $rs.Fields("Name").Value


Change it to display one of your fields. Its good to dig down to this level because it gives an appreciation for how this stuff works under-the-covers (imho) ...

Code:

break on

$= SetOption("WrapAtEol", "On")

$connection = createobject("adodb.connection")

$ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=phone;USER=root;PASSWORD=******;";OPTION=3;"

$= $connection.open($connDSN)

$rs = $connection.execute("SELECT Name FROM Business WHERE Name = 'Shawn'")

While Not $rs.EOF

?"Name=" $rs.Fields("Name").Value

$rs.MoveNext

Loop

exit 1



If you dont see any values, try putting in an @ERROR to catch the error. If it does, we can move on ...

Top
#134345 - 2005-02-24 07:52 PM Re: ODBC - DBcommand
Faithfulman Offline
Getting the hang of it

Registered: 2005-02-22
Posts: 68
Boo ya! I got results!!

Cool .... I just added back in the rest of my code and it works fine ... So why did the UDF not work?? Is it buggy?

Thanks so much for your help!!!

Faithful

Top
#134346 - 2005-02-24 08:06 PM Re: ODBC - DBcommand
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
tbh idk - maybe Jens can fill in the blanks, the only other thing you can try and verify is the GetRows, that returns all the data into a really funky (COM) variant array, and then you parse it yourself (DBCommand parses it into a 2dim array) ... or you can use this $rs.EOF/MOVENEXT thingy to step through the data yourself - but the GetRows() is faster (imho)

The benefit of using EOF/MOVENEXT is that you can change the data model, shift stuff around - and maybe be not so code impacted by that (because your refering to fields through the Fields collection, by name) and not by a hardcoded array index ... your call ...

You can try GetRows like this (after your Execute):

$rows = $rs.getrows()

?"vartype= " + vartypename($rows) + " error=" @SERROR

-Shawn

Top
#134347 - 2005-02-24 08:10 PM Re: ODBC - DBcommand
Faithfulman Offline
Getting the hang of it

Registered: 2005-02-22
Posts: 68
I think that the code you showed will be fine as is. Thanks again so much.

Faithful

Top
#134348 - 2005-02-25 04:23 AM Re: ODBC - DBcommand
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Try to comment out sectionCode:

$rsRecordset.LockType = $adLockReadOnly
if @ERROR
exit @ERROR
endif

and try again. Also, for the error checks we'll need to know the line executed before the error lone triggered.

the function has been confirmed to work with MS Access and MS SQL Server, I don't have MySQL to test with.
_________________________
There are two types of vessels, submarines and targets.

Top
#134349 - 2005-02-25 04:32 AM Re: ODBC - DBcommand
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jens, thought I could help-out by doing a bit of debugging with my mysql, but this syntax works perfectly for me:

Code:

break on

$dsn = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=phone;USER=root;PASSWORD=******;option=3"
$sql = "SELECT Name FROM Business WHERE Name = 'Shawn'"

$rows = DBCommand($dsn, $sql)

? @SERROR

?"VarTypeName=" VarTypeName($rows)

exit 0



Get this:

Quote:


E:\>kix32 t

The operation completed successfully.
VarTypeName=Variant[]





So, this might be some kind of weird issue with his instance.

-Shawn



Top
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 496 anonymous users online.
Newest Members
Raoul, Timothy, Jojo67, MaikSimon, kvn317
17875 Registered Users

Generated in 0.068 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org