CasewareDocs

RegisterDatabase

This command can only be used in the partial import task context. Registers a database for the ImportFiles collection of the Standard Import Routine or Standard Import Routine extension that owns the task.

Compatibility

Available as of IDEA version 10.2

Syntax

RegisterDatabase(databaseName As String, databaseAlias As String) As Object

Parameter

databaseName

A string containing the name of the database to register. Leading and trailing spaces are ignored. An exception is thrown if this name is empty or if the database does not exist.

databaseAlias

A string containing the alias under which the database will be registered with the collection of imported databases of the Standard Import Routine or Standard Import Routine extension that owns the task. If databaseAlias is empty the application will generate a unique alias.

An exception is thrown if the owner's import files (the collection of imported databases) already contains an element with the same alias. Note that the comparison is case insensitive. However, one exception exists: If the registration is performed by a Standard Import Routine extension and the proposed alias was inherited from the main routine, the entry that was inherited from the main routine will be replaced with the entry registered by the extension.

Return Value

An ISimpleImportFile2 reference to the object in ImportFiles that contains information on the database.

Remarks

The registration may change the reference to the collection of imported databases. If the registration was successful, the caller should requery the context object for the new ImportFiles collection.

Example

Option Explicit 
Sub Main
'Creates the database and registers it under the alias that will be used in the data preparation.
'Registered databases will be part of the collection ImportFiles.
SmartContext.RegisterDatabase CreateDatabaseT1(), "T1"
End Sub
'Creates the database T1 at the location that is the target of the current import session and returns its name.
Function CreateDatabaseT1() As String
'Your code to create a new database
End Function

Extended Example

Option Explicit
Const ExecutionLocation_Client As Long = 0
Const ExecutionLocation_Server As Long = 1
Sub Main
'Creates the databases and registers them under the aliases that will be used in data preparation
'Registered databases will be part of the collection ImportFiles
SmartContext.RegisteredDatabase CreateDatabaseT1(), "T1"
SmartContext.RegisteredDatabase CreateDatabaseT2(), "T2"


EnableAuditFolderSelectionPage
End Sub


'Creates the database T1 at the location that is the target of the current import session and returns its name.
Function CreateDatabaseT1() As String
Dim task As Object
Set task = NewDatabaseCreator()
task.FieldDelimiter = "|"
 
Dim databaseName As String
databaseName = UniqueDatabaseName "T1"


task.AddDatabaseAt databaseName, "", GetCurrentImportTarget()

'Numeric field F1
task.AddField "F1", "<F1>", 4, 8, 2

'Char field F2
task.AddField "F2", "<F2>", 3, 32, 0

'Append row #1
task.AppendValues "1|F2,1"

'Append row #2
task.AppendValues "2|F2,2"

task.PerformTask

CreateDatabaseT1 = databaseName
End Function
'Creates the database T2 at hte location that is the target of the current import session and returns its name.
Function CreateDatabaseT2() As String
Dim task As Object
Set task = NewDatabaseCreator()
task.FieldDelimiter = "|"
Dim databaseName As String
databaseName = UniqueDatabaseName ("T2")

task.AddDatabaseAt databaseName, "", GetCurrentImportTarget()

'Numeric field F1
task.AddField "F1", "<F1>", 4, 8, 2

'Date field F3
task.AddField "F3", "<F3>", 5, 0, 0

'Append row #1
task.AppendValues "1|20130306"


'Append row #2
task.AppendValues "2|20130912"


task.PerformTask

CreateDatabaseT2 = databaseName
End Function
'Enables the Select Audit Folder page in the wizard and initializes it with a dummy period.
Sub EnableAuditFolderSelectionPage()
Dim pageSettingsService As Object
Set pageSettingsService = SmartContext.GetServiceById("CirWizardPageSettingsService")
Dim selectAuditFolderPageSettings As Object
Set selectAuditFolderPageSettings = pageSettingsService.GetCirWizardPageSettings("SelectAuditFolder")
If selectAuditFolderPageSettings is nothing Then
SmartContext.Log.LogWarning "The settings object for the page SelectAuditFolder was not found."
Else
selectAuditFolderPageSettings.Enabled = true
selectAuditFolderPageSettings.Inputs.Add "PeriodStart", "20130101"
selectAuditFolderPageSettings.Inputs.Add "PeriodEnd", "20131231"
End If
End Sub


'Returns a new database creator
Function NewDatabaseCreator() As Object
Set NewDatabaseCreator = SmartContext.MacroCommands.CreateDatabase
End Function

'Returns a value that specifies whether the target of the current import session is the desktop 
(ExecutionLocation_Client) or the server project (ExyecutionLocation_Server).
Function GetCurrentImportTarget() As Long
Dim executionLocation As Long
If SmartContext.IsServerImportTask Then
executionLocation = ExecutionLocation_Server
Else
executionLocation = ExecutionLocation_Client
End If

GetCurrentImportTarget = executionLocation
End Function

'Generates a database name that is unique at the target of the current import session from a specified logical name.
Function UniqueDatabaseName(ByVal logicalName as string) As String
UniqueDatabaseName = SmartContext.MacroCommands.SimpleCommands.UniqueFileFlatName(logicalName)
End Function