File: eaf_n_datastore.sru
Size: 58642
Date: Tue, 22 Jan 2008 23:39:17 +0100
$PBExportHeader$eaf_n_datastore.sru
forward
global type eaf_n_datastore from datastore
end type
end forward

global type eaf_n_datastore from datastore
event htmlcontextapplied pbm_dwnhtmlcontextapplied
end type
global eaf_n_datastore eaf_n_datastore

type variables
Public:
transaction                   itr_assigned
n_cst_messageservice          inv_messaging

Protected:
long                          il_languageid = 1
boolean                       ib_internalallowupdate = true
boolean                       ib_suppressretrieve

//Debugging/Error references
boolean                       ib_trace = false
boolean                       ib_debug = false
boolean                       ib_detailed = false
boolean                       ib_warning = false
boolean                       ib_usedatabaselogging = false
boolean                       ib_sqlspy = false

n_cst_loggingservice_base     inv_log
n_cst_dberrorattrib           inv_dberror
n_cst_objecterrorattrib       inv_error
n_cst_constants               inv_constants

// DataWindow Object Type
long                          il_datawindowobjecttype =                          0

String                        is_resourcesearchpath[]
end variables

forward prototypes
public function long settrace (boolean ab_state)
public function long setdetailed (boolean ab_state)
public function long setdebug (boolean ab_state)
public function integer settransobject (transaction atr_assign)
public function long getlastdberror (ref n_cst_dberrorattrib anv_dberrorattrib)
public function long getlastdberror (ref long al_sqldbcode, ref string as_message)
public function any getitemany (long al_row, string as_column, dwbuffer ae_dwbuffer, boolean ab_originalvalue)
public function long setsqlspy (boolean ab_state)
public function any getitemany (long al_row, long al_column)
public function any getitemany (long al_row, string as_column)
public function long getlanguageid ()
public function string columntypeof (string as_column)
public function long getlasterror (ref long al_errornumber, ref string as_errortext)
public function long getlasterror (ref n_cst_objecterrorattrib anv_errorattrib)
public function any getitemany (long al_row, long al_column, dwbuffer ae_dwbuffer, boolean ab_originalvalue)
public function long setlanguageid (long al_languageid)
public function long clearlasterror ()
public function string getitemstr (long al_row, string as_column, dwbuffer ae_dwbuffer, boolean ab_originalvalue)
public function long setwarning (boolean ab_value)
public function long setusedatabaselogging (boolean ab_value)
public function long propagatelogsettings ()
public function long adderror (string as_methodname, string as_message)
public function boolean iscolumnexist (string as_column)
public function string getkeydata (long al_row, dwbuffer a_dwbuffer, boolean ab_flag)
public function long sethtmlaction (string as_action, string as_context, boolean ab_allowupdate)
public function long setdataobject (string as_name, long al_datasettype, string as_resourcesearhpath[])
public function long setdataobject (string as_name, string as_resourcesearchpath[])
public function long setdataobject (string as_name)
end prototypes

event htmlcontextapplied;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the a Web Datawindow context is applied to the datastore
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "htmlcontextapplied "

inv_log.debugLog( "htmlcontextapplied", inv_constants.MESSAGE_TYPE_EAF_DEBUG, "RowCount: " + string(rowCount()) )

if ib_suppressretrieve then
   return 1
end if


return 0

end event

public function long settrace (boolean ab_state);////////////////////////////////////////////////////////////////
// Description:
//    Sets the trace property.  If TRUE it will allow tracing 
//    messages to be send to the logging service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    ab_state - The switch to enable/disable the property
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setTrace "

// Validate arguments
If isNull(ab_state) Then
   addError (METHOD_NAME, "Invalid ab_state argument")
   Return -1
End If

ib_trace = ab_state

inv_log.setTrace( ib_trace )

Return 1
end function

public function long setdetailed (boolean ab_state);////////////////////////////////////////////////////////////////
// Description:
//    Sets the detailed property.  If TRUE it will allow detailed
//    tracing and debugging messages to be sent to the logging service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    ab_state - The switch to enable/disable the property
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setDetailed "

// Validate arguments
If isNull(ab_state) Then
   addError (METHOD_NAME, "Invalid ab_state argument")
   Return -1
End If

ib_detailed = ab_state

inv_log.setDetailed( ib_detailed )

Return 1
end function

public function long setdebug (boolean ab_state);////////////////////////////////////////////////////////////////
// Description:
//    Sets the debug property.  If TRUE it will allow debugging 
//    messages to be send to the logging service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    ab_state - The switch to enable/disable the property
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application d Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setDebug "

// Validate arguments
If isNull(ab_state) Then
   addError (METHOD_NAME, "Invalid ab_state argument")
   Return -1
End If

ib_debug = ab_state

inv_log.setDebug( ib_debug )

Return 1
end function

public function integer settransobject (transaction atr_assign);////////////////////////////////////////////////////////////////
// Description:
//    Causes the DataStore to use the specified transaction object. 
//    The transaction object provides the information necessary 
//    for communicating with the database.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    atr_assign - The transaction to be assigned
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setTransObject (transaction)"

