"createDatabase" (JSON Action)
JSON DB "createDatabase" action creates a database
A database contains tables.
Request examples
Minimal
{
"api": "db",
"action": "createDatabase",
"params": {
"databaseName": "test_db_min"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}{
"api": "db",
"apiVersion": "1.0",
"requestId": "1",
"action": "createDatabase",
"params": {
"databaseName": "test_db_max",
"path": "c:\\"
},
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string"
},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Success
{
"authToken": "replaceWithAuthTokenFromCreateSession",
"result": {
"dataFormat": "objects",
"fields": [
{
"name": "databaseName",
"type": "varchar",
"length": 8192,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "path",
"type": "varchar",
"length": 8192,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "uid",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey": 0,
"autoValue": "none"
}
],
"data": [
{
"databaseName": "testdatabase",
"path": ".\\testdatabase.dbs\\SQL_SYS",
"uid": 1007
}
]
},
"requestId": "00000010",
"debugInfo": {
"request": {
"authToken": "replaceWithAuthTokenFromCreateSession",
"api": "db",
"action": "createDatabase",
"params": {
"databaseName": "testdatabase",
"path": "."
},
"apiVersion": "1.0",
"requestId": "00000010",
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string"
},
"debug": "max"
},
"serverSuppliedValues": {
"databaseName": null,
"ownerName": null
},
"errorData": {
"errorData": null
},
"warnings": []
},
"errorCode": 0,
"errorMessage": ""
}
{
"requestId": "3",
"debugInfo": {
"request": {
"api": "db",
"action": "createDatabase",
"params": {
"databaseName": "test_db_min"
},
"requestId": "3",
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
},
"serverSuppliedValues": {
"databaseName": null,
"ownerName": null
},
"errorData": {
"errorData": null
},
"warnings": []
},
"errorCode": 4021,
"errorMessage": "Can't create database",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Use the createDatabase API action to create a database
The "params" property is an object that contains an action's request parameters as defined by a set of properties. Each action defines its own required and optional properties. See System limits for a comprehensive overview of property requirements and limitations.
"params" properties summaryProperty | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
defines the name of the database about to be created | Required - No default value | string | 1 to 64 bytes | |
(optional) changes the path of the database |
| string | 0 to 2,048 bytes | |
(optional) identifies a transaction in which this action will be included. |
| string | 0 to 255 bytes |
The "databaseName" property is a string that identifies the name of the target database.
A zero-length
"databaseName"is invalid.Its limits are from 1 to 64 bytes.
The "path" property is a string that identifies the path of the database folder.
Do not include the name of the database file in the path because the database filename and the extension
.dbsare automatically added to the path, see Create thetest_db_max.dbsdatabase in thec:\temp\folder.When
"path"is omitted or set to null, the FairCom server creates the database in the<faircom>/datafolder.When you include the
\character in the"path"property, you must include two backslashes in a row because in JSON the single backslash character is an escape character— for example,"c:\\temp"designates thec:\temppath.You can use forward slashes in the path property (even on Microsoft Windows) because the FairCom server correctly interprets them as backslashes on Windows and as forward slashes on Linux, MacOS, and Unix.
Examples
Create the test_db_max.dbs database in the c:\temp\ folder
{
"action": "createDatabase",
"params": {
"databaseName": "test_db_max",
"path": "c:\\temp"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}"path" omitted or set to null
If the FairCom server is installed in the C:\FairCom\FairCom-Edge.windows.64bit.v4.5.1.170\ folder, this code example creates the test3.dbs database in C:\FairCom\FairCom-Edge.windows.64bit.v4.5.1.170\data\.
{
"action": "createDatabase",
"params": {
"databaseName": "test3"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Forward slash
{
"action": "createDatabase",
"params": {
"databaseName": "test4",
"path": "c:/temp"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
"result" properties summaryProperty | Description | Type | Limits (inclusive) | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
is an array of objects or arrays. Each item in the array describes a record. The array is empty if no results are available. | array | The action determines its contents. | ||||||||||||||||||||||
identifies the format of the data in the | string |
| ||||||||||||||||||||||
is an array of objects, each of which contains the characteristics of a field. The | array | |||||||||||||||||||||||
| identifies when and how the server automatically sets the field value. | string |
| |||||||||||||||||||||
| (optional) identifies the default value of the field. | string | 0 to 65,500 bytes | |||||||||||||||||||||
| identifies the length of the field. | integer |
| |||||||||||||||||||||
| identifies the name of the field. | string | 0 to 64 bytes | |||||||||||||||||||||
| (optional) identifies whether a field can contain a NULL value. | Boolean |
| |||||||||||||||||||||
| (optional) when > 0, identifies the ordinal position of the field within the table's primary key. | integer |
| |||||||||||||||||||||
| if the type is | integer |
| |||||||||||||||||||||
| identifies the type of the field. See Data types. | string |
|
This optional property indicates when and how the server automatically sets the field value.
Only one of these values is allowed per field.
"none"indicates that the server does not automatically set the field's value."incrementOnInsert"indicates that the server automatically increments a field’s value each time the server inserts a new record. It applies to fields that are of the type of decimal or one of the integer types, such as"bigint". Only one field per table can have this attribute. The server returns an error when assigning this attribute to multiple fields. The JSON DB API automatically creates the"id"field as an"incrementOnInsert"field. If you apply this attribute to another field, it becomes the only automatically incremented field in the table. If you want that field to be the primary key, assign"primaryKey": 1to it."timestampOnInsert"indicates that the server automatically sets a field’s value to the current date and time of an insert. It applies only to fields with a type of"timestamp".Note
If you attempt to insert a record and specify a timestamp for a field that has
"autoValue"set to"timestampOnInsert", the timestamp you specified is ignored, and the current date and time are assigned to the field."timestampOnUpdate"indicates that the server automatically sets a field’s value to the current date and time of an update. This setting applies only to timestamp fields."timestampOnUpdateAndInsert"indicates that the server automatically sets a field’s value to the current date and time of an insert and an update. It applies only to fields with a type of"timestamp"."changeId"indicates the server uses the field for optimistic locking. The server automatically sets the field's value to the internal transaction number used during the last update of the record. This value changes each time the server updates the record. A table may only have one change tracking field. The field type must be"bigint".The JSON DB API automatically creates a
"changeid"field with change-tracking functionality.Change tracking is optional in the CTDB and ISAM APIs. The application must create a 64-bit integer field and assign change-tracking functionality to it.
Request Example
"fields": [
{
"name": "signed_int32",
"type": "integer",
"autoValue": "incrementOnInsert"
}
]
Response Example
{
"result": {
"dataFormat": "objects",
"data": [
{
"changeIdField": "changeId",
"createRecByteIndex": false,
"databaseName": "ctreeSQL",
"fieldDelimiterValue": 0,
"fields": [
{
"autoValue": "incrementOnInsert",
"defaultValue": null,
"length": null,
"name": "signed_int32",
"nullable": true,
"primaryKey": 0,
"scale": null,
"type": "integer"
}
]
}
]
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
The "data" property is an array of objects or arrays that contain information about the database. The "dataFormat" property specifies whether the content is arrays or objects. The initiating action defines the data contents. In results messages, when no results are available, it is empty. For path formats, see "path".
Examples
arrays
"data": [ ["test1", ".\\test1.dbs\\SQL_SYS", 1003] ]
objects
"data":
[
{
"databaseName": "test7",
"path": ".\\test7.dbs\\SQL_SYS",
"uid": 1015
}
]
The "dataFormat" property is a case-insensitive string enum that defines the format of the "data" property. The default format is an array of arrays. The alternative is an array of objects. The default for "dataFormat" can be changed during a "createSession" action by assigning a different value to the "dataFormat" property in "defaultResponseOptions".
"dataFormat" property:Two of those versions occur in a request, and another occurs in a response. They all indicate how data is formatted.
"dataFormat"in the request in"responseOptions"determines how the"data"property in the response is formatted.Possible values include:
"arrays"This is the default and causes the server to return results as an array of arrays, which is the most efficient.
"objects"This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
"dataFormat"in the request in the"params"object notifies the server how the"sourceData"property is formatted in the request. This version is rarely used because of the default"autoDetect"behavior.Possible values include:
"arrays"This causes the server to return results as an array of arrays, which is the most efficient.
"objects"This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
"autoDetect"This is the default, and the server automatically detects the format of the data in the
"sourceData"property.
"dataFormat"in the response shows the client how the server formatted the"data"property.Possible values include:
"arrays"This is the default and causes the server to return results as an array of arrays, which is the most efficient.
"objects"This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
Example response
{
"result": {
"dataFormat": "objects"
}
}
The "fields" property is an array of objects. It is required when creating a table. Each object in the array defines a field by specifying its properties.
Example
"fields": [
{
"autoValue": "none",
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"defaultValue": null,
"nullable": false
}
]