Request for Access *.mb files

Started by José Roca, August 07, 2016, 03:49:15 AM

Previous topic - Next topic

José Roca

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?

José Roca

#1
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


Knuth Konrad

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 is a versatile free tool for dealing with Access files. And contrary to its name ("Viewer"), it let's you create MDB files also.

David Warner

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

Paul Squires

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).
Paul Squires
PlanetSquires Software

David Warner

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.

José Roca

#6
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.

José Roca

Unfortunately, the lack of native support for BSTRrings forces to have to make copies of the data.

Paul Squires

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.
Paul Squires
PlanetSquires Software