inv_log.traceLog (METHOD_NAME, + "")

// Declare local variables
long        ll_method_rc
transaction ltr_unassigned

// Perform cleanup
itr_assigned = ltr_unassigned

// Validate arguments
If isNull(atr_assign) Or Not isValid(atr_assign) Then
   addError (METHOD_NAME, "Invalid atr_assign argument")
   Return -1
End If

ll_method_rc = Super::setTransObject(atr_assign)
If ll_method_rc >= 1 Then
   itr_assigned = atr_assign
End If
Return ll_method_rc
end function

public function long getlastdberror (ref n_cst_dberrorattrib anv_dberrorattrib);////////////////////////////////////////////////////////////////
// Description:
//    Gets the last known dberror from the dberror event. (if any) 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dberrorattrib - Place holder to hold the last known error
// Returns: 
//     1 - Success
//     0 - No error was stored
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getLastDBError "

// Declare local variables
n_cst_dberrorattrib  lnv_dberror

// Validate required references
If isNull(inv_dberror) Or Not isValid(inv_dberror) Then
   addError (METHOD_NAME, "Invalid inv_dberror reference")
   Return -1
End If

// See if there is an error
If len(inv_dberror.is_message) = 0 Then
   Return 0
End If

// Pass back a copy of the error object
lnv_dberror = inv_dberror
anv_dberrorattrib = lnv_dberror
Return 1
end function

public function long getlastdberror (ref long al_sqldbcode, ref string as_message);////////////////////////////////////////////////////////////////
// Description:
//    Gets the last known dberror from the dberror event. (if any) 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_sqldbcode   - Place holder to hold the last known sqldbcode
//    as_message     - Place holder to hold the last known message
// Returns: 
//     1 - Success
//     0 - No error was stored
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getLastDBError "

// Validate required references
If isNull(inv_dberror) Or Not isValid(inv_dberror) Then
   addError (METHOD_NAME, "Invalid inv_dberror reference")
   Return -1
End If

// See if there is an error
If len(inv_dberror.is_message) = 0 Then
   Return 0
End If

// Pass the contents of the error object
al_sqldbcode =  inv_dberror.il_sqldbcode
as_message =  inv_dberror.is_message
Return 1
end function

public function any getitemany (long al_row, string as_column, dwbuffer ae_dwbuffer, boolean ab_originalvalue);////////////////////////////////////////////////////////////////
// Description:
//    Performs the appropriate getItemXXX call and returns the 
//    value casted to an ANY type variable
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_row            - The row
//    as_column         - The column name
//    ae_dwbuffer       - The datawindow buffer
//    ab_originalvalue  - True if the original value is desired
// Returns:
//    Behavior is the same as other getItemXXXX methods.
//    In summary from the Sybase/Powersoft Help system:
//    Success - The requested value casted to an ANY variable
//    Failure - Triggers the SystemError event and returns -1 if an error occurs 
//    (see "Handling errors" below). 
//    If any argument value is NULL, in PowerBuilder and JavaScript the method 
//    returns NULL, and in Java a NullPointerException is thrown.
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getItemAny (long, string, DWBuffer, boolean, REF any)"

inv_log.traceLog (METHOD_NAME, "al_row="+string(al_row)+ "~r~n" + &
   "   as_column="+as_column+ "~r~n" + &
   "   ab_originalvalue="+string(ab_originalvalue))

// Declare local variables
string   ls_gettype

// Perform cleanup
as_column = trim(as_column)

// Get the appropriate "Column Type"
ls_gettype = columnTypeOf (as_column)

If isNull(ls_gettype) Or ls_gettype = "!" Then
   addError(METHOD_NAME, "Invalid as_column argument (columnTypeOf() failed) as_column="+as_column)
      
   // The following code will fail!
   Return this.getItemNumber ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
End If

// Make the appropriate method call, depending on the column type
Choose Case ls_gettype
   Case "string"
      Return this.getItemString ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
   Case "date"
      Return this.getItemDate ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
   Case "datetime"
      Return this.getItemDateTime ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
   Case "decimal"
      Return this.getItemDecimal ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
   Case "number"
      Return this.getItemNumber ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
   Case "time"
      Return this.getItemTime ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
End Choose

// Method should never reach here
addError(METHOD_NAME, "Unrecognized 'Column Type' ("+ls_gettype+")")

// The following code will fail!
Return this.getItemNumber ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
end function

public function long setsqlspy (boolean ab_state);////////////////////////////////////////////////////////////////
// Description:
//    Sets the SQLSpy property.  If TRUE it will allow spy 
//    messages to be send to the logging service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    ab_state - The switch to enable/disable the property
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setSQLSpy ( string )"

inv_log.traceLog (METHOD_NAME, "")

// Validate arguments
If isNull(ab_state) Then
   addError (METHOD_NAME, "Invalid ab_state argument")
   Return -1
End If

ib_sqlspy = ab_state
Return 1
end function

public function any getitemany (long al_row, long al_column);////////////////////////////////////////////////////////////////
// Description:
//    Performs the appropriate getItemXXX call and returns the 
//    value after being casted to an ANY type variable
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_row            - The row
//    al_column         - The column number
// Returns:
//    Behavior is the same as other getItemXXXX methods.
//    In summary from the Sybase/Powersoft Help system:
//    Success - The requested value casted to an ANY variable
//    Failure - Triggers the SystemError event and returns -1 if an error occurs 
//    (see "Handling errors" below). 
//    If any argument value is NULL, in PowerBuilder and JavaScript the method 
//    returns NULL, and in Java a NullPointerException is thrown.
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getItemAny ( long, long )"

inv_log.traceLog (METHOD_NAME, "al_row="+string(al_row)+ "~r~nal_column="+string(al_column))

// Declare local variables
any   la_value

// Function overload default is OriginalValue = false
// Function overload default is DataWindow Buffer = primary!
la_value = getItemAny(al_row, al_column, primary!, false)
Return la_value
end function

public function any getitemany (long al_row, string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Performs the appropriate getItemXXX call and returns the 
//    value after being casted to an ANY type variable
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_row            - The row
//    as_column         - The column name
// Returns:
//    Behavior is the same as other getItemXXXX methods.
//    In summary from the Sybase/Powersoft Help system:
//    Success - The requested value casted to an ANY variable
//    Failure - Triggers the SystemError event and returns -1 if an error occurs 
//    (see "Handling errors" below). 
//    If any argument value is NULL, in PowerBuilder and JavaScript the method 
//    returns NULL, and in Java a NullPointerException is thrown.
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getItemAny (long, string)"

inv_log.traceLog (METHOD_NAME, "al_row="+string(al_row)+ "~r~nas_column="+as_column)

// Declare local variables
any   la_value

// Function overload default is OriginalValue = false
// Function overload default is DataWindow Buffer = primary!
la_value = getItemAny(al_row, as_column, primary!, false)
Return la_value
end function

public function long getlanguageid ();////////////////////////////////////////////////////////////////
// Description:
//    Gets the Language ID property.  
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns:
//     The Language ID property
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getLanguageID() "

inv_log.traceLog (METHOD_NAME, "")

Return il_languageid
end function

public function string columntypeof (string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Determines the Column "Column Type" for the passed in Column
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The column for which to determine the
//                Column Type
// Returns:
//     The Column Type, either
//          String, Date, DateTime, Decimal, Number, Time
//    "!" - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "columnTypeOf ( string ) "

inv_log.traceLog (METHOD_NAME, "as_column="+as_column)

// Declare local variables
string   ls_type

// Perform cleanup
as_column = trim(as_column)

// Validate arguments
If IsNull(as_column) Or len(as_column) = 0 Then
   addError(METHOD_NAME, "Invalid as_column argument")
   Return "!"
End If

// Get the column type from the datawindow object
ls_type = trim(this.describe(as_column+".colType"))
If IsNull(ls_type) Or len(trim(ls_type)) = 0 Or &
   ls_type = "!" Or ls_type = "?" Then
   addError(METHOD_NAME, "Invalid as_column argument (colType failed)")
   Return "!"
End If

// Make the following changes to convert into the "GetType"
Choose Case lower(left(ls_type, 5))
      Case "char(", "char"
         ls_type = "string"   
      Case "int", "integ", "long", "ulong", "real"
         ls_type = "number"
      Case "times"
         ls_type = "time"
      Case "decim"
         ls_type = "decimal"
End Choose

Return ls_type
end function

public function long getlasterror (ref long al_errornumber, ref string as_errortext);////////////////////////////////////////////////////////////////
// Description:
//    Gets the last known error from the error event. (if any) 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_errornumber    - Place holder to hold the last known errornumber
//    as_errortext      - Place holder to hold the last known errortext
// Returns: 
//     1 - Success
//     0 - No error was stored
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getLastError ( REF long, REF string ) "

// Validate required references
If isNull(inv_error) Or Not isValid(inv_error) Then
   addError (METHOD_NAME, "Invalid inv_error reference")
   Return -1
End If

// See if there is an error
If len(inv_error.is_completeerror) = 0 Then
   Return 0
End If

// Pass the contents of the error object
al_errornumber =  inv_error.il_errornumber
as_errortext =  inv_error.is_errortext

// Ensure something is passed back
If isNull(as_errortext) Or len(trim(as_errortext)) = 0 Then
   as_errortext = inv_error.is_completeerror
End If

clearLastError()

Return 1
end function

public function long getlasterror (ref n_cst_objecterrorattrib anv_errorattrib);////////////////////////////////////////////////////////////////
// Description:
//    Gets the last known error from the error event. (if any) 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_errorattrib - Place holder to hold the last known error
// Returns: 
//     1 - Success
//     0 - No error was stored
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getLastError "

// Declare local variables
n_cst_objecterrorattrib    lnv_error

// Validate required references
If isNull(inv_error) Or Not isValid(inv_error) Then
   addError (METHOD_NAME, "Invalid inv_error reference")
   Return -1
End If

// See if there is an error
If len(inv_error.is_completeerror) = 0 Then
   Return 0
End If

// Pass back a copy of the error object
lnv_error = inv_error
anv_errorattrib = lnv_error

clearLastError()

Return 1
end function

public function any getitemany (long al_row, long al_column, dwbuffer ae_dwbuffer, boolean ab_originalvalue);////////////////////////////////////////////////////////////////
// Description:
//    Performs the appropriate getItemXXX call and returns the 
//    value after being casted to an ANY type variable
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_row            - The row
//    al_column         - The column number
//    ae_dwbuffer       - The datawindow buffer
//    ab_originalvalue  - True if the original value is desired
// Returns:
//    Behavior is the same as other getItemXXXX methods.
//    In summary from the Sybase/Powersoft Help system:
//    Success - The requested value casted to an ANY variable
//    Failure - Triggers the SystemError event and returns -1 if an error occurs 
//    (see "Handling errors" below). 
//    If any argument value is NULL, in PowerBuilder and JavaScript the method 
//    returns NULL, and in Java a NullPointerException is thrown.
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getItemAny (long, long, DWBuffer, boolean, REF any)"

inv_log.traceLog (METHOD_NAME, "al_row="+string(al_row)+ "~r~n" + &
   "   al_column="+string(al_column)+ "~r~n" + &
   "   ab_originalvalue="+string(ab_originalvalue))

// Declare local variables
any      la_value
string   ls_column


// Function overload
ls_column = this.describe ( "#" + string( al_column ) + ".name" )
la_value = getItemAny(al_row, ls_column, ae_dwbuffer, ab_originalvalue)
Return la_value
end function

public function long setlanguageid (long al_languageid);////////////////////////////////////////////////////////////////
// Description:
//    Sets the Language ID property.  
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_languageid - The new default Language
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setLanguageID( long ) "

inv_log.traceLog (METHOD_NAME, "")
inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "al_languageid="+string(al_languageid))

// Validate arguments
If isNull(al_languageid) Or al_languageid <= 0 Then
   addError (METHOD_NAME, "Invalid al_languageid argument")
   Return -1
End If

il_languageid = al_languageid
Return 1
end function

public function long clearlasterror ();////////////////////////////////////////////////////////////////
// Description:
//    Clears the last known object error. (if any) 
// Revisions
//    1.0   - Initial version
// Arguments:
//    None
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "clearLastError "

// Validate required references
If isNull(inv_error) Or Not isValid(inv_error) Then
   addError (METHOD_NAME, "Invalid inv_error reference")
   Return -1
End If

// Clear out the object error
inv_error.il_errornumber = 0
inv_error.is_errortext = ""
inv_error.is_errorobject = ""
inv_error.il_errorline = 0
inv_error.is_completeerror = ""

Return 1
end function

public function string getitemstr (long al_row, string as_column, dwbuffer ae_dwbuffer, boolean ab_originalvalue);////////////////////////////////////////////////////////////////
// Description:
//    Performs the appropriate getItemXXX call and returns the 
//    value casted to a string type variable
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_row            - The row
//    as_column         - The column name
//    ae_dwbuffer       - The datawindow buffer
//    ab_originalvalue  - True if the original value is desired
// Returns:
//    Behavior is the same as other getItemXXXX methods.
//    In summary from the Sybase/Powersoft Help system:
//    Success - The requested value casted to an ANY variable
//    Failure - Triggers the SystemError event and returns -1 if an error occurs 
//    (see "Handling errors" below). 
//    If any argument value is NULL, in PowerBuilder and JavaScript the method 
//    returns NULL, and in Java a NullPointerException is thrown.
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getItemStr (long, string, DWBuffer, boolean, REF any)"

inv_log.traceLog (METHOD_NAME, "al_row="+string(al_row)+ "~r~n" + &
   "   as_column="+as_column+ "~r~n" + &
   "   ab_originalvalue="+string(ab_originalvalue))

// Declare local variables
string   ls_gettype

// Perform cleanup
as_column = trim(as_column)

// Get the appropriate "Column Type"
ls_gettype = columnTypeOf (as_column)
If isNull(ls_gettype) Or ls_gettype = "!" Then
   addError(METHOD_NAME, "Invalid as_column argument (columnTypeOf() failed) as_column="+as_column)
      
   // The following code will fail!
   Return string(this.getItemNumber ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) )
