[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
##############################################################################
###+------+###################################################################
#+-| OPEN |--------------------------------------------+######################
#| +------+ The OPEN command opens database and index |######################
#| files and associated memo files, assigning |######################
#| the database file to alias <Alias> |######################
#+-----------------------------------------------------+######################
##############################################################################
##############################################################################
#+--| Syntax |----------------------------------------+#######################
#| OPEN [<C-exp> ALIAS] <Alias> |#######################
#| [INDEX <Index-list>] [SHARED || EXCLUSIVE] |#######################
#+----------------------------------------------------+#######################
##############################################################################
##############################################################################
#######+---| Description |--------------------------------------------+#######
#######| OPEN is the preferred command for using a database file and |#######
#######| its associated indexes. Unlike the USE command, several |#######
#######| databases can be opened at one time without concern for the |#######
#######| status of SELECT or the current work area. |#######
#######| ------------------------------------------------------------ |#######
#######| OPEN does not imply the CLOSE of a database. Unlike the USE |#######
#######| command, OPEN will not close the currently selected database |#######
#######| To close an OPENed file, use the CLOSE <Alias> command. |#######
#######| ------------------------------------------------------------ |#######
#######| A work area <Alias> is created when OPEN is issued. OPEN |#######
#######| changes the current work area to <Alias>. Use SELECT to |#######
#######| change the active work area. |#######
#######| ------------------------------------------------------------ |#######
#######| [<C-exp> ALIAS] <Alias> |#######
#######| |#######
#######| <C-exp> defines the file to be used. If <C-exp> is not |#######
#######| defined, then the OPEN command will try to open the file |#######
#######| set by the last SET ALIAS command or '<C-exp>.dbf' |#######
#######| if no alias is set. |#######
#######| ------------------------------------------------------------ |#######
#######| [INDEX <Index-list>] |#######
#######| |#######
#######| If <Index-list> is specified, the first index file in the |#######
#######| list will become the master index file. If no extension |#######
#######| is specified, then .fdx is assumed. |#######
#######| ------------------------------------------------------------ |#######
#######| If opening a database in shared mode, do not open any |#######
#######| associated indexes through the INDEX clause. This assures |#######
#######| proper interpretation of the neterr() error code. |#######
#######| ------------------------------------------------------------ |#######
#######| [SHARED || EXCLUSIVE] |#######
#######| |#######
#######| The keywords SHARED and EXCLUSIVE specify the access rights |#######
#######| to the database file. SHARED allows the database file to |#######
#######| be used by several users on a network. EXCLUSIVE specifies |#######
#######| that the database file should be used by one person. The |#######
#######| status of SET EXCLUSIVE serves as the default. The default |#######
#######| status for SET EXCLUSIVE is ON. |#######
#######| ------------------------------------------------------------ |#######
#######| The OPEN command returns if it can not open a shared |#######
#######| database due to a network error. It does NOT return if the |#######
#######| error condition is caused by a non-network error. Use the |#######
#######| net_err() function to obtain the network error code. |#######
#######+--------------------------------------------------------------+#######
##############################################################################
##############################################################################
#########+--| Example 1 |-------------------------------------------+#########
#########| * OPEN a specific database file. |#########
#########| |#########
#########| OPEN "mydata.dbf" ALIAS john && Alias is |#########
#########| && required |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 2 |-------------------------------------------+#########
#########| * OPEN a file with its associated index files. |#########
#########| |#########
#########| OPEN "test" ALIAS t INDEX a,b,c |#########
#########| && a, b, and c refer |#########
#########| && to index aliases, |#########
#########| && not to filenames. |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 3 |-------------------------------------------+#########
#########| * Use the SET ALIAS <alias name> TO <C-exp> to |#########
#########| * initialize the filename for the alias before |#########
#########| * opening the alias. |#########
#########| |#########
#########| DBFDEF numbers |#########
#########| INT(3) counter |#########
#########| ENDDEF |#########
#########| {...} |#########
#########| SET ALIAS numbers TO "d:\force\data\numbers" |#########
#########| OPEN numbers && Specify only the alias |#########
#########| && name. The filename |#########
#########| && has been inserted in |#########
#########| && the previous command. |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 4 |-------------------------------------------+#########
#########| * The OPEN command ties a database file to an |#########
#########| * alias without use of the SELECT command. |#########
#########| |#########
#########| OPEN one && Opens "one.dbf" |#########
#########| && with alias one. |#########
#########| OPEN "b.dbf" ALIAS two && Does not close |#########
#########| && "one.dbf". |#########
#########| OPEN "c.dbf" ALIAS three && Does not close |#########
#########| && "b.dbf". |#########
#########| |#########
#########| * At this point..."one.dbf", "b.dbf" and "c.dbf" |#########
#########| * are open. Use all database commands with an |#########
#########| * alias override. |#########
#########| |#########
#########| !one APPEND BLANK |#########
#########| !two GOTO TOP |#########
#########| !three REPLACE three->name WITH "Georgia" |#########
#########| !one EDIT |#########
#########| |#########
#########| SELECT two && Makes two the current |#########
#########| && alias. |#########
#########| APPEND BLANK && Append to two.dbf. |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 5 |-------------------------------------------+#########
#########| * Do not mix USE...SELECT <number> with OPEN. |#########
#########| * Any database opened with the OPEN command can |#########
#########| * not be selected with SELECT <number>. It must be |#########
#########| * selected through SELECT <alias>. |#########
#########| |#########
#########| OPEN abc |#########
#########| OPEN xyz && Append a blank to |#########
#########| APPEND BLANK && xyz.dbf, the current |#########
#########| && alias. |#########
#########| |#########
#########| CLOSE xyz && Closes xyz.dbf. |#########
#########| APPEND BLANK && Generates an error |#########
#########| && because there is |#########
#########| && no current alias. |#########
#########| |#########
#########| !abc APPEND BLANK && Append a blank |#########
#########| && to abc.dbf. |#########
#########| |#########
#########| SELECT 2 && Will not select |#########
#########| && xyz.dbf. Selects |#########
#########| && work area 2, which |#########
#########| && can be opened only |#########
#########| && by the USE command. |#########
#########| |#########
#########| SELECT abc && abc is the current |#########
#########| && alias. |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 6 |-------------------------------------------+#########
#########| * A generic open routine for databases |#########
#########| * on a server. |#########
#########| |#########
#########| DBFDEF data1 |#########
#########| {...} |#########
#########| ENDDEF |#########
#########| |#########
#########| DBFDEF data2 |#########
#########| {...} |#########
#########| ENDDEF |#########
#########| |#########
#########| FUNCTION LOGICAL net_open |#########
#########| PARAMETERS ALIAS netdatabase |#########
#########| VARDEF |#########
#########| LOGICAL retry |#########
#########| ENDDEF |#########
#########| |#########
#########| REPEAT |#########
#########| OPEN netdatabase SHARED |#########
#########| && assumes the database |#########
#########| && name is equal to the |#########
#########| && alias name. |#########
#########| IF neterr() <> 0 |#########
#########| @ 0,0 SAY "Error: Retry? " GET retry |#########
#########| READ |#########
#########| ELSE |#########
#########| RETURN .T. |#########
#########| ENDIF |#########
#########| UNTIL .NOT. retry |#########
#########| ENDPRO |#########
#########| |#########
#########| PROCEDURE force_main |#########
#########| |#########
#########| * use the "net_open" function described |#########
#########| * on the previous page |#########
#########| |#########
#########| IF .NOT. net_open( data1 ) |#########
#########| {...} |#########
#########| IF .NOT. net_open( data2 ) |#########
#########+----------------------------------------------------------+#########
##############################################################################
See Also:
SELECT
USE
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson