Skip to content

DF_FILE_OPEN_MODE

See Also: Get_Attribute, Set_Attribute

The mode in which the table was opened.

Level

Table

Supported by

All Drivers

Type

Enumeration list, temporary

Access

Read Only

Values

  • DF_SHARE
  • DF_EXCLUSIVE

Remarks

The DF_FILE_OPEN_MODE attribute retrieves the mode with which a table was opened. The DF_EXCLUSIVE mode signifies that a table has been opened in exclusive mode. The DF_SHARE mode is the normal file mode allowing multiple processes to access the table.

This attribute cannot be set directly; it reflects the way a table was opened by the open command. Below is a code fragment that opens table MyExclusive exclusively and table MyShared in shared mode:

Open MyExclusive Mode DF_EXCLUSIVE
Open MyShared

Note that in order to open a table in shared mode, you do not need to specify an open mode. When the open mode is not explicitly specified, DF_SHARED is assumed. To open a table in shared mode, one could also use the code below:

Open MyShared Mode DF_SHARED

The Embedded Database and Pervasive.SQL support opening tables in exclusive mode. If a process attempts to open a table (either shared or exclusive) that is already opened exclusively by some other process, an error will be generated: DFERR_FILE_ACCESS_VIOLATION. If a process attempts to open a table in exclusive mode that is already opened in shared mode by some other process, the DFERR_FILE_ACCESS_VIOLATION will also be generated.

In the SQL environment used by the DataFlex SQL Drivers, there is no such concept as opening a table; therefore, there is also no such concept as opening a table exclusively or shared. The attribute is supported and will correctly reflect the mode used in the open command. If a process attempts to open a (SQL Based) table that is already opened exclusively by some other process, no error will be generated, and the attempt succeeds.

The Structure_Start and Sort commands require the table to be opened in exclusive mode. As a result, all the commands that must be executed inside a Structure_Start ... Structure_End operation, including the Structure_End itself, require the table to be open in exclusive mode.

Procedure ShowOpenMode
    Handle hTable
    String sTable
    Integer iMode
    Showln "Open tables open mode:"
    Move 0 To hTable
    Repeat
        Get_Attribute DF_FILE_NEXT_OPENED Of hTable To hTable
        If (hTable > 0) Begin
            Get_Attribute DF_FILE_LOGICAL_NAME Of hTable To sTable
            Get_Attribute DF_FILE_OPEN_MODE Of hTable To iMode
            Showln "    " hTable ", " sTable ", " (If(iMode = DF_EXCLUSIVE, "Exclusive", "Shared"))
        End
    Until (hTable = 0)
End_Procedure

The sample procedure above shows the open mode for all tables open in an application.

Define C_SORT_SUCCESS               For 0
Define C_SORT_FAILED_OPENEXCLUSIVE  For 1
Define C_SORT_FAILED_REOPENSHARED   For 2

Function SortTable Handle hTable Returns Integer
    Integer iMode
    Boolean bOpenExclusive
    Boolean bOpenShared
    Integer iStatus
    Move C_SORT_SUCCESS To iStatus
    Get_Attribute DF_FILE_OPEN_MODE Of hTable To iMode
    If (iMode <> DF_EXCLUSIVE) Begin
        //*** Make sure we don't see the can't open error
        Send IgnoreError Of Error_Object_ID DFERR_CANT_OPEN_DATA_FILE
        Send IgnoreError Of Error_Object_ID DFERR_FILE_ACCESS_VIOLATION
        Move False To Err
        Close hTable
        Open hTable Mode DF_EXCLUSIVE
        Get_Attribute DF_FILE_OPENED Of hTable To bOpenExclusive
        If (Not(bOpenExclusive)) ;
            Move C_SORT_FAILED_OPENEXCLUSIVE To iStatus
        Send TrapError Of Error_Object_ID DFERR_CANT_OPEN_DATA_FILE
        Send TrapError Of Error_Object_ID DFERR_FILE_ACCESS_VIOLATION
    End
    Else ;
        Move (True) To bOpenExclusive

    If (bOpenExclusive) Begin
        Sort hTable
        //*** If we re-opened the table, try to restore previous situation
        If (iMode <> DF_EXCLUSIVE) Begin
            //*** Make sure we don't see the can't open error
            Send IgnoreError Of Error_Object_ID DFERR_CANT_OPEN_DATA_FILE
            Send IgnoreError Of Error_Object_ID DFERR_FILE_ACCESS_VIOLATION
            Move False To Err
            Close hTable
            Open hTable
            Get_Attribute DF_FILE_OPENED Of hTable To bOpenShared
            If (Not(bOpenShared)) ;
                Move C_SORT_FAILED_OPENEXCLUSIVE To iStatus
            Send TrapError Of Error_Object_ID DFERR_CANT_OPEN_DATA_FILE
            Send TrapError Of Error_Object_ID DFERR_FILE_ACCESS_VIOLATION
        End
    End
    Function_Return iStatus
End_Procedure

The sample function above will attempt to sort a table. If the table is not opened exclusively, it will attempt to do so. If the table is open exclusively, it will be sorted. If the function opened the table itself, it will attempt to restore the shared mode by reopening the table.