End If

// Make the appropriate method call, depending on the column type
Choose Case ls_gettype
   Case "string"
      Return this.getItemString ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) 
   Case "date"
      Return string(this.getItemDate ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) )
   Case "datetime"
      Return string(this.getItemDateTime ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) )
   Case "decimal"
      Return string(this.getItemDecimal ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) )
   Case "number"
      Return string(this.getItemNumber ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) )
   Case "time"
      Return string(this.getItemTime ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) )
End Choose

// Method should never reach here
addError(METHOD_NAME, "Unrecognized 'Column Type' ("+ls_gettype+")")

// The following code will fail!
Return string(this.getItemNumber ( al_row, as_column, ae_dwbuffer, ab_originalvalue ) )
end function

public function long setwarning (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the warning variable
//    Required for the LogPropagation interface
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setWarning( boolean value ) "

ib_warning = ab_value

inv_log.setWarning( ib_warning )

Return 1
end function

public function long setusedatabaselogging (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the Use Database Logging variable
//    Required for the LogPropagation interface
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setUseDatabaseLogging( boolean value ) "

ib_usedatabaselogging = ab_value

inv_log.setUseDatabaseLogging( ib_usedatabaselogging )

Return 1

end function

public function long propagatelogsettings ();////////////////////////////////////////////////////////////////
// Description:
//    Stub method to signal the completion of log settings to allow 
//    propagation to continue to other loggable objects
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "propagateLogSettings() "

inv_log.traceLog (METHOD_NAME, "")

inv_log.setTrace( ib_trace )
inv_log.setDebug( ib_debug )
inv_log.setDetailed( ib_detailed )
inv_log.setWarning( ib_warning )
inv_log.setUseDatabaseLogging( ib_usedatabaselogging )


return 1

end function

public function long adderror (string as_methodname, string as_message);////////////////////////////////////////////////////////////////
// Description:
//    Adds the error to the message stack and logs the error
//    Sets the last error variable for legacy code support
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
/////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

inv_log.addError(as_methodname, as_message, inv_messaging)

return 1

end function

public function boolean iscolumnexist (string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Determines the Column "Column Type" for the passed in Column
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The column for which to determine the existence
// Returns:
//     true  - column exist
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "isColumnExist ( string as_column) "

inv_log.traceLog (METHOD_NAME, "as_column=" + as_column)

if this.Describe(as_column + ".coltype") = "!" then
   return false
else
   return true
end if
end function

public function string getkeydata (long al_row, dwbuffer a_dwbuffer, boolean ab_flag);////////////////////////////////////////////////////////////////
// Description:
//    Get the key value of datawindow
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_row            - The row
//    a_dwbuffer        - The datawindow buffer
//    ab_flag           - current or original value flag
// Returns:
//    Success - The requested key value
//    Failure - returns "" if an error occurs 
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getKeyData (long al_row, DWBuffer, boolean ab_flag)"

inv_log.traceLog (METHOD_NAME, "al_row="+string(al_row)+ "~r~n")

string ls_keystring, ls_num, ls_str, ls_key, ls_cname, ls_data
int li_i, li_ccount

if not IsNumber(this.Describe("DataWindow.Processing")) then
   AddError(METHOD_NAME, "Invalid datastore")
   return ""
end if

li_ccount = Integer(this.Describe("DataWindow.Column.Count"))
for li_i = 1 to li_ccount
    ls_num = "#" + string(li_i)
    ls_str   = ls_num + ".Key" 
    ls_key   = this.Describe(ls_str)
    if ls_key = "no" then continue

    ls_str   = ls_num + ".Name "
    ls_cname = this.Describe(ls_str)
    
    ls_data = String(this.getitemany(al_row, ls_cname, a_dwbuffer, ab_flag))   
    ls_keystring += ls_data + ";"
next

return Left(ls_keystring, Len(ls_keystring) - 1)
end function

public function long sethtmlaction (string as_action, string as_context, boolean ab_allowupdate);////////////////////////////////////////////////////////////////
// Description:
//    performs a setHtmlAction on the datastore. 
//    If the action is 'Update' then it prevents the update from 
//    actually taking place
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_action   - The action passed in from the HTML form
//    as_context - The context passed in from the HTML form
//    ab_allowupdate - Prevent the datastore from doing an update if the action is 'update'
// Returns: 
//     Same codes as the actual setHTMLaction method
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setHtmlAction (string, string, boolean)"

inv_log.traceLog (METHOD_NAME, "")

inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "as_action     ="+as_action+"~r~n" + &
   "   as_context    ="+as_context+"~r~n" +&
   "   ab_allowupdate="+string(ab_allowupdate))

// Declare local variables
long ll_method_rc
boolean lb_internalallowupdate

// Handle possible null with Default values
If IsNull(as_action) Then as_action = ""
If IsNull(as_context) Then as_context = ""
If IsNull(ab_allowupdate) Then ab_allowupdate = false

// Validate arguments
If Len(Trim(as_action)) = 0 And Len(Trim(as_context)) = 0 Then
   // No action and No Context so nothing to do
   Return 1
End If

ib_internalallowupdate = ab_allowupdate

//Suppress retrieve to work around bug with PowerBuilder and SetHTMLAction which causes a retrieve
// Set the attribute, if False it will prevent updates from the datastore
if ( lower( trim( as_action ) ) ) = "update" then
   ib_suppressretrieve = true
end if

// Perform the Action
//Workaround PB11 Bug: setHtmlAction don't trigger htmlcontextapplied event, so disable transaction, after setHtmlAction enable the transaction
if lower(as_action) = 'update' then
   lb_internalallowupdate = ib_internalallowupdate
   ib_internalallowupdate = false
   SQLCA.transactiondisconnect( )
end if
ll_method_rc = Super::setHtmlAction(as_action, as_context)
if lower(as_action) = 'update' then
   ib_internalallowupdate = lb_internalallowupdate
   SQLCA.transactionconnect( )
   this.SetTransObject(SQLCA)
end if
If ll_method_rc < 0 Then
   If Not ab_allowupdate And lower(as_action) = 'update' Then
      // Get an error as we explicitly prevent the update from actually being executed
      // Continue processing
      ll_method_rc = 1
   Else
      addError(METHOD_NAME,"setHtmlAction operation failed ("+string(ll_method_rc))
   End If
End If

inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "RowCount after SetHTMLAction: " + string(rowCount()) )

//reset the retrieval suppression to allow retrieves
ib_suppressretrieve = false

// Reset the attribute to allow updates 
// (default behavior when not going through this method)
ib_internalallowupdate = true

Return ll_method_rc

end function

public function long setdataobject (string as_name, long al_datasettype, string as_resourcesearhpath[]);////////////////////////////////////////////////////////////////
// Description:
//    Assigns a Dataobject object to the datastore control
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_name - The dataobject name to be assigned
//    al_datasettype - The dataset type to be assigned
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setDataobject ( string )"

Long ll_row
String ls_syntax, ls_errors, ls_runtimeerror, ls_filename
Boolean lb_fileexists
n_cst_stringservice lnv_string
n_cst_helperservice lnvo_helper

inv_log.traceLog (METHOD_NAME, "")
inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "as_name="+as_name)

