PlanetSquires Forums

Support Forums => General Board => Topic started by: José Roca on August 07, 2016, 03:49:15 AM

Title: Request for Access *.mb files
Post by: José Roca on August 07, 2016, 03:49:15 AM
I would like to write a class to wrap ODBC, but I only can test it in 32 bit because I don't have versions of biblio.mdb and northwind.mdb in 64 bit. Anybody has Access 32 and 64 bit *.mdb files to test?
Title: Re: Request for Access *.mb files
Post by: José Roca on August 07, 2016, 06:01:02 AM
An small test:


'#define unicode
'#define _CODBC_DEBUG_ 1
#include once "Afx/COdbc/COdbc.inc"
USING Afx
' // Connect with the database
DIM wszConStr AS WSTRING * 260 = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=biblio.mdb"
DIM pDbc AS CODBC = wszConStr

' // Allocate an statement object
DIM pStmt AS COdbcStmt PTR = NEW COdbcStmt(@pDbc)
IF pStmt THEN
   ' // Generate a result set
   pStmt->ExecDirect ("SELECT TOP 20 * FROM Authors ORDER BY Author")
   ' // Parse the result set
   DIM cwsOutput AS CWSTR
   DO
      ' // Fetch the record
      IF pStmt->Fetch = FALSE THEN EXIT DO
      ' // Get the values of the columns and display them
      cwsOutput = ""
      cwsOutput += pStmt->GetData(1) & " "
      cwsOutput += pStmt->GetData(2) & " "
      cwsOutput += pStmt->GetData(3)
      PRINT cwsOutput
   LOOP
   Delete pStmt
END IF

PRINT
PRINT "Press any key..."
SLEEP

Title: Re: Request for Access *.mb files
Post by: Knuth Konrad on October 07, 2016, 10:59:08 AM
Quote from: Jose Roca on August 07, 2016, 03:49:15 AM
I would like to write a class to wrap ODBC, but I only can test it in 32 bit because I don't have versions of biblio.mdb and northwind.mdb in 64 bit. Anybody has Access 32 and 64 bit *.mdb files to test?

A bit late, but nontheless: I'm pretty sure there isn't a difference of a *.mdb file created with a 32 or 64 bit version of Access.

There is however a new Access file format: *.accdb. Never used that one, though.

BTW, MDB Viewer (http://www.alexnolan.net/software/mdb_viewer_plus.htm) is a versatile free tool for dealing with Access files. And contrary to its name ("Viewer"), it let's you create MDB files also.
Title: Re: Request for Access *.mb files
Post by: David Warner on February 10, 2017, 10:32:09 AM
Hi Jose,

I'm just taking a look at your ODBC class and my first impression is... Wow, that's amazing!
Thank you.

Cheers,

David
Title: Re: Request for Access *.mb files
Post by: Paul Squires on February 10, 2017, 12:43:47 PM
Quote from: David Warner on February 10, 2017, 10:32:09 AM
Hi Jose,

I'm just taking a look at your ODBC class and my first impression is... Wow, that's amazing!
Thank you.

Cheers,

David

I agree 100%. The work that Jose has done with the FB classes is incredible. Only last weekend I was having trouble with some file input/output so I switched to using Jose's CTextStream class and it worked perfectly (and it is syntactically more pleasing to deal with).
Title: Re: Request for Access *.mb files
Post by: David Warner on February 10, 2017, 01:03:30 PM
Jose’s CWindow framework truly is an amazing coding resource containing lots of interesting and useful items. There is a great deal of information to take in and I think we are fortunate indeed to have received such a generously given gift.
Title: Re: Request for Access *.mb files
Post by: José Roca on February 10, 2017, 01:21:42 PM
Thanks very much.

@Paul,

If you're using CTextStream, I have modified two of the methods: Read and ReadLine.


' ========================================================================================
' Reads a specified number of characters from a TextStream file and returns the resulting string.
' After a file is initially opened and before anything is written, Line is equal to 1.
' ========================================================================================
PRIVATE FUNCTION CTextStream.Read (BYVAL numChars AS LONG) AS CWSTR
   DIM bstrText AS AFX_BSTR
   IF m_pTxtStm THEN SetResult(m_pTxtStm->Read(numChars, @bstrText))
   DIM cwsText AS CWSTR = *bstrText
   SysFreeString bstrText
   RETURN cwsText
END FUNCTION
' ========================================================================================

' ========================================================================================
' Reads an entire line (up to, but not including, the newline character) from a TextStream
' file and returns the resulting string.
' ========================================================================================
PRIVATE FUNCTION CTextStream.ReadLine () AS CWSTR
   DIM bstrText AS AFX_BSTR
   IF m_pTxtStm THEN SetResult(m_pTxtStm->ReadLine(@bstrText))
   DIM cwsText AS CWSTR = *bstrText
   SysFreeString bstrText
   RETURN cwsText
END FUNCTION
' ========================================================================================


Previously the code used was:


DIM cwsText AS CWSTR = SysallocString(*bstrText)


Instead of


DIM cwsText AS CWSTR = *bstrText
[(code]

Because the original version returned a CBSTR instead of a CWSTR.
Title: Re: Request for Access *.mb files
Post by: José Roca on February 10, 2017, 01:40:54 PM
Unfortunately, the lack of native support for BSTRrings forces to have to make copies of the data.
Title: Re: Request for Access *.mb files
Post by: Paul Squires on February 10, 2017, 04:56:10 PM
Thanks Jose, I only used the class to write/output files. I didn't need to read them at the time. Thanks for letting me know that you've change the code.