Author Topic: ESENT = Extensible Storage Engine (ESE) Sample  (Read 7199 times)

0 Members and 1 Guest are viewing this topic.

Offline Guenter Fuessner

  • Newbie
  • *
  • Posts: 4
  • User-Rate: +1/-0
ESENT = Extensible Storage Engine (ESE) Sample
« on: August 18, 2012, 05:36:27 PM »
The Extensible Storage Engine (ESE) comes with every Windows since Windows 2000. It is also called ESENT or JetBlue. This is NOT the Access compatible engine JetRed!
ESE is an advanced indexed and sequential access method (ISAM) storage technology for databases of allmost any size from KB to TB.

The following code covers only the basics to give you an idea how to use ESENT. This means connect to ESENT, create a Database, create a Table with 2 columns, fill with some data, retrieve it and close the database.


this is Esent_Test.bas

Code: [Select]

' -----------------------------------------------------------------------------------------------------------------
' Esent_Test.BAS
' Routines to test and use Microsoft Esent.DLL (= Extensible Storage Engine) aka Jet_Blue
' The Extensible Storage Engine (ESE) is an advanced indexed and sequential access method (ISAM) storage technology
' Version 0.1 (YES, there is much room to optimize)
' Esent.inc (c) by José Roca
' Copyright (c) 2012, Günter Füssner
' Portions Copyright (c) Microsoft Corporation
' All Rights Reserved
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' -----------------------------------------------------------------------------------------------------------------


   #IF NOT %DEF(%True)
       %TRUE  = 1
   #ENDIF

   #IF NOT %DEF(%FALSE)
       %FALSE  = 0
   #ENDIF


   %USEMACROS = 1          'use Win32API Macros


'---------------------------------------------------------------------------------------------------------
'  select version to use:
  '%JET_VERSION = &H0501  'Windows XP
   %JET_VERSION = &H0502  'Windows 2003       'I had do do some changes for Esent.INC to get it to work
  '%JET_VERSION = &H0600  'Windows Vista
  '%JET_VERSION = &H0601  'Windows 7
'---------------------------------------------------------------------------------------------------------

   #OPTION   VERSION5
   #OPTION   ANSIAPI
   #REGISTER NONE          'disable automatic assignment of register variables
   #OPTIMIZE SPEED
   #ALIGN 8
   #DIM ALL                'we have to declare all variables
   #UNIQUE VAR ON
   #DEBUG ERROR OFF
   #TOOLS OFF

' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

'============================================================================================================================
   #INCLUDE ONCE "windows.inc"             'José Roca includes      (Vers.: 03.08.2012 00:00)
   #INCLUDE ONCE "Esent.INC"               'include from Jose Roca  (Vers.: 03.08.2012 00:00)  MODIFIED!!! see Esent_Test.INC
   #INCLUDE ONCE "Esent_Test.INC"          'some helper functions and additions to Esent.inc