try
   
   lnvo_helper = create n_cst_helperservice
   lnv_string = create n_cst_stringservice
   
   if Pos(Lower(as_name), "&languageid") > 0 then
      as_name = lnv_string.globalreplace( as_name, "&languageid", String(GetLanguageID()), true)
   end if

   il_datawindowobjecttype = al_datasettype
   
   if al_datasettype = inv_constants.DATASET_TYPE_SRD then
                  
      lb_fileexists = false
      if UpperBound(as_resourcesearhpath[]) > 0 then
         for ll_row = 1 to UpperBound(as_resourcesearhpath)
             if Right(as_resourcesearhpath[ll_row], 1) <> "\" then
                as_resourcesearhpath[ll_row] += "\"
             end if
             if Lower(Right(as_name, 4)) <> ".srd" then
                ls_filename = as_name + ".srd"
             else
                ls_filename = as_name
             end if
             ls_filename = as_resourcesearhpath[ll_row] + "Language_" + String(GetLanguageid()) + "\" + ls_filename
             if FileExists(ls_filename) then
                lb_fileexists = true
                exit
             end if
         next
      else
         if Lower(Right(as_name, 4)) <> ".srd" then
            ls_filename = as_name + ".srd"
         else
            ls_filename = as_name
         end if
         if FileExists(ls_filename) then lb_fileexists = true
      end if
      
      if lb_fileexists then
         // Read SRD file
         lnvo_helper.readfile(ls_filename, ls_syntax)
         if this.Create(ls_syntax, ls_errors) = -1 then
            addError(METHOD_NAME, "Create datastore failed, error text=" + ls_errors)
            return -1
         end if
      else
         this.DataObject = as_name
         If Not isNumber(this.describe("DataWindow.Processing")) Then
            addError(METHOD_NAME, "Can't find datawindow object file=" + ls_filename)
            return -1
         end if
      end if
      
      
   elseif al_datasettype = inv_constants.DATASET_TYPE_DWO then
      
      // Perform the actual assignment
      this.dataobject = as_name
      
   elseif al_datasettype = inv_constants.DATASET_TYPE_SQL then
      
      ls_syntax = SQLCA.SyntaxFromSql(as_name, "", ls_errors)
      if ls_syntax = "" then
         addError(METHOD_NAME, "SyntaxFromSql failed, SQL is:" + as_name + ", error text=" + ls_errors)
         return -1
      end if
      
      if this.Create(ls_syntax, ls_errors) = -1 then
         addError(METHOD_NAME, "Create datastore failed, error text=" + ls_errors)
         return -1
      end if
      
   end if
   
   // If appropriate, validate the actual assignment
   If len(trim(as_name)) > 0 Then
      If Not isNumber(this.describe("DataWindow.Processing")) Then
         Return -1
      End If
   End If

   // Set dialect of DBMS
   if Left(Lower(SQLCA.dbms), 3) = "odb" then // Supposed as ASA
      ls_syntax = this.Object.DataWindow.Syntax
      ls_syntax = lnv_string.globalreplace(ls_syntax, "dbo.", "dba.", true)   
      if this.Create(ls_syntax, ls_errors) = -1 then
         addError(METHOD_NAME, "Create datastore failed, error text=" + ls_errors)
         return -1
      end if
   end if

