Jump to content
Sign in to follow this  
bartekd

_sql.au3 - No Records

Recommended Posts

bartekd

Hello all, I have been using Autoit for a couple years, and over time have been learning as I go. Recently I have expanded into using SQL. At my work we have a million little queries that we use all the time. We use SQL 2000, so I found the _sql.au3 which has done wonders.

I have all my queries running nicely. However there is one issue that I have not been able to see the solution for even as I have searched the forum allot for. When I run a select statement, and there are no results, it doesn't display anything, but if there is results, it displays it in 2d array. Is there a piece of code that I can add that if there are no results it will display a msg box or something. Here is some of my code.

Let me know if I can provide any other information.

#include <array.au3>

#include <_sql.au3>

_SQLRegisterErrorHandler();register the error handler to prevent hard crash on COM error

$listname = 'TDCS08'

$con = _SQLStartup()

If @error then Msgbox(0,"Error","Error starting ADODB.Connection")

_SQLConnect(-1,"toronto4","gcti_500",'Username','password')

if @Error then Msgbox(0,"",$SQLErr)

$Query = "select top 20 * from " & $ListName

$data = _SQLExecute(-1,$Query)

If Not @error then

$aData = _SQLGetData2D($data)

_arrayDisplay($aData)

Else

Msgbox(0,"",$SQLErr)

EndIf

_SQLClose()

Share this post


Link to post
Share on other sites
Juvigy

I am not 100% sure but i think it should return "null" if no entries are found so just check: if $data=="null" then Msgbox()

Share this post


Link to post
Share on other sites
bartekd

Thanks for the suggestion, but that doesn't seem to work. Can anyone else think of something?

Share this post


Link to post
Share on other sites
Juvigy

Maybe it is returning blank string - ""? I dont have _sql include file. What does _SQLExecute return if no records are found??

Share this post


Link to post
Share on other sites
ChrisL

Hi

I've updated the _sql.au3 file

See here http://www.autoitscript.com/forum/index.php?showtopic=51952

Change this part of your script as follows

$aData = _SQLGetData2D($data)
If NOT @error then 
  _arrayDisplay($aData)
Else
  Msgbox(0,"Error",$SQLErr)
Endif

If there a Zero records @error will be set and $SQLErr will be set to "Query has no data"

Chris

Edited by ChrisL

Share this post


Link to post
Share on other sites
bartekd

Nice, thanks allot Chris. This works like a charm.

Hey one thing, are you from peterborough ontario canada? If so thats weird because that is where I grew up. ^_^

Share this post


Link to post
Share on other sites
ChrisL

Nice, thanks allot Chris. This works like a charm.

Hey one thing, are you from peterborough ontario canada? If so thats weird because that is where I grew up. ^_^

Your welcome! I live in Peterborough in England, just a little bit further away ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×