'============================================================================================================================


    FUNCTION WINMAIN(BYVAL hCurInstance  AS DWORD, _
                     BYVAL hPrevInstance AS DWORD, _
                     BYVAL lpszCmdLine   AS WSTRINGZ PTR, _
                     BYVAL nCmdShow      AS LONG) _
                     AS LONG

        LOCAL I            AS LONG
        LOCAL lResult      AS LONG
        LOCAL DataLen      AS LONG
        LOCAL SessionId    AS DWORD
        LOCAL grbit     AS DWORD
        LOCAL DbId         AS DWORD
        LOCAL TableId      AS DWORD
        LOCAL pvDefault    AS DWORD
        LOCAL cbDefault    AS DWORD
        LOCAL pcbActual AS DWORD
        LOCAL ColumnId     AS DWORD
        LOCAL ColumnId1    AS DWORD
        LOCAL ColumnId2    AS DWORD
        LOCAL lPages       AS DWORD
        LOCAL lDensity     AS DWORD
        LOCAL cbBookmark   AS DWORD
        LOCAL cbData       AS DWORD

        LOCAL qColumnData  AS QUAD
        LOCAL pvBookmark   AS QUAD

        LOCAL ColumnData$
        LOCAL RecBuf$

        LOCAL ColBuf       AS ASCIIZ * 1024
        LOCAL szColumnName AS ASCIIZ * 32
        LOCAL szTableName  AS ASCIIZ * 32
        LOCAL szUserName   AS ASCIIZ * 32
        LOCAL szPassword   AS ASCIIZ * 32
        LOCAL szFilename   AS ASCIIZ * %MAX_PATH
        LOCAL szConnect    AS ASCIIZ * %MAX_PATH

        LOCAL FT           AS FileTime
        LOCAL ColumnDef    AS JET_COLUMNDEF


        CON.SCREEN   = 32, 100
        CON.CAPTION$ = "ESENT-Test"

         '----------------------------------------------------------------------------------------------------

       #IF %DEF(%UNICODE)
        PRINT "%DEF(%UNICODE): %TRUE " & STR$(%UNICODE)
       #ELSE
        PRINT "%DEF(%UNICODE): %FALSE"
       #ENDIF

        PRINT "JET_VERSION: 0x" & HEX$(%JET_VERSION, 4)

       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'init the connection to esent.dll

        lResult = InitEsent(ghESE_Instance)   'create Instance to Esent and do Init
        PRINT "InitEsent  lResult:" & STR$(lResult) & "  ghESE_Instance: 0x" & HEX$(ghESE_Instance, 8)
       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'start Session

        szUserName = ""
        szPassword = ""
        grbit = 0     'this flag is reserved and setting it has no effect
        lResult = JetBeginSession(ghESE_Instance, SessionId, szUserName, szPassword)
        PRINT "JetBeginSession  lResult:" & STR$(lResult)
        PRINT "JetBeginSession  SessionId:" & HEX$(SessionId, 8)
       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

       'now let's do something ...

       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'create a database
        szFilename = "TestData.ese"              'The name of the database to be created
        szConnect  = ""                          'Reserved for future use. Set to NULL
        DbId       = 0                           'Pointer to a buffer that, on a successful call, contains the
                                                 'identifier of the database. On failure, the value is undefined
        grbit      = %JET_bitDbOverwriteExisting 'By default, if JetCreateDatabase is called and the database
                                                 'already exists, the API call will fail and the original database
                                                 'will not be overwritten. JET_bitDbOverwriteExisting changes this
                                                 'behavior, and the old database will be overwritten with a new one.
                                                 '(Windows XP and later)

        lResult = JetCreateDataBase(SessionId, szFilename, szConnect, DbId, grbit)
        PRINT "JetCreateDataBase  lResult:" & STR$(lResult) & "  DbId: " & HEX$(DbId, 8)
       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'start a transaction for our session
        lResult = JetBeginTransaction(SessionId)
        PRINT "JetBeginTransaction  lResult:" & STR$(lResult)
       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'create a table
        lPages      = 8            'The initial number of database pages to allocate for the table. Specifying a
                                   'number larger than one can reduce fragmentation if many rows are inserted into
                                   'this table
        lDensity    = 80           'The table density, in percentage points. The number must be either 0 or in the
                                   'range of 20 through 100. Passing 0 means that the default value should be used.
                                   'The default is 80
        TableId     = 0            'On success, the table identifier is returned in this field. The value is undefined
                                   'if the API does not return JET_errSuccess
        szTableName = "Table1"     'The name of the index to create

        lResult = JetCreateTable(SessionId, DbId, szTableName, lPages, lDensity, TableId)
        PRINT "JetCreateTable  lResult:" & STR$(lResult) & "  TableId: " & HEX$(TableId, 8)
       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'add Column1 to our new table
        ColumnDef.cbStruct = SIZEOF(ColumnDef)  'The size of the structure in bytes. It must be set to sizeof( JET_COLUMNDEF)
        ColumnDef.ColumnId = 0                  'Reserved. columnid must be set to 0 (zero)
        ColumnDef.ColTyp   = %JET_coltypText    'The type of the column (for example, text, binary, or numerical).
        ColumnDef.wCountry = 0                  'Reserved. wCountry must be set to 0 (zero)
        ColumnDef.LangId   = 0                  'Obsolete. langid should be set to 0 (zero)
        ColumnDef.cp       = 0                  'The code page for the column. The only valid values for text columns are
                                                'English (1252) and Unicode (1200). A value of zero means the default will
                                                'be used (English, 1252). If the column is not a text column, the code page
                                                'automatically gets set to zero
        ColumnDef.wCollate = 0                  'Reserved. wCollate must be set to 0 (zero)
        ColumnDef.cbMax    = 255                'The maximum length, in bytes, of a variable-length column, or the length of
                                                'a fixed-length column
        ColumnDef.grBit    = 0                  'A group of bits that contain the options to be used for this call

        szColumnName       = "Column1"
        pvDefault          = 0
        cbDefault          = 0
        ColumnId1          = 0

        lResult = JetAddColumn(SessionId, TableId, szColumnName, ColumnDef, BYVAL pvDefault, cbDefault, ColumnId1)
        PRINT "JetAddColumn1  lResult:" & STR$(lResult) & "  ColumnId:" & HEX$(ColumnId1, 8)
       '- - - - - - - - - - - - - - - - - - - -
       'add Column1 to our new table
        ColumnDef.cbStruct = SIZEOF(ColumnDef)  'The size of the structure in bytes. It must be set to sizeof( JET_COLUMNDEF)
        ColumnDef.ColumnId = 0                  'Reserved. columnid must be set to 0 (zero)
        ColumnDef.ColTyp   = %JET_coltypCurrency'The type of the column (for example, text, binary, or numerical).
        ColumnDef.wCountry = 0                  'Reserved. wCountry must be set to 0 (zero)
        ColumnDef.LangId   = 0                  'Obsolete. langid should be set to 0 (zero)
        ColumnDef.cp       = 0                  'The code page for the column. The only valid values for text columns are
                                                'English (1252) and Unicode (1200). A value of zero means the default will
                                                'be used (English, 1252). If the column is not a text column, the code page
                                                'automatically gets set to zero
        ColumnDef.wCollate = 0                  'Reserved. wCollate must be set to 0 (zero)
        ColumnDef.cbMax    = 8                  'The maximum length, in bytes, of a variable-length column, or the length of
                                                'a fixed-length column
        ColumnDef.grBit    = 0                  'A group of bits that contain the options to be used for this call

        szColumnName       = "Column2"
        pvDefault          = 0
        cbDefault          = 0
        ColumnId2          = 0
        pvDefault          = 0

        lResult = JetAddColumn(SessionId, TableId, szColumnName, ColumnDef, BYVAL pvDefault, cbDefault, ColumnId2)
        PRINT "JetAddColumn2  lResult:" & STR$(lResult) & "  ColumnId:" & HEX$(ColumnId2, 8)
       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'commit transaction for our session

        grbit   = %JET_bitCommitLazyFlush       'The transaction is committed normally but this API does not wait
                                                'for the transaction to be flushed to the transaction log file
                                                'before returning to the caller. This drastically reduces the
                                                'duration of a commit operation at the cost of durability.
        lResult = JetCommitTransaction(SessionId, grbit)
        PRINT "JetCommitTransaction  lResult:" & STR$(lResult)
       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'prepare to insert a record:

       'start a transaction for our session
        lResult = JetBeginTransaction(SessionId)
        PRINT "JetBeginTransaction  lResult:" & STR$(lResult)

       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'insert 10 records with two columns filled:

        FOR I = 1 TO 10
             lResult = JetPrepareUpdate(SessionId, TableId, %JET_prepInsert)
             IF lResult <> %JET_errSuccess THEN PRINT "JetPrepareUpdate  lResult:" & STR$(lResult)

             ColBuf       = "ColData " & HEX$(RND(1, 20000000), 8)  & CHR$(0)
             DataLen      = LEN(ColBuf)
             lResult      = JetSetColumn(SessionId, TableId, ColumnId1, ColBuf, DataLen, 0, BYVAL 0)
             IF lResult <> %JET_errSuccess THEN PRINT "JetSetColumn  ColumnId1 lResult:" & STR$(lResult)

             GetSystemTimeAsFileTime FT
             FileTimeToLocalFileTime FT, FT
             DataLen      = SIZEOF(FT)
             lResult      = JetSetColumn(SessionId, TableId, ColumnId2, FT, DataLen, 0, BYVAL 0)
             IF lResult <> %JET_errSuccess THEN PRINT "JetSetColumn  ColumnId2 lResult:" & STR$(lResult)

             pvBookmark   = 0                    'Pointer to a returned bookmark for an inserted row
             cbBookmark   = SIZEOF(pvBookmark)   'Size of the buffer pointed to by pvBookmark
             pcbActual    = 0                    'The returned size of the bookmark for the inserted row returned in pvBookmark

             lResult      = JetUpdate(SessionId, TableId, pvBookmark, cbBookmark, pcbActual)
             PRINT "JetUpdate  lResult:" & STR$(lResult) & "  pcbActual:" & STR$(pcbActual) & "  pvBookmark: " & HEX$(pvBookmark, pcbActual * 2)
        NEXT I

       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'commit transaction for our session and do the insert

        grbit   = %JET_bitCommitLazyFlush       'The transaction is committed normally but this API does not wait
                                                'for the transaction to be flushed to the transaction log file
                                                'before returning to the caller. This drastically reduces the
                                                'duration of a commit operation at the cost of durability.
        lResult = JetCommitTransaction(SessionId, grbit)
        PRINT "JetCommitTransaction  lResult:" & STR$(lResult)
       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'retrieve all records and columns

        I = 0
        lResult = JetMove(SessionId, TableId, %JET_MoveFirst, 0)
        PRINT "JetMove %JET_MoveFirst  lResult:" & STR$(lResult)

        DO
        INCR I

       'ColBuf    = STRING$(1024, 0)
        ColBuf    = ""                          'the output buffer that receives the column value
        cbData    = SIZEOF(ColBuf)              'the maximum size, in bytes, of the output buffer
        pcbActual = 0                           'receives the actual size, in bytes, of the column value
        grBit     = 0                           'group of bits that contain the options to be used for this call
       'pretInfo AS JET_RETINFO                 'if pretInfo is give as NULL then the function behaves as though
                                                'an itagSequence of 1 and an ibLongValue of 0 (zero) were given.
                                                'this causes column retrieval to retrieve the first value of a
                                                'multi-valued column, and to retrieve long data at offset 0 (zero).
        lResult = JetRetrieveColumn(SessionId, TableId, ColumnId1, ColBuf, cbData, pcbActual, grBit, BYVAL 0)
        IF lResult <> %JET_errSuccess THEN PRINT "JetRetrieveColumn1  lResult:" & STR$(lResult)


        FT.qDateTime = 0                        'the output buffer that receives the column value
        cbData       = SIZEOF(FT)               'the maximum size, in bytes, of the output buffer
        pcbActual    = 0                        'receives the actual size, in bytes, of the column value
        grBit        = 0                        'group of bits that contain the options to be used for this call
       'pretInfo AS JET_RETINFO                 'if pretInfo is give as NULL then the function behaves as though
                                                'an itagSequence of 1 and an ibLongValue of 0 (zero) were given.
                                                'this causes column retrieval to retrieve the first value of a
                                                'multi-valued column, and to retrieve long data at offset 0 (zero).
        lResult = JetRetrieveColumn(SessionId, TableId, ColumnId2, FT, cbData, pcbActual, grBit, BYVAL 0)
        IF lResult <> %JET_errSuccess THEN PRINT "JetRetrieveColumn2  lResult:" & STR$(lResult)

       'show result
        RecBuf$ = DEC$(I, -3) & ". " & RTRIM$(ColBuf, ANY $WHITESPACE) & "  " & FileTimeToLocal$(FT)
        PRINT RecBuf$

        lResult = JetMove(SessionId, TableId, %JET_MoveNext, 0)
        IF lResult <> %JET_errSuccess THEN PRINT "I:" & DEC$(I, -3) & "  JetMove %JET_MoveNext  lResult:" & STR$(lResult)

        IF lResult <> %JET_errSuccess THEN
           EXIT DO
        END IF

        LOOP

       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       'end session and instance

        grbit = 0    'this flag is reserved and setting it has no effect
        lResult = JetEndSession(SessionId, grbit)
        PRINT "JetEndSession SessionId  lResult:" & STR$(lResult)

        lResult = JetTerm(ghESE_Instance)
        PRINT "JetTerm  lResult:" & STR$(lResult)

       '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        PRINT : PRINT "press any key to close window ..."
        WAITKEY$


    END FUNCTION