catch ( RuntimeError re )
   
   ls_runtimeerror = "Runtime Error:" + inv_constants.CRLF + inv_constants.CRLF
   ls_runtimeerror += "Error Code: " + string(re.number) + inv_constants.CRLF
   ls_runtimeerror += "Object: " + re.objectName + inv_constants.CRLF
   ls_runtimeerror += "Class: " + re.class + inv_constants.CRLF
   ls_runtimeerror += "Function/Event: " + re.routineName + inv_constants.CRLF
   ls_runtimeerror += "Line: " + string(re.line) + inv_constants.CRLF
   inv_log.addError( METHOD_NAME, "Runtime Error: " + ls_runtimeerror, inv_messaging )
   
   return -1
   
finally

   if IsValid(lnv_string) then
      destroy lnv_string
   end if
   
   if IsValid(lnvo_helper) then
      destroy lnvo_helper
   end if
   
end try

Return 1
end function

public function long setdataobject (string as_name, string as_resourcesearchpath[]);////////////////////////////////////////////////////////////////
// Description:
//    Assigns a Dataobject object to the datastore control
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_name - The dataobject name to be assigned
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

return setdataobject(as_name, inv_constants.DATASET_TYPE_DWO, as_resourcesearchpath)
end function

public function long setdataobject (string as_name);////////////////////////////////////////////////////////////////
// Description:
//    Assigns a Dataobject object to the datastore control
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_name - The dataobject name to be assigned
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

