News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ODBC

Started by psylem, July 26, 2005, 02:31:51 AM

Previous topic - Next topic

psylem

Has anyone tried to access a database using assembler? Haven't seen anything about that anywhere. I'm trying to write a DLL that calls stored procedures in an oracle DB.

Biterider

Hi psylem
One of the projects that comes with the ObjAsm32 package is an OleDB application.
The project shows all necessary access types you need using ODBC.

Regards,

Biterider

Porkster

It just happens I'm about to do some odbc code myself.

In the last couple of day I've been doing some VBA business scripts by request, and I knew nothing about Excel's VBA.  I jumped into a crash course in VBA and done the scripts/programs in a couple of days.   Now that I've finished them I've been thinking of making the scripts/ algorithms more commercial by putting them into a UI, due to there need for small business.

What I need to do is access Excel and Quickbook data files.

As far as I remember the concept of using ODBC is talking to the ODBC manager which then does tasks.  The requests are in SQL I think and you set up the access interface with assembly or c++ or what ever.

Iczelion has a assembly tutor on ODBC.

.

wormz

Hi... sorry for digging up such an old post but this thread is most related to what i am trying to do with ODBC. Following Iczelion's tutorial, I managed to connect to an Access database and managed to retrieve the correct results when i use the following connection string:

SELECT * FROM tablename WHERE column1 = ? AND column2 = ?

However a SQL_ERROR gets thrown when i use the following string:

SELECT * FROM tablename WHERE column1 = ? AND column2 LIKE ?%

Any ideas on where i had gone wrong?

ToutEnMasm

#4
Hello,
best method to do this is using ACCESS.

Do the work with access.Then acces is abble to translate it in SQL langage without ...errors

jdoe

Quote from: wormz on September 17, 2007, 03:02:29 PM
...managed to retrieve the correct results when i use the following connection string:

SELECT * FROM tablename WHERE column1 = ? AND column2 = ?

However a SQL_ERROR gets thrown when i use the following string:

SELECT * FROM tablename WHERE column1 = ? AND column2 LIKE ?%

Any ideas on where i had gone wrong?

wormz,

Both syntaxes seem incorrect for me. I can help you but I need to know what data type is in column1 and column2 and what data you need to retrieve because "column1 = ?" is weird and "column2 LIKE ?%" even more. Looks like it is string data and you are searching for "?" in column1 and you are searching for "?" as first character in column2.

Tell me more.


wormz

Quote from: jdoe on September 19, 2007, 03:38:53 AM
wormz,

Both syntaxes seem incorrect for me. I can help you but I need to know what data type is in column1 and column2 and what data you need to retrieve because "column1 = ?" is weird and "column2 LIKE ?%" even more. Looks like it is string data and you are searching for "?" in column1 and you are searching for "?" as first character in column2.

Tell me more.



Yes column1 is called "Diploma" and column2 is called "Seat". Both contains string data. The table name is "main". A typical record in the table looks like this:

NameDiplomaSeat
JohnDIOMW2.01.06

I am trying to retrieve the names of people belonging to a particular diploma and sitting in a particular area (denoted by the first 2 letters in the "Seat" field). Hence i am using the "LIKE" condition instead of "=" to search the first 2 letters.

Below are excerpts from my code:

SQLStatement    db "SELECT * FROM main WHERE Diploma=? AND Seat LIKE ?% ", 0

INVOKE SQLBindParameter, hStmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 25, 0, ADDR Dip, 25, ADDR DipLength
INVOKE SQLBindParameter, hStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 25, 0, ADDR Pod, 25, ADDR PodLength

INVOKE SQLPrepare, hStmt, addr Conn, sizeof Conn

; retrieving user input from Combobox for search terms

INVOKE  SendMessage, hDipCombo, CB_GETCURSEL, 0, 0
MOV      EDX, EAX
INVOKE  SendMessage, hDipCombo, CB_GETLBTEXT, EDX, ADDR Dip
INVOKE  lstrlen, ADDR Dip
MOV       PodLength, EAX

INVOKE  SendMessage, hPodCombo, CB_GETCURSEL, 0, 0
MOV      EDX, EAX
INVOKE  SendMessage, hPodCombo, CB_GETLBTEXT, EDX, ADDR Pod
INVOKE  lstrlen, ADDR Pod
MOV       PodLength, EAX

INVOKE SQLExecute, hStmt

Vortex


jdoe

Quote from: wormz on September 19, 2007, 07:51:52 AM

SQLStatement    db "SELECT * FROM main WHERE Diploma=? AND Seat LIKE ?% ", 0


wormz,

You seem to do it the right way. Before anything else, I would recommend to try the same SQLStatement and replacing % with *
LIKE % is the Oracle syntax and not the Access one. Try the following...


Quote

SQLStatement    db "SELECT * FROM main WHERE Diploma=? AND Seat LIKE ?* ", 0




P1

Transact SQL of Microsoft require proper syntax for executing the SQL statement.

"WHERE LastName Like '[A-D]*';"  the Like clause is treat as string literal.  Though, I believe the terminating semi-colon is optional.

I do know that the question marks are not part of a properly format SQL statement.  So build your SQL statement string properly with data literals or parameters and pass it to be executed.

Regards,  P1   :8)

jdoe

Quote from: P1 on September 19, 2007, 10:24:20 PM

"WHERE LastName Like '[A-D]*';"  the Like clause is treat as string literal.  Though, I believe the terminating semi-colon is optional.

I do know that the question marks are not part of a properly format SQL statement.  So build your SQL statement string properly with data literals or parameters and pass it to be executed.


P1,

You are right about putting strings between quotes but, without being 100% sure, if there is no spaces in the search string, Access will not throw an error.

About question mark you are half right/wrong. There is few differences between databases that use (custom) SQL language and with Access, which is what wormz is using, question marks are used to replace an unknown character. It could possibly create problems to use question marks in an Access WHERE clause because it is also used by the SQLBindParameter function as a parameter identifier.


jdoe

Quote from: psylem on July 26, 2005, 02:31:51 AM
Has anyone tried to access a database using assembler? Haven't seen anything about that anywhere. I'm trying to write a DLL that calls stored procedures in an oracle DB.

psylem,

I could be wrong here but for calling a stored procedure, you need the Oracle Client, Oracle Developer or PL/SQL Developer installed on your system and the ODBC tutorial won't help you much for what you are trying to do. I don't think an ODBC driver have enough functionalities for accessing an Oracle package.

:snooty:


Mark Jones

Here is a thread with the latest SQLite .dll, .inc, and .lib. Also included is a testbed app, fully commented, showing how to use most features of SQLite. Check it out. :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08