'========================================================================================================================================

'init Esent for use by our code

 FUNCTION InitEsent(ESE_Instance AS DWORD) AS LONG

    LOCAL lResult        AS LONG

    LOCAL grbit          AS DWORD                        ' __in JET_GRBIT grbit
    LOCAL pinstance      AS DWORD                       ' __inout_opt JET_INSTANCE* pinstance
    LOCAL sesid          AS DWORD                       ' __in JET_SESID sesid
    LOCAL paramid        AS DWORD                       ' __in unsigned long paramid
    LOCAL lParam         AS DWORD                       ' __in JET_API_PTR lParam

    LOCAL szInstanceName AS ASCIIZ * 32              ' __in_opt JET_PCSTR szInstanceName
    LOCAL szDisplayName  AS ASCIIZ * 32              ' __in_opt JET_PCSTR szDisplayName
    LOCAL szParam        AS ASCIIZ * 32                 ' __in_opt JET_PCSTR szParam

    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   'create instance
    szInstanceName = "ESENTTest"
    szDisplayName  = "ESENT (first Test)"
    grbit          = 0                                  'for future use

    lResult = JetCreateInstance2(ESE_Instance, szInstanceName, szDisplayName, grbit) 'returns JET_ERR
    IF lResult = %JET_errSuccess THEN
      'Function = %TRUE
    ELSE
       PRINT "Error JetCreateInstance2:" & STR$(lResult)
       FUNCTION = %FALSE
       EXIT FUNCTION
    END IF
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    'init some parameters
     lParam  = 0
    szParam = ""

    lResult = JetSetSystemParameter(ESE_Instance, %JET_sesidNil, %JET_paramMaxOpenTables,    5000, szParam)  'default  300
    IF lResult <> %JET_errSuccess THEN
       PRINT "Error  JetSetSystemParameter:  %JET_paramMaxOpenTables" & STR$(lResult)
    END IF
    lResult = JetSetSystemParameter(ESE_Instance, %JET_sesidNil, %JET_paramMaxSessions,       256, szParam)  'default   16
    IF lResult <> %JET_errSuccess THEN
       PRINT "Error  JetSetSystemParameter:  %JET_paramMaxSessions  " & STR$(lResult)
    END IF
    lResult = JetSetSystemParameter(ESE_Instance, %JET_sesidNil, %JET_paramCircularLog,         1, szParam)  'default    0
    IF lResult <> %JET_errSuccess THEN
       PRINT "Error  JetSetSystemParameter:  %JET_paramCircularLog  " & STR$(lResult)
    END IF
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    'try to init instance and do cleanup if needed

    grbit = %JET_bitTruncateLogsAfterRecovery _   'On successful soft recovery, truncate log files.
         OR %JET_bitReplayMissingMapEntryDB    'Missing database map entry default to same location.

    lResult = JetInit2(ESE_Instance, grbit)
    IF lResult <> %JET_errSuccess THEN
       PRINT "Error  JetInit2:" & STR$(lResult)
    END IF

    FUNCTION = lResult

 END FUNCTION