String ls_null[]

return setdataobject(as_name, inv_constants.DATASET_TYPE_DWO, ls_null)
end function

event dberror;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when a database error occurs in the DataStore.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    sqldbcode - A database-specific error code 
//    sqlerrtext - A database-specific error message
//    sqlsyntax - The full text of the SQL statement being sent to the 
//                DBMS when the error occurred
//    buffer - The buffer containing the row involved in the database 
//             activity that caused the error
//    row - The number of the row involved in the database activity 
//          that caused the error
// Returns: 
//    1 - Suppress the default message box   
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "dbError (long, string, string, DWBuffer, long)"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
string                     ls_message

n_cst_conversionservice    lnv_conversion

try
   
   // Disable show dberror message, for the PB11 BUG of setHtmlAction don't trigger htmlcontextapplied event
   if not ib_internalallowupdate then return 1
   
   lnv_conversion = create n_cst_conversionservice
   inv_log.propagateSettings( lnv_conversion )
   
   // Construct the message
   ls_message = " A database error has occurred.~r~n"
   If Not isNull(buffer)      Then  ls_message += "~r~nBuffer= "+lnv_conversion.string(buffer)
   If row > 0                 Then  ls_message += "~r~nRow= "+string(row)
   If Not isNull(sqldbcode)   Then  ls_message += "~r~nDB error code= "+String (sqldbcode)
   If len(sqlerrtext) > 0     Then  ls_message += "~r~nDB message= "+ sqlerrtext
   If len(sqlsyntax)  > 0     Then  ls_message += "~r~nDB SQL= "+ sqlsyntax
   
   addError( METHOD_NAME, ls_message )
   
   //Add the individual named messages for more granular introspection into the error
   inv_messaging.add( inv_constants.MESSAGE_NAME_EAF_DB_ERROR_BUFFER, inv_constants.MESSAGE_TYPE_EAF_DB_ERROR, lnv_conversion.string(buffer) )
   inv_messaging.add( inv_constants.MESSAGE_NAME_EAF_DB_ERROR_ROW, inv_constants.MESSAGE_TYPE_EAF_DB_ERROR, string(row) )
   inv_messaging.add( inv_constants.MESSAGE_NAME_EAF_DB_ERROR_SQLDBCODE, inv_constants.MESSAGE_TYPE_EAF_DB_ERROR, string(sqldbcode) )
   inv_messaging.add( inv_constants.MESSAGE_NAME_EAF_DB_ERROR_SQLERRTEXT, inv_constants.MESSAGE_TYPE_EAF_DB_ERROR, sqlerrtext )
   inv_messaging.add( inv_constants.MESSAGE_NAME_EAF_DB_ERROR_SQLSYNTAX, inv_constants.MESSAGE_TYPE_EAF_DB_ERROR, sqlsyntax )

   // Store the error information for later usage
   If isValid(inv_dberror) Then
      inv_dberror.ie_buffer = buffer
      inv_dberror.il_row = row
      inv_dberror.il_sqldbcode = sqldbcode
      inv_dberror.is_sqlerrtext = sqlerrtext
      inv_dberror.is_sqlsyntax = sqlsyntax
      inv_dberror.is_message = ls_message
   Else
      addError(METHOD_NAME, "Invalid inv_dberror reference")
   End If
   
finally
   if isValid( lnv_conversion ) then
      destroy lnv_conversion
   end if
end try

Return 1
end event

on eaf_n_datastore.create
call super::create
TriggerEvent( this, "constructor" )
end on

on eaf_n_datastore.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event constructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is created
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "constructor "

inv_log = create n_cst_loggingservice_base
inv_dberror = create n_cst_dberrorattrib           
inv_error = create n_cst_objecterrorattrib         
inv_messaging = create n_cst_messageservice
inv_constants = create n_cst_constants

