Jump to content

Recommended Posts

Posted

Hello,

I,m connecting to a access mdb, it works fine except when i use a select query and the requested data does not exists, then i get an error.

; Example

Local $dbName = @ScriptDir & "\test.mdb"

$dbCon = ObjCreate("ADODB.Connection") ; Create DataBase connection
$dbCon.Open("Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $dbName)

$sQuery = "select * from sourcefiles where Text='test'"
$result = $dbCon.Execute($sQuery)

MsgBox(0, "", $result.Fields( "ID" ).Value)

If "test" exists in column Text then i get the ID number from column ID

But if it doesn't exist i get an error:

MsgBox(0, "", $result.Fields( "ID" ).Value)
MsgBox(0, "", $result.Fields( "ID" )^ ERROR

If the value "test"does not exist i just want $result to be 0 or ""

Someone an idea?

My scripts: _ConsoleWriteLog | _FileArray2D

 

 

 

Posted

This should do:

Local $dbName = @ScriptDir & "\test.mdb"

$dbCon = ObjCreate("ADODB.Connection") ; Create DataBase connection
$dbCon.Open("Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $dbName)

$sQuery = "select * from sourcefiles where Text='test'"
$result = $dbCon.Execute($sQuery)

If Not $result.EOF Then
    MsgBox(0, "", $result.Fields( "ID" ).Value)
    ; ...
EndIf

I'm not familiar with Access, but typical SQL engine would allow that as well:

$sQuery = "select coalesce(ID, 0) from sourcefiles where Text='test'"
$result = $dbCon.Execute($sQuery)

MsgBox(0, "", $result.Fields(0).Value)

 

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted
  On 10/8/2015 at 8:58 AM, SnArF said:

Someone an idea?

btw.

You should use Com Error Handler with this :
 

ObjEvent()

Look in examples from HelpFile

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Yes but in this case this is not an actual error: it's indeed to be expected that some SELECT returns an empty set. So testing for the resultset being empty seems appropriate here.

Of course it's always a good idea to have a genuine COM error handler setup.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted
  On 10/8/2015 at 11:42 AM, jchd said:

Yes but in this case this is not an actual error: it's indeed to be expected that some SELECT returns an empty set. So testing for the resultset being empty seems appropriate here.

Of course it's always a good idea to have a genuine COM error handler setup.

For this I use "btw."

Sorry for so short help/support but actually I get 100 mail / day  and 50 phone call / day.
I hope my hell will end in next 4 weeks :)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
×
×
  • Create New...