The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: psylem on July 26, 2005, 02:31:51 AM

Title: ODBC
Post by: 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.
Title: Re: ODBC
Post by: Biterider on July 26, 2005, 05:50:52 AM
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
Title: Re: ODBC
Post by: Porkster on July 29, 2005, 02:32:29 AM
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.

.
Title: Re: ODBC
Post by: wormz on September 17, 2007, 03:02:29 PM
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?
Title: Re: ODBC
Post by: ToutEnMasm on September 17, 2007, 06:58:12 PM
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
Title: Re: ODBC
Post by: jdoe on September 19, 2007, 03:38:53 AM
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.

Title: Re: ODBC
Post by: wormz on September 19, 2007, 07:51:52 AM
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
Title: Re: ODBC
Post by: Vortex on September 19, 2007, 04:52:07 PM
Iczelion's ODBC Tutorial set :

http://win32assembly.online.fr/tutorials.html
Title: Re: ODBC
Post by: jdoe on September 19, 2007, 07:18:48 PM
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



Title: Re: ODBC
Post by: P1 on September 19, 2007, 10:24:20 PM
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)
Title: Re: ODBC
Post by: jdoe on September 19, 2007, 11:10:50 PM
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.

Title: Re: ODBC
Post by: jdoe on September 20, 2007, 01:36:44 AM
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:

Title: Re: ODBC
Post by: Mark Jones on September 23, 2007, 04:51:44 PM
Here is a thread (http://www.masm32.com/board/index.php?topic=1891.msg58065#msg58065) 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