'========================================================================================================================================




this is Esent_Test.inc


Code: [Select]

'-----------------------------------------------------------------------------------------------------------------
'Esent_Test.INC
'Test-Routines to test and use Microsoft Esent.DLL (= Extensible Storage Engine) aka Jet_Blue
'Version 0.1
'Copyright 2012, Günter Füssner
'All Rights Reserved
'-----------------------------------------------------------------------------------------------------------------

GLOBAL ghESE_Instance        AS DWORD

'-----------------------------------------------------------------------------------------------------------------
#IF 0

'#################################################################################################################
'the following additions to José Roca Esent.inc have been made because at least with Windows 2003 & Windows XP
'are these definitions missing. The problem is, as I see it, identical with the original microsoft esent.h.
'Thank you José for your excellent work!
'#################################################################################################################

#IF %JET_VERSION < &H0600

 %JET_bitTruncateLogsAfterRecovery  = &H00000010???  ' //   on successful soft recovery, truncate log files
 %JET_bitReplayMissingMapEntryDB    = &H00000020???  ' /* missing database map entry default to same location */


' // Size = 48 bytes
TYPE JET_TABLECREATE_A DWORD
   cbStruct            AS DWORD                  ' unsigned long        // size of this structure (for future expansion)
   szTableName         AS ASCIIZ PTR             ' char *               // name of table to create.
   szTemplateTableName AS ASCIIZ PTR             ' char *               // name of table from which to inherit base DDL
   ulPages             AS DWORD                  ' unsigned long        // initial pages to allocate for table.
   ulDensity           AS DWORD                  ' unsigned long        // table density.
   rgcolumncreate      AS JET_COLUMNCREATE_A PTR ' JET_COLUMNCREATE_A * // array of column creation info
   cColumns            AS DWORD                  ' unsigned long        // number of columns to create
   rgindexcreate       AS JET_INDEXCREATE_A  PTR ' JET_INDEXCREATE_A *  // array of index creation info
   cIndexes            AS DWORD                  ' unsigned long        // number of indexes to create
   grbit               AS DWORD                  ' JET_GRBIT
   tableid             AS DWORD                  ' JET_TABLEID          // returned tableid.
   cCreated            AS DWORD                  ' unsigned long        // count of objects created (columns+table+indexes).
