PdcDatabase.CreateUserTable: Difference between revisions
Jump to navigation
Jump to search
Line 3: | Line 3: | ||
== Description == | == Description == | ||
Using this method you can create a usertable inclusive all fields | Using this method you can create a usertable inclusive all fields, no manually database reorganisation needed.<br> | ||
This is only possible if the table doesn't exist already. To determine this use the method 'UserTableExists'.<br> | This is only possible if the table doesn't exist already. To determine this use the method 'UserTableExists'.<br> | ||
<br /> | <br /> | ||
Line 31: | Line 31: | ||
* Indexed:<br /> | * Indexed:<br /> | ||
: text value, true or false.<br /> | : text value, true or false.<br /> | ||
== Notes == | == Notes == |
Latest revision as of 13:25, 22 June 2023
Declaration
CreateUserTable(TableName: String, TableDescription: String, FieldData: String) as boolean
Description
Using this method you can create a usertable inclusive all fields, no manually database reorganisation needed.
This is only possible if the table doesn't exist already. To determine this use the method 'UserTableExists'.
The FieldData parameter is the most important and complex parameter in this method. It consists of 8 elements, separated by ~.
- Field Name:
- text value, cannot be empty, cannot exist in UF_FIELDNAME or VELDNAAM.
- Field Description:
- text value. This text will be stored in the long fieldname in the user's language in the VELDNAAM table.
- Field Type:
- TEXT: Length >0, number of decimals = 0 and the length of the default value <= length.
- CHOICE: text value, length >0, number of decimals = 0, and the length of the default value <= length, choices are separated by #. If a default value is provided it needs to exists in the list of choices.
- NUMERIC: fieldlength = 0, number of decimals <= 99, if a default value is provided it needs to be numeric.
- CURRENCY: fieldlength = 0, number of decimals <= 99, if a default value is provided it needs to be numeric.
- DATE: fieldlength = 0, number of decimals = 0, default value is emtpy.
- YESNO: fieldlength = 0, number of decimals = 0, default value is empty (will be created as false), FALSE, TRUE.
- MEMO: fieldlength = 0, number of decimals = 0, default value is emtpy.
- TIMESTAMP: fieldlength = 0, number of decimals = 0, default value is emtpy.
- Field length:
- see specifics per field type above.
- Default value:
- see specifics per field type above.
- Number of decimals:
- see specifics per field type above.
- Choices:
- text value, separated by #.
- Indexed:
- text value, true or false.
Notes
After creating a table with this method, you have to restart PdC, to have the new table shown in the menu of PdC.
Code example
Example in vb.NET
Private Function CheckUserTable() As Boolean
Dim result As Boolean = False
If PDC.App.Database.UserTableExists("UT_TEST") Then
result = True
Else
Dim fieldstring As StringBuilder = New StringBuilder
fieldstring.Append("UT_TEST_CREATEDATE~datetime created~TIMESTAMP~0~~0~~FALSE")
fieldstring.Append("~UT_TEST_CHOICE~Choice test~CHOICE~99~Yes~0~Yes#No#DontKnow~FALSE")
fieldstring.Append("~UT_TEST_STRINGVALUE~string value~TEXT~40~~0~~FALSE")
fieldstring.Append("~UT_TEST_NUMERICVALUE~numeric value~NUMERIC~0~0~4~~FALSE")
fieldstring.Append("~UT_TEST_BOOLEANVALUE~boolean value~YESNO~0~~0~~FALSE")
fieldstring.Append("~UT_TEST_DATEVALUE~date value~DATE~0~~0~~FALSE")
fieldstring.Append("~UT_TEST_DATETIMEVALUE~datetime value~TIMESTAMP~0~~0~~FALSE")
fieldstring.Append("~UT_TEST_MEMOVALUE~memo value~MEMO~0~~0~~FALSE")
If Not PDC.App.Database.CreateUserTable("UT_TEST", "Test usertable", fieldstring.ToString) Then
MsgBox(PDC.App.LastError)
End If
End If
Return result
End Function
Example in VBScript
sub sCreateUserTable
dim strTableName
dim strFieldData
if pdc.Info.PDCVersion >= 5.1 then
strTableName = "UT_TEST"
if not pdc.Database.UserTableExists(strTableName ) then
if pdc.Info.PDCVersion >= 5.3 then
'Create indexed userfields
strFieldData = "UT_TEXT~Tekstveld~TEXT~99~Default~0~~TRUE"
strFieldData = strFieldData & "~UT_CHOICE~Keuzelijst~CHOICE~99~Yes~0~Yes#No#DontKnow~FALSE"
strFieldData = strFieldData & "~UT_NUMERIC~Getal~NUMERIC~0~99~4~~FALSE"
strFieldData = strFieldData & "~UT_CURRENCY~Valuta~CURRENCY~0~99,99~2~~FALSE"
strFieldData = strFieldData & "~UT_DATE~Datum~DATE~0~~0~~FALSE"
strFieldData = strFieldData & "~UT_YESNO~Checkbox~YESNO~0~TRUE~~~FALSE"
strFieldData = strFieldData & "~UT_MEMO~Memo~MEMO~0~~~~FALSE"
strFieldData = strFieldData & "~UT_TIMESTAMP~Datum/Tijd~TIMESTAMP~0~~~~FALSE"
else
'Not indexed userfields
strFieldData = "UT_TEXT~Tekstveld~TEXT~99~Default~0~"
strFieldData = strFieldData & "~UT_CHOICE~Keuzelijst~CHOICE~99~Yes~0~Yes#No#DontKnow"
strFieldData = strFieldData & "~UT_NUMERIC~Getal~NUMERIC~0~99~4~"
strFieldData = strFieldData & "~UT_CURRENCY~Valuta~CURRENCY~0~99,99~2~"
strFieldData = strFieldData & "~UT_DATE~Datum~DATE~0~~0~"
strFieldData = strFieldData & "~UT_YESNO~Checkbox~YESNO~0~TRUE~~"
strFieldData = strFieldData & "~UT_MEMO~Memo~MEMO~0~~~"
strFieldData = strFieldData & "~UT_TIMESTAMP~Datum/Tijd~TIMESTAMP~0~~~"
end if
if pdc.Database.CreateUserTable(strTableName , strTableName , strFieldData) then
msgbox "Table '" & strTableName & "' created successfull."
else
msgbox "Error during creation of table '" & strTableName & "'." & vbCrLf & _
"Error: " & pdc.LastError
end if
else
msgbox "Table '" & strTableName & "' already exists."
end if
else
msgbox "Free user tables only created from PdC version 5.1 onwards."
end if
end sub
Availability
Available since 11-12-2015 (from version 5.1 onwards)
parameter Indexed is available since 05-11-2017 (from 5.3 onwards)