// Tell the logging service who requested it
inv_log.setRequestor(this)
end event

event sqlpreview;////////////////////////////////////////////////////////////////
// Description:
//    Occurs immediately before a SQL statement is submitted to the DBMS. 
//    Functions that trigger DBMS activity are Retrieve, Update, and ReselectRow.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    request - The function that initiated the database activity
//    sqltype - The type of SQL statement being sent to the DBMS
//    sqlsyntax - The full text of the SQL statement
//    buffer   - The buffer containing the row involved in the database activity 
//    row   - The number of the row involved in the database activity, 
///            that is, the row being updated, selected, inserted, or deleted
// Returns: 
//    0  - Continue processing
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "sqlPreview ()"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
string                        ls_message

n_cst_conversionservice    lnv_conversion

try
   //Check for retrieval suppression
   //Only possible during application of Updates from Web DataWindow
   if ( ib_suppressretrieve ) then
      return 1
   end if
   
   lnv_conversion = create n_cst_conversionservice
   inv_log.propagateSettings( lnv_conversion )
   If ib_sqlspy Or ib_debug Then
      ls_message = "~r~n" +&
         "   AllowUpdate=  "+string(ib_internalallowupdate)+"~r~n"+ &
         "   Request=      "+lnv_conversion.string(request)+"~r~n"+ &
         "   Type=         "+lnv_conversion.string(sqltype)+"~r~n"+ &
         "   Buffer=       "+lnv_conversion.string(buffer)+"~r~n"+ &
         "   Row=          "+string(row)+"~r~n"+ &
         "   Syntax=       "+sqlsyntax 
   
      inv_log.debuglog(METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, ls_message)
   End If
   
finally
   if isValid( lnv_conversion ) then
      destroy lnv_conversion
   end if
end try

// Return 0 - Continue processing
Return 0


end event

event updatestart;////////////////////////////////////////////////////////////////
// Description:
//    Occurs after a script calls the Update function and just 
//    before changes in the DataStore are sent to the database.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//    0 - Continue processing
//    1 - Do not perform the update
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "updateStart ()"

inv_log.traceLog (METHOD_NAME, "")

// Check to see if Updates are to be allowed
If Not ib_internalallowupdate Then 
   // Do not perform the update
   Return 1 
End If

If ib_sqlspy Or ib_debug Then
   inv_log.debugLog(METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "rowCount() = "+string(this.rowCount()) + " " + &
      "modifiedCount()="+string(this.modifiedCount()) + " " + &
      "deletedCount()="+string(this.deletedCount()))
End If

// Continue processing
Return 0
end event

event error;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when an error is found in a data or property expression 
//    for an external object or a DataWindow object. Also occurs when
//    a communications error is found in a distributed application.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    errornumber - PowerBuilder's error number
//    errortext   - PowerBuilder's error message
//    errorwindowmenu - The name of the window or menu that is the parent 
//                      of the object whose script caused the error
//    errorobject - The name of the object whose script caused the error
//    errorscript - The full text of the script in which the error occurred
//    errorline   - The line in the script where the error occurred 
//    action   - A value you specify to control the application's course of 
//                action as a result of the error.
//    returnvalue - 
// Returns: None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "error ( long, errortext, errorwindowmenu, errorobject, errorscript, errorline, refaction, ref returnvalue )"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
string      ls_completeerror

// Construct the message
ls_completeerror = " An error has occurred.~r~n" 
If errornumber > 0         Then  ls_completeerror += "~r~n   errornumber= "+string(errornumber)
If len(errortext) > 0      Then  ls_completeerror += "~r~n   errortext=   "+errortext
If len(errorobject) > 0    Then  ls_completeerror += "~r~n   errorobject= "+errorobject
If errorline > 0           Then  ls_completeerror += "~r~n   errorline=   "+string(errorline)

// Store the error information for later usage
If isValid(inv_error) Then
   inv_error.il_errornumber = errornumber
   inv_error.is_errortext = errortext
   inv_error.is_errorobject = errorobject
   inv_error.il_errorline = errorline
   inv_error.is_completeerror = ls_completeerror
Else
   addError(METHOD_NAME, "Invalid inv_error reference")
End If

// Log the error
addError( METHOD_NAME, ls_completeerror)

end event

event retrieveend;////////////////////////////////////////////////////////////////
// Description:
//    This event executes when a retrieval process completes
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//    0  Continue processing
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "retrieveEnd ()"

inv_log.traceLog (METHOD_NAME, "")

If ib_sqlspy Or ib_debug Then
   inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "rowCount() = "+string(this.rowCount()))
End If   

end event

event destructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is destroyed
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

if isValid( inv_dberror ) then
   destroy inv_dberror
end if

if isValid( inv_error ) then
   destroy inv_error
end if

if isValid( inv_log ) then
   destroy inv_log
end if

if isValid( inv_messaging ) then
   destroy inv_messaging
end if

if isValid( inv_constants ) then
   destroy inv_constants
end if

end event