END TYPE

' // Size = 48 bytes
TYPE JET_TABLECREATE_W DWORD
   cbStruct            AS DWORD                  ' unsigned long        // size of this structure (for future expansion)
   szTableName         AS WSTRINGZ PTR           ' WCHAR *              // name of table to create.
   szTemplateTableName AS WSTRINGZ PTR           ' WCHAR *              // name of table from which to inherit base DDL
   ulPages             AS DWORD                  ' unsigned long        // initial pages to allocate for table.
   ulDensity           AS DWORD                  ' unsigned long        // table density.
   rgcolumncreate      AS JET_COLUMNCREATE_W PTR ' JET_COLUMNCREATE_W * // array of column creation info
   cColumns            AS DWORD                  ' unsigned long        // number of columns to create
   rgindexcreate       AS JET_INDEXCREATE_W  PTR ' JET_INDEXCREATE_W *  // array of index creation info
   cIndexes            AS DWORD                  ' unsigned long        // number of indexes to create
   grbit               AS DWORD                  ' JET_GRBIT
   tableid             AS DWORD                  ' JET_TABLEID          // returned tableid.
   cCreated            AS DWORD                  ' unsigned long        // count of objects created (columns+table+indexes).
END TYPE

#IF %DEF(%UNICODE)
   MACRO JET_TABLECREATE = JET_TABLECREATE_W
