sx_AppendEx

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_AppendEx

VB Declaration

Declare Function sx_Append Lib "Apollo9.dll" () As Integer

C Declaration

SHORT FAR PASCAL sx_AppendEx (VOID);

Description

Append a record to the database using the current contents of the record buffer. Use sx_AppendEx in situations where the user has the ability to cancel an intended record addition. If the record addition is canceled, a record does not have to be deleted from the database, as is the case with sx_AppendBlank.

 

To begin with an empty record buffer, force the record pointer to EOF as in the example below.

sx_AppendEx immediately commits the new record to disk and updates all open indexes.

 

The standard sx_Append and sx_AppendBlank procedures do not return a value to the applications programmer. In fact, if a lock contention occurs with the non-extended procedures, the user must wait for the lock to be released before the record is appended. This extended function will return an error code if ANY error is encountered, so that the application programmer may deal with it.

Return Value

-1

Record successfully appended

1

Table lock failure (record not written)

2

File seek error (record not written)

3

File write error (record not written)

4

Key insertion failure (record written/index corrupted)

5

Table is read only (record not written)

6

Current work area invalid (record not written)

VB Example

Sub bAdd_Click()

Dim lSaveRec As Long

Dim iRet As Integer

iAddMode = True

lSaveRec = sx_RecNo()

sx_GoBottom ' force eof to clear rec buffer

sx_Skip 1

Editor.Show 1 ' if User cancels iAddmode will be false

If iAddMode Then

iRet = sx_AppendEx

If iRet = 1 Then MsgBox "Table lock failure!"  

If iRet = 2 Then MsgBox "File seek error"

If iRet = 3 Then MsgBox "File write error"

If iRet = 4 Then MsgBox "Key insertion failure"

If iRet = 5 Then MsgBox "Table is read only"

If iRet = 6 Then MsgBox "Current work area invalid"  

If iRet > -1 Then Exit Sub

else

sx_Go lSaveRec

End If

End Sub

C Example

void CNamesForm::OnButtonAdd()

{

SHORT iRet;

LONG lSaveRec;

// set switch on, setup append, and then edit

bAddMode = TRUE;

lSaveRec = sx_RecNo();

sx_GoBottom();

sx_Skip(1L);

OnButtonEdit();

 

// if user cancels edit, bAddMode will be FALSE

if (bAddMode)

{

iRet = sx_AppendEx();

switch( iRet )

 {

case -1:  

AfxMessageBox((LPCSTR) "Success!");

break;  

case 1:  

AfxMessageBox((LPCSTR) "Table lock failure!" );  

break;  

case 2:  

AfxMessageBox((LPCSTR) "File seek error" );

break;

case 3:  

AfxMessageBox((LPCSTR) "File write error" );

break;

case 4:  

AfxMessageBox((LPCSTR) "Key insertion failure" );

break;

case 5:  

AfxMessageBox((LPCSTR) "Table is read only" );

break; case 6:  

AfxMessageBox((LPCSTR) "Current work area invalid" );

}

}

else

sx_Go(lSaveRec);

}

See Also

sx_Append, sx_AppendBlank, sx_AppendBlankEx, sx_Commit, sx_PutRecord, sx_Replace