#ELSE
   MACRO JET_TABLECREATE = JET_TABLECREATE_A
#ENDIF

' ========================================================================================
' The JetBeginSession function starts a session and initializes and returns an ESE
' session handle (JET_SESID). Sessions control all access to the database and are used
' to control the scope of transactions. The session can be used to begin, commit, or
' abort transactions. The session is also used to attach, create, or open a database.
' The session is used as the context for all DDL and DML operations. To increase
' concurrency and parallel access to the database, multiple sessions can be begun.
' Requires Windows Vista, Windows XP, or Windows 2000 Professional.
' ========================================================================================
DECLARE FUNCTION JetBeginSession IMPORT "ESENT.DLL" ALIAS "JetBeginSession" ( _
   BYVAL instance  AS DWORD _                           ' __in JET_INSTANCE instance
 , BYREF psesid    AS DWORD  _                          ' __out JET_SESID* psesid       (BYVAL results in exeption error)
 , BYREF szUserName AS ASCIIZ _                         ' __in_opt JET_PCSTR szUserName (This parameter is reserved, set to "")
 , BYREF szPassword AS ASCIIZ _                         ' __in_opt JET_PCSTR szPassword (This parameter is reserved, set to "")
 ) AS LONG                                              ' JET_ERR
' ========================================================================================
#ENDIF

#ENDIF   'end of modifications to esent.inc

'------------------------------------------------------------------------------------------------------------------------------

' Format a time and date to the current locale, return as a string.

FUNCTION TimeDate_FormatToLocal$(OPTIONAL BYVAL st AS SYSTEMTIME)

 'if year = 0 on entry, get current systemtime and convert to local string

  LOCAL szTime AS ASCIIZ * 128, szDate AS ASCIIZ * 128

 'Get current if none specified...
  IF st.wYear = 0 THEN GetLocalTime st

 'Format to locale...
  GetTimeFormat %LOCALE_USER_DEFAULT, 0, st, "", szTime, SIZEOF(szTime)
  GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, st, "", szDate, SIZEOF(szDate)

 'Return it...
  FUNCTION = szDate + ", " + szTime

END FUNCTION

'------------------------------------------------------------------------------------------------------------------------------
' Format Filetime to the current locale, return as a string.

FUNCTION FileTimeToLocal$(OPTIONAL BYVAL Ft AS FileTime  )

 'if year = 0 on entry, get current systemtime and convert to local string

  LOCAL St AS SYSTEMTIME
  LOCAL szTime AS ASCIIZ * 128, szDate AS ASCIIZ * 128

  IF Ft.qDateTime = 0 THEN
     GetLocalTime St      'Get current if none specified...
  ELSE
     FileTimeToSystemTime Ft, St
  END IF

  IF st.wYear = 0 THEN GetLocalTime st

 'Format to locale...
  GetTimeFormat %LOCALE_USER_DEFAULT, 0, st, "", szTime, SIZEOF(szTime)
  GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, st, "", szDate, SIZEOF(szDate)

 'Return it...
  FUNCTION = szDate + ", " + szTime

END FUNCTION

'------------------------------------------------------------------------------------------------------------------------------



attached is a esent.inc with modifications in a very few places (see Esent_Test.inc)
« Last Edit: August 18, 2012, 10:12:44 PM by Guenter Fuessner »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: ESENT = Extensible Storage Engine (ESE) Sample
« Reply #1 on: August 18, 2012, 06:23:14 PM »
Ok, I have removed the condition for these couple of equates and structures. Thanks for posting the example.
« Last Edit: October 18, 2012, 08:09:56 AM by Theo Gottwald »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: ESENT = Extensible Storage Engine (ESE) Sample
« Reply #2 on: October 15, 2012, 06:33:58 PM »
The declare for JetOpenTempTable3 must be changed to:

Code: [Select]
DECLARE FUNCTION JetOpenTempTable3 IMPORT "ESENT.DLL" ALIAS "JetOpenTempTable3" ( _
   BYVAL sesid AS DWORD _                               ' __in JET_SESID sesid
 , BYREF prgcolumndef AS JET_COLUMNDEF _                ' __in const JET_COLUMNDEF* prgcolumndef
 , BYVAL ccolumn AS DWORD _                             ' __in unsigned long ccolumn
 , BYREF pidxunicode AS JET_UNICODEINDEX _              ' __in_opt JET_UNICODEINDEX* pidxunicode
 , BYVAL grbit AS DWORD _                               ' __in JET_GRBIT grbit
 , BYREF ptableid AS DWORD _                            ' __out JET_TABLEID* ptableid
 , BYREF prgcolumnid AS DWORD _                         ' __out JET_COLUMNID* prgcolumnid
 ) AS LONG                                              ' JET_ERR