Skip to main content

"alterTable" (JSON Action)

JSON DB "alterTable" action modifies an existing table

The "alterTable" action changes, modifies, updates, or configures an existing table in a database. This action works for all FairCom products that include the FairCom database engine.

Important

  • Altering a table can break applications that use the table. Be sure to update all applications when you make the change.

  • "alterTable" temporarily blocks the table. Blocking the table has no effect on the JSON and SQL APIs. It may cause errors 798 or 799 to occur in applications that have opened the table using the ISAM or CTDB APIs.

  • Renaming a table or field causes errors to occur in processes that use the old names.

  • Changing a field's data type may cause errors in applications that read and write data to that field.

Request examples

Add fields

This example uses "alterTable" to define new fields of a table.

{
  "api": "db",
  "action": "alterTable",
  "params": {
    "tableName": "test1",
    "addFields": [
      {
        "name": "rename_me1",
        "type": "varchar",
        "length": 10,
        "nullable": false
      },
      {
        "name": "rename_me2",
        "type": "varchar",
        "length": 10,
        "nullable": false
      },
      {
        "name": "alter_me1",
        "type": "varchar",
        "length": 10,
        "nullable": false
      },
      {
        "name": "alter_me2",
        "type": "varchar",
        "length": 10,
        "nullable": false
      },
      {
        "name": "delete_me1",
        "type": "varchar",
        "length": 10,
        "nullable": false
      },
      {
        "name": "delete_me2",
        "type": "varchar",
        "length": 10,
        "nullable": false
      }
    ]
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

This example uses "alterTable" to modify existing table fields. Specifically, it changes the name of the "rename_me1" field to "description", changes the "length" value of the "alter_me1" field from its current value to 50 , and the "nullable" value from its current value to true.

{
  "api": "db",
  "action": "alterTable",
  "params": {
    "databaseName": "ctreeSQL",
    "ownerName": "admin",
    "tableName": "test1",
    "alterFields": [
      {
        "name": "rename_me1",
        "type": "varchar",
        "newName": "description"
      },
      {
        "name": "alter_me1",
        "type": "varchar",
        "length": 50,
        "nullable": true
      }
    ]
  },
  "requestId": "2",
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

This example uses "alterTable" to remove the "delete_me1" field.

{
  "requestId": "3",
  "api": "db",
  "action": "alterTable",
  "params": {
    "databaseName": "ctreeSQL",
    "ownerName": "admin",
    "tableName": "test1",
    "deleteFields": [
      "delete_me1"
    ]
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}
{
  "api": "db",
  "action": "alterTable",
  "params": {
    "ownerName": null,
    "tableName": "test1",
    "addFields": [
      {
        "name": "nested_json_object_or_array",
        "type": "json",
        "length": 65500
      },
      {
        "name": "boolean_byte",
        "type": "bit"
      },
      {
        "name": "signed_int8",
        "type": "tinyint"
      },
      {
        "name": "signed_int16",
        "type": "smallint"
      },
      {
        "name": "signed_int32",
        "type": "integer"
      },
      {
        "name": "signed_int64",
        "type": "bigint"
      },
      {
        "name": "ieee_base2float32",
        "type": "real"
      },
      {
        "name": "ieee_base2float64",
        "type": "float"
      },
      {
        "name": "signed32digits_base10_left32right0",
        "type": "number",
        "length": 32,
        "scale": 0
      },
      {
        "name": "signed32digits_base10_left0right32",
        "type": "number",
        "length": 32,
        "scale": 32
      },
      {
        "name": "signed32digits_base10_left20right12",
        "type": "number",
        "length": 32,
        "scale": 12
      },
      {
        "name": "signed32digits_base10_left30right2",
        "type": "money",
        "length": 32,
        "scale": 2
      },
      {
        "name": "signed32digits_base10_left28right4",
        "type": "money",
        "length": 32,
        "scale": 4
      },
      {
        "name": "date_yyyymmdd",
        "type": "date"
      },
      {
        "name": "time_hhmmss",
        "type": "time"
      },
      {
        "name": "datetime_yyyymmddthhmmss_nnnz",
        "type": "timestamp"
      },
      {
        "name": "fixed_string_10bytes",
        "type": "char",
        "length": 10
      },
      {
        "name": "variable_string_up_to_max65500bytes",
        "type": "varchar",
        "length": 65500
      },
      {
        "name": "variable_string_up_to_2GB",
        "type": "lvarbinary"
      },
      {
        "name": "fixed_binary_10bytes",
        "type": "binary",
        "length": 10
      },
      {
        "name": "variable_binary_up_to_max65500bytes",
        "type": "varbinary",
        "length": 65500
      }
    ],
    "alterFields": [
      {
        "name": "alter_me2",
        "type": "varchar",
        "length": 50,
        "nullable": true
      },
      {
        "name": "datetime_yyyymmddthhmmssfff",
        "autoValue": "timestampOnUpdateAndInsert"
      }
    ],
    "deleteFields": [
      "delete_me2"
    ],
    "transactionModel": "logTransactions",
    "growthExtent": 100000,
    "padValue": 0,
    "fieldDelimiterValue": 0,
    "createRecByteIndex": null,
    "tableFileExtension": ".dat",
    "indexFileExtension": ".idx",
    "changeIdField": null,
    "databaseName": null,
    "folder": null,
    "primaryKeyFields": [],
    "smallFile": null,
    "transactionId": null
  },
  "responseOptions": {
    "binaryFormat": "hex",
    "dataFormat": "objects",
    "numberFormat": "string"
  },
  "authToken": "replaceWithAuthTokenFromCreateSession",
  "apiVersion": "1.0",
  "requestId": "00000003",
  "debug": "max"
}

Add fields

{
  "result": {
    "dataFormat": "objects",
    "data": [
      {
        "changeIdField": "changeId",
        "createRecByteIndex": false,
        "databaseName": "ctreeSQL",
        "fieldDelimiterValue": 0,
        "fields": [
          {
            "autoValue": "incrementOnInsert",
            "defaultValue": null,
            "length": null,
            "name": "id",
            "nullable": false,
            "primaryKey": 1,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "changeid",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 50,
            "name": "name",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "rename_me1",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "rename_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "alter_me1",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "alter_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "delete_me1",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "delete_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          }
        ],
        "folder": ".\\ctreeSQL.dbs",
        "growthExtent": 0,
        "indexFileExtension": ".idx",
        "indexes": [
          {
            "collectStats": false,
            "compression": "off",
            "conditionalExpression": null,
            "databaseName": "ctreeSQL",
            "deferIndexing": false,
            "fields": [
              {
                "caseInsensitive": false,
                "name": "id",
                "reverseCompare": false,
                "sortDescending": false
              }
            ],
            "filename": "admin_test1.idx",
            "immutableKeys": false,
            "indexName": "id_pk",
            "indexNumber": 0,
            "ownerName": "admin",
            "tableName": "test1",
            "unique": true
          }
        ],
        "ownerName": "admin",
        "padValue": 0,
        "path": ".\\ctreeSQL.dbs\\admin_test1.dat",
        "primaryKeyFields": [
          "id"
        ],
        "smallFile": false,
        "tableFileExtension": ".dat",
        "tableName": "test1",
        "totalRecordCount": 12,
        "transactionModel": "logTransactions",
        "uid": 1181
      }
    ]
  },
  "errorCode": 0,
  "errorMessage": "",
  "authToken": "replaceWithAuthTokenFromCreateSession"
}
{
  "result": {
    "dataFormat": "objects",
    "data": [
      {
        "changeIdField": "changeId",
        "createRecByteIndex": false,
        "databaseName": "ctreeSQL",
        "fieldDelimiterValue": 0,
        "fields": [
          {
            "autoValue": "incrementOnInsert",
            "defaultValue": null,
            "length": null,
            "name": "id",
            "nullable": false,
            "primaryKey": 1,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "changeid",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 50,
            "name": "name",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "description",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "rename_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 50,
            "name": "alter_me1",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "alter_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "delete_me1",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "delete_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          }
        ],
        "folder": ".\\ctreeSQL.dbs",
        "growthExtent": 0,
        "indexFileExtension": ".idx",
        "indexes": [
          {
            "collectStats": false,
            "compression": "off",
            "conditionalExpression": null,
            "databaseName": "ctreeSQL",
            "deferIndexing": false,
            "fields": [
              {
                "caseInsensitive": false,
                "name": "id",
                "reverseCompare": false,
                "sortDescending": false
              }
            ],
            "filename": "admin_test1.idx",
            "immutableKeys": false,
            "indexName": "id_pk",
            "indexNumber": 0,
            "ownerName": "admin",
            "tableName": "test1",
            "unique": true
          }
        ],
        "ownerName": "admin",
        "padValue": 0,
        "path": ".\\ctreeSQL.dbs\\admin_test1.dat",
        "primaryKeyFields": [
          "id"
        ],
        "smallFile": false,
        "tableFileExtension": ".dat",
        "tableName": "test1",
        "totalRecordCount": 12,
        "transactionModel": "logTransactions",
        "uid": 1181
      }
    ]
  },
  "requestId": "2",
  "errorCode": 0,
  "errorMessage": "",
  "authToken": "replaceWithAuthTokenFromCreateSession"
}
{
  "result": {
    "dataFormat": "objects",
    "data": [
      {
        "changeIdField": "changeId",
        "createRecByteIndex": false,
        "databaseName": "ctreeSQL",
        "fieldDelimiterValue": 0,
        "fields": [
          {
            "autoValue": "incrementOnInsert",
            "defaultValue": null,
            "length": null,
            "name": "id",
            "nullable": false,
            "primaryKey": 1,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "changeid",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 50,
            "name": "name",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "description",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "rename_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 50,
            "name": "alter_me1",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "alter_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "delete_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          }
        ],
        "folder": ".\\ctreeSQL.dbs",
        "growthExtent": 0,
        "indexFileExtension": ".idx",
        "indexes": [
          {
            "collectStats": false,
            "compression": "off",
            "conditionalExpression": null,
            "databaseName": "ctreeSQL",
            "deferIndexing": false,
            "fields": [
              {
                "caseInsensitive": false,
                "name": "id",
                "reverseCompare": false,
                "sortDescending": false
              }
            ],
            "filename": "admin_test1.idx",
            "immutableKeys": false,
            "indexName": "id_pk",
            "indexNumber": 0,
            "ownerName": "admin",
            "tableName": "test1",
            "unique": true
          }
        ],
        "ownerName": "admin",
        "padValue": 0,
        "path": ".\\ctreeSQL.dbs\\admin_test1.dat",
        "primaryKeyFields": [
          "id"
        ],
        "smallFile": false,
        "tableFileExtension": ".dat",
        "tableName": "test1",
        "totalRecordCount": 12,
        "transactionModel": "logTransactions",
        "uid": 1181
      }
    ]
  },
  "requestId": "3",
  "errorCode": 0,
  "errorMessage": "",
  "authToken": "replaceWithAuthTokenFromCreateSession"
}
{
  "result": {
    "dataFormat": "objects",
    "data": [
      {
        "changeIdField": "changeId",
        "createRecByteIndex": false,
        "databaseName": "ctreeSQL",
        "fieldDelimiterValue": 0,
        "fields": [
          {
            "autoValue": "incrementOnInsert",
            "defaultValue": null,
            "length": null,
            "name": "id",
            "nullable": false,
            "primaryKey": 1,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "changeid",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 50,
            "name": "name",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "description",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "rename_me2",
            "nullable": false,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 50,
            "name": "alter_me1",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 50,
            "name": "alter_me2",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 65500,
            "name": "nested_json_object_or_array",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "json"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "boolean_byte",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "bit"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "signed_int8",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "tinyint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "signed_int16",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "smallint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "signed_int32",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "integer"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "signed_int64",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "bigint"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "ieee_base2float32",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "real"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "ieee_base2float64",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "float"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 32,
            "name": "signed32digits_base10_left32right0",
            "nullable": true,
            "primaryKey": 0,
            "scale": 0,
            "type": "number"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 32,
            "name": "signed32digits_base10_left0right32",
            "nullable": true,
            "primaryKey": 0,
            "scale": 32,
            "type": "number"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 32,
            "name": "signed32digits_base10_left20right12",
            "nullable": true,
            "primaryKey": 0,
            "scale": 12,
            "type": "number"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 32,
            "name": "signed32digits_base10_left30right2",
            "nullable": true,
            "primaryKey": 0,
            "scale": 2,
            "type": "money"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 32,
            "name": "signed32digits_base10_left28right4",
            "nullable": true,
            "primaryKey": 0,
            "scale": 4,
            "type": "money"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "date_yyyymmdd",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "date"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "time_hhmmss",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "time"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "datetime_yyyymmddthhmmss_nnnz",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "timestamp"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "fixed_string_10bytes",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "char"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 65500,
            "name": "variable_string_up_to_max65500bytes",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "variable_string_up_to_2gb",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "lvarchar"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 10,
            "name": "fixed_binary_10bytes",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "binary"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": 65500,
            "name": "variable_binary_up_to_max65500bytes",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "varbinary"
          },
          {
            "autoValue": "none",
            "defaultValue": null,
            "length": null,
            "name": "variable_binary_up_to_2gb",
            "nullable": true,
            "primaryKey": 0,
            "scale": null,
            "type": "lvarbinary"
          }
        ],
        "folder": ".\\ctreeSQL.dbs",
        "growthExtent": 100000,
        "indexFileExtension": ".idx",
        "indexes": [
          {
            "collectStats": false,
            "compression": "off",
            "conditionalExpression": null,
            "databaseName": "ctreeSQL",
            "deferIndexing": false,
            "fields": [
              {
                "caseInsensitive": false,
                "name": "id",
                "reverseCompare": false,
                "sortDescending": false
              }
            ],
            "filename": "admin_test1.idx",
            "immutableKeys": false,
            "indexName": "id_pk",
            "indexNumber": 0,
            "ownerName": "admin",
            "tableName": "test1",
            "unique": true
          }
        ],
        "ownerName": "admin",
        "padValue": 0,
        "path": ".\\ctreeSQL.dbs\\admin_test1.dat",
        "primaryKeyFields": [
          "id"
        ],
        "smallFile": false,
        "tableFileExtension": ".dat",
        "tableName": "test1",
        "totalRecordCount": 12,
        "transactionModel": "logTransactions",
        "uid": 1181
      }
    ]
  },
  "requestId": "5",
  "debugInfo": {
    "request": {
      "api": "db",
      "action": "alterTable",
      "params": {
        "databaseName": "ctreeSQL",
        "ownerName": "admin",
        "tableName": "test1",
        "addFields": [
          {
            "name": "nested_json_object_or_array",
            "type": "json",
            "length": 65500
          },
          {
            "name": "boolean_byte",
            "type": "bit"
          },
          {
            "name": "signed_int8",
            "type": "tinyint"
          },
          {
            "name": "signed_int16",
            "type": "smallint"
          },
          {
            "name": "signed_int32",
            "type": "integer"
          },
          {
            "name": "signed_int64",
            "type": "bigint"
          },
          {
            "name": "ieee_base2float32",
            "type": "real"
          },
          {
            "name": "ieee_base2float64",
            "type": "float"
          },
          {
            "name": "signed32digits_base10_left32right0",
            "type": "number",
            "length": 32,
            "scale": 0
          },
          {
            "name": "signed32digits_base10_left0right32",
            "type": "number",
            "length": 32,
            "scale": 32
          },
          {
            "name": "signed32digits_base10_left20right12",
            "type": "number",
            "length": 32,
            "scale": 12
          },
          {
            "name": "signed32digits_base10_left30right2",
            "type": "money",
            "length": 32,
            "scale": 2
          },
          {
            "name": "signed32digits_base10_left28right4",
            "type": "money",
            "length": 32,
            "scale": 4
          },
          {
            "name": "date_yyyymmdd",
            "type": "date"
          },
          {
            "name": "time_hhmmss",
            "type": "time"
          },
          {
            "name": "datetime_yyyymmddthhmmss_nnnz",
            "type": "timestamp"
          },
          {
            "name": "fixed_string_10bytes",
            "type": "char",
            "length": 10
          },
          {
            "name": "variable_string_up_to_max65500bytes",
            "type": "varchar",
            "length": 65500
          },
          {
            "name": "variable_string_up_to_2GB",
            "type": "lvarchar"
          },
          {
            "name": "fixed_binary_10bytes",
            "type": "binary",
            "length": 10
          },
          {
            "name": "variable_binary_up_to_max65500bytes",
            "type": "varbinary",
            "length": 65500
          },
          {
            "name": "variable_binary_up_to_2GB",
            "type": "lvarbinary"
          }
        ],
        "alterFields": [
          {
            "name": "alter_me2",
            "type": "varchar",
            "length": 50,
            "nullable": true
          }
        ],
        "deleteFields": [
          "delete_me2"
        ],
        "transactionModel": "logTransactions",
        "growthExtent": 100000,
        "padValue": 0,
        "fieldDelimiterValue": 0,
        "createRecByteIndex": false,
        "tableFileExtension": ".dat",
        "indexFileExtension": ".idx"
      },
      "apiVersion": "1.0",
      "requestId": "5",
      "responseOptions": {
        "dataFormat": "objects"
      },
      "debug": "max",
      "authToken": "replaceWithAuthTokenFromCreateSession"
    },
    "serverSuppliedValues": {
      "databaseName": "ctreeSQL",
      "ownerName": "admin"
    },
    "errorData": {
      "errorData": null
    },
    "warnings": []
  },
  "errorCode": 0,
  "errorMessage": "",
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

Use the alterTable JSON API action to alter an existing table in a database

API actionsJSON DB APIJSON Actiontable actionsalter tablealterTable

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.

Table 1. alterTable "params" properties summary

Property

Description

Default

Type

Limits (inclusive)

addFields

(optional) adds new fields to the table and specifies their properties

[]

array of objects

addFields
.autoValue

(optional) specifies when and how the server automatically sets the field value.

"none"

string

"none"
"incrementOnInsert"
"timestampOnInsert"
"timestampOnUpdate"
"timestampOnUpdate AndInsert"
"changeid"
addFields
.defaultValue

(optional) specifies the default value of a field. It is used when a record is inserted without specifying a value for the field. The server coerces the string value into the proper field type. It is a string because a string can represent any type of data.

""

string

0 to 65,500 bytes

addfields
.length

(optional) specifies the length of a field's value in a record.

null

integer

1 to 65500

addFields
.name

specifies the name of an existing field in a table.

Required - No default value

string

0 to 64 bytes

addFields
.newName

(optional) specifies a new name for an existing field in a table.

""

string

0 to 64 bytes

addFields
.newPosition

(optional) changes the physical position of a field in a table.

-1

integer

-1 to 2500

addFields
.nullable

(optional) allows a field to contain a NULL value when true.

true

Boolean

true
false
addFields
.scale

(optional) for "number" and "money" field types, specifies the number of places to the right of the decimal point.

null

integer

0 to 32

addFields
.type

specifies the data type of the field.

Required - No default value

string

"json"
"bit"
"tinyint"
"smallint"
"integer"
"bigint"
"real"
"float"
"number"
"money"
"date"
"time"
"timestamp"
"char"
"varchar"
"lvarchar"
"binary"
"varbinary"
"lvarbinary"

alterFields

(optional) defines fields to alter in a table.

[{"name":""}]

array of objects

changeIdField

(optional) specifies the field name used for change-tracking.

""

string

1 to 64 bytes

createRecByteIndex

(optional) creates a special index for quickly walking variable-length records backward when true.

false

Boolean

true
false

databaseName

(optional) specifies the name of a database.

Defaults to the "defaultDatabaseName" value that is set during "createSession". If no default is set during "createSession", then "faircom" is used.

string

1 to 64 bytes

deleteFields

(optional) contains the names of fields to remove from a table.

[]

array

1 to 64 bytes

fieldDelimiterValue

(optional) delimits fields internally for FairCom use.

0

integer

0 to 255

growthExtent

(optional) specifies the number of bytes that a server uses to extend a file by using a larger number to minimize the number of times a file needs to be extended or using a smaller number to minimize the amount of unused space in a file.

0

integer

0 to 2147483647

indexFileExtension

(optional) specifies the file system extension (must contain the dot before the extension) to use for a table's index files.

".idx"

string

0 to 64 bytes

ownerName

(optional) specifies the owner of the object in the database.

""

string

0 to 64 bytes

padValue

(optional) pads all "char" and "binary" fields in a table.

0

integer

0 to 255

primaryKeyFields

(optional) specifies the fields to use for the table’s primary key.

[]

array of strings

["field1", …,"fieldN"]

tableFileExtension

(optional) specifies the file extension (must contain the dot before the extension) that the server assigns to the table's data file.

".dat"

string

0 to 64 bytes

tableName

specifies the name of a table.

Required - No default value

string

1 to 64 bytes

transactionModel

(optional) specifies how the server processes transactions for a table.

"logTransactions"

string

"logTransactions"
"ramTransactions"
"noTransactions"


The "addFields" property is optional. It is an array of objects. It allows you to add new fields to a table and specify their properties. Each object in the array defines the properties of a field being added.

Example

"addFields": [
  {
    "autoValue": "none",
    "name": "field1",
    "type": "varchar",
    "length": 50,
    "scale": null,
    "defaultValue": null,
    "nullable": false,
    "primaryKey":1
  }
]

The "alterFields" property is optional. It is an array of objects. It allows you to modify properties of existing fields in a table. Each object in the array defines the modifications to the named field.

In this example, the field named "field1" is being modified.

Example

"alterFields": [
  {
    "autoValue": "none",
    "name": "field1",
    "type": "varchar",
    "newName": "address",
    "newPosition": 5,
    "length": 50,
    "scale": null,
    "defaultValue": null,
    "nullable": false
  }
]

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": 1 to 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 value of this property is the name of the field used for the change-tracking functionality.

If the table already has a change-tracking field, this new field is now used instead for change-tracking.

The "createRecByteIndex" property is an optional Boolean that creates a special index for quickly walking variable-length records backward when set to true. It defaults to false.

Note

It is not needed for fixed-length records.

"params": {
  "createRecByteIndex": true
  }

The "databaseName" property is an optional string that specifies the database that contains the tables. It defaults to the database name supplied at login.

Note

In the API Explorer, "defaultDatabaseName" is set to "ctreeSQL" in the "createSession" action that happens at login.

  • A zero-length "databaseName" is invalid.

  • Its length limit is from 0 to 64 bytes.

  • If the "databaseName" property is omitted or set to null, the server will use the default database name specified at login.

  • If no default database is specified during "createSession", "databaseName" will be set to the "defaultDatabaseName" value that is specified in the services.json file.

"params": {
  "databaseName": "mainDatabase"
  }

The "deleteFields" property is an optional array of strings. Each string is the name of a field to remove from a table.

  • Each string is 1 to 64 bytes.

  • Removing a field destroys the data in that field.

  • A zero-length "fieldName" is invalid.

The "fieldDelimiterValue" property is a decimal number from 0 to 255. It is optional. If omitted, it defaults to 0. The only reason to change it is for backward compatibility with legacy c-tree files.

Note

Do not set this value without first contacting FairCom customer support.

"params": {
  "fieldDelimiterValue": 255
}

The "growthExtent" property is an optional integer from 0 to 2,147,483,647. It is the number of bytes that a server uses to increase a file's size. The default value is 0.

  • A file is extended when adding or updating a record, which requires the file to grow larger.

  • Use a larger number to minimize the number of times a file needs to be extended.

  • Use a smaller number to minimize the amount of unused space in a file.

{
  "api": "db",
  "action": "createTable",
  "params": {
    "growthExtent": 64000000
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

The "indexFileExtension" property is an optional string from 0 to 64 bytes. It specifies the file system extension to use for a table's index files. If omitted, it defaults to ".idx".

Note

If set to a zero-length string, then newly created index files will have no extension.

"params": {
  "indexFileExtension": ".tidx"
}

This property is an integer that specifies the length of a table field. See also Data types.

It is required to set the length of the following fixed-length data types:

  • "char" (between 1 and 65,500 bytes)

  • "binary" (between 1 and 65,500 bytes).

It is required to set the maximum length for the following variable-length data types:

  • "varchar" (between 1 and 65,500 bytes).

  • "varbinary" (between 1 and 65,500 bytes).

It is optional to set the maximum length of the "json" data type, which defaults to 2 gigabytes. You may set its maximum length between 1 and 65,500 bytes.

It is optional to set the maximum length of the "number" and "money" data types, which default to 32 numeric digits. You can change the "length" to limit the precision of the number of digits to the left of the decimal point.

  • "number" and "money" are always stored as 32 decimal digits. Using a length less than 32 does not benefit storage.

  • You may optionally use "length" to specify fewer than 32 total digits to limit the maximum number of digits in the field. For example, a length of 4 allows numbers such as 12, 123, 1234, 12.34, and 0.1234, but not 12345, 123.45, or 0.12345.

  • You must always use "scale" to set the number of decimal places to the right of the decimal point, which must be less than or equal to the length. For example, "money" with a scale of 2, defaults to 30 digits to the left of the decimal point and 2 digits to the right, and "money" with a scale of 4, defaults to 28 digits to the left of the decimal point and 4 digits to the right.

 The "length" property is ignored for other data types because they have predefined lengths. For example, "lvarchar" and "lvarbinary" always have a maximum length of 2GB.

Note

"nchar" and "nvarchar" are only supported in FairCom's special UCS-2 server edition. These field types allocate two bytes to each character. Because UCS-2 is inefficient, FairCom recommends its standard database, which supports modern, efficient, variable-length UTF-8 characters.

  • "nchar" can be between 1 and 65,500 bytes.

  • "nvarchar" can be between 1 and 65,500 bytes.

Request example

Create a table that contains all field types that use the "length" property.

"fields": [
  {
    "name": "a",
    "type": "char",
    "length": 16
  },
  {
    "name": "b",
    "type": "varchar",
    "length": 65500
  },
  {
    "name": "c",
    "type": "lvarchar"
  },
  {
    "name": "d",
    "type": "binary",
    "length": 16
  },
  {
    "name": "e",
    "type": "varbinary",
    "length": 65500
  },
  {
    "name": "f",
    "type": "lvarbinary"
  },
  {
    "name": "g",
    "type": "json"
  },
  {
    "name": "h",
    "type": "json",
    "length": 65500
  },
  {
    "name": "j",
    "type": "number",
    "scale": 32
  },
  {
    "name": "k",
    "type": "number",
    "scale": 4
  },
  {
    "name": "i",
    "type": "number",
    "length": 12,
    "scale": 2
  },
  {
    "name": "l",
    "type": "money",
    "scale": 2
  },
  {
    "name": "m",
    "type": "money",
    "scale": 4
  },
  {
    "name": "n",
    "type": "money",
    "length": 12,
    "scale": 2
  }
] 

The optional "name" property is a case-sensitive string from 1 to 64 bytes in length. It is a new name for an existing field in a table. A field is not renamed when "name" is zero-length or omitted..

  • A zero-length "name" is invalid.

  • A client should enforce the uniqueness of the "name".

Request example

"fields": [
  {
    "name": "field1",
    "type": "varchar",
    "newName": "company"
  }
]

The optional property is a case-sensitive string from 1 to 64 bytes in length. It is what is used to replace the name of an existing field.

  • A zero-length "newName" is invalid.

  • A client should enforce the uniqueness of the "newName".

Request example

"fields": [
  {
    "name": "company",
    "type": "varchar",
    "newName": "Corporation"
  }
]

This optional property is a signed 16-bit integer from -1 to 2500. It changes the physical position of a field in a table. The first field is position 0. A field is not moved to a new position when its value is -1 or when "newPosition" is omitted. A table may contain up to 2500 fields..

Request example

"fields": [
  {
    "name": "field1",
    "type": "varchar",
    "newPosition": 100
  }
]

The "nullable" property is an optional Boolean. When true, it allows a field to contain a NULL value. To require a field to have a non-null value, set "nullable" to false.

"fields": [
  {
    "name": "company",
    "type": "varchar",
    "nullable": true 
  }
]

The "ownerName" property is an optional string from 1 to 64 bytes that identifies the user who owns an object (see Object owner). If it is omitted or set to "" or null, the server uses the default owner name supplied during the "createSession" action or uses the account's "username" as the owner name.

"params": {
  "ownerName": "SuperUser"
}

The "padValue" property is a decimal number from 0 to 255. It is optional. If omitted, it defaults to 0.

  • The server uses this decimal number as a byte value to pad all "char" and "binary" fields in a table when the contents of these fixed-length fields is shorter than the field size.

  • All fixed-length fields in a table are padded with the same pad value. 

    Note

    Padding does not apply to the variable-length fields of the table, including "varchar", "lvarchar", "varbinary", and "lvarbinary".

Reasons to use fixed-length fields:
  • Fixed-length fields are an optimization for the specific use case of storing fixed-length data that matches the exact length of the field.

  • For fixed-length fields, the following use cases work well:

    • Bit flags

      A "binary" field is useful for efficiently storing a fixed set of bit flags where each bit represents a different on/off setting.

    • Legacy identifiers

      A "char" field is useful for efficiently storing legacy fixed-length identifiers, such as a VIN number, where characters in specific positions represent different subsets of data.

    • Very small strings

      A "char" field is useful for efficiently storing strings that are smaller than six characters because they do not have the overhead of requiring two extra bytes to track the length of the field.

  • A fixed-length field is more efficient than a variable-length field because it does not require extra bytes to track the length of the field:

    • The "varchar" and "varbinary" fields require two extra bytes to track the length of the field, which can be up to 64K. 

    • The "lvarchar", "lvarchar",  and "lvarbinary" fields require four extra bytes to track the length of the field, which can be up to 2GB.

Reasons for padding fixed-length fields:
  • Padding is required for fixed-length fields because data can be assigned to a field with a shorter length than the field's length.

  • Padding is useful in the following use cases:

    • The default padding value of 0 in a "char" field makes a fixed-length string behave like a variable-length string. It works because the database can treat a fixed-length string as a null-terminated string that can be smaller than the fixed width.

    • A padding value of 32 in a "char" field is the ASCII space character, which automatically left-aligns fixed-length strings.

    • The default padding value of 0 in a "binary" field works for bit flags when zero is the desired default state of a bit. Otherwise, padding in a "binary" field is rarely a good thing because it alters the binary value.

How padding works:
  • When the server assigns a value to a "char" or "binary" field (which are fixed-length field types), it puts the value in the field starting on the left and uses the pad value to fill in any remaining bytes on the right.

  • In other words, when the number of bytes in a value being assigned to a "char" or "binary" field is less than the number of bytes in the field, the server fills in the remaining bytes with the pad value.

CHAR padding behavior:
  • The default pad value of 0 causes a special padding behavior for "char" fields.

    • It causes the JSON DB API to treat fixed-length string fields as if they were variable-length strings with a maximum length.

    • In other words, the same string value going into a "char" field comes out the same, no padding is added — for example, when a table's "padValue" is set to 0 and a JSON string of "12" is inserted into a "char" field, the JSON string of "12" is returned from that field.

  • When you want the server to add padding to strings that are stored in a "char" field, set the "padValue" property to a non-zero number that is the ASCII character you want to pad the string.

    For example, set "padValue" to 32 to pad strings with the space character. When a table's "padValue" is set to 32 and a JSON string of "12" is inserted into a "char" field with a "length" of 4 bytes, the JSON string of "12 " is returned from that field.

BINARY padding behavior:
  • The server always applies padding when the number of bytes in a binary value is less than the number of bytes in the fixed-length, "binary" field. When the server adds padding to a binary value, it permanently modifies the binary value. If this is not desirable, ensure the binary value exactly matches the size of the "binary" field.

  • The JSON DB API always returns the entire stored value of a "binary" field. This binary value is encoded as a JSON array of bytes or a string containing a base64 or hexadecimal representation of the binary value. The length of the JSON string encoded in base64 or hexadecimal is always longer than the length of the binary field.

  • If a table's "padValue" is set to 0, and a binary value of 0x3132 is stored in a "binary" field with a "length" of 4 bytes, the server pads the value and stores the value of 0x31320000 into the field. When the value is returned by the JSON DB API, it is returned as 0x31320000. Thus, padding alters a binary value when the value is smaller than the field. The default padding behavior of a "binary" field is different from the default padding behavior of a "char" field because the server can assume that an ASCII NULL padding value is a string terminator, but it cannot assume the same for a binary value.

Example 1. Turning off padding

If a table's "padValue" is set to 0, the ASCII NULL character with the hexadecimal value of 0x00 is used to pad unfilled byte positions. So when the JSON string "12" is inserted into a "char" field that has a "length" of 4 bytes, the binary value of 0x31320000 is stored in the field. The value returned is a JSON string of "12" because it recognizes the ASCII NULL character as a string terminator.

In other words, the ASCII NULL character allows the server to automatically trim the length of a string that is stored in a fixed-length field before it returns the string in JSON. So, by default, the same JSON string inserted into a "char" field is always returned by the JSON DB API. This behavior is safe for UTF-8 strings, which is the string encoding used by JSON.



Example 2. Padding s a string with spaces

When a table's "padValue" is set to 32, which is hexadecimal 0x20, and a JSON string of "12" is assigned to a "char" field that has a "length" of 4 bytes, the binary value of 0x31322020 is stored in the field. When the JSON DB API retrieves the value, it returns it as a JSON string of "12  ". This is because the value 32 is the ASCII space character " ".



Example 3. Padding a string with hyphens

If a table's "padValue" is set to 54, which is hexadecimal 0x36, and a JSON string of "12" is assigned to a "char" field that has a "length" of 4 bytes, the binary value of 0x31323636 is stored in the field. When the JSON DB API retrieves the value, it returns it as a JSON string of "12--". This is because the value 54 is the ASCII character "-".



Example 4. Manually padding a string

Assigning "12**" to a "char" field that has a "length" of 4 bytes stores "12**" into the field regardless of the table's "padValue".



Example 5. Right-aligning a value in a string

Assigning " $12.34" to a "char" field that has a "length" of 8 bytes stores " $12.34" into the field regardless of the table's "padValue".



Example 6. Avoiding padding

Use the variable-length char and binary field types ("varchar", "lvarchar", "lvarchar", "varbinary", and "lvarbinary"). 

Each of these field types is stored in the table with length information, so the data returned matches the data stored.



Request example

{
  "api": "db",
  "action": "createTable",
  "params": {
    "padValue": 32
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

This property specifies the fields to use for the table’s primary key.

The "primaryKeyFields" property creates a unique "primary key" index on these fields.
The index is named "field1_fieldN_pk" where field1 through fieldN are the names of the specified fields.
When the table already has a primary key index, altering a table with this property may create an additional "primary key index".
The user can use "deleteIndexes" to remove extra indexes.

The "scale" property is required only for the "number" and "money" data types because they require fixed precision. It is ignored for all other data types. See also Data types. The scale specifies the number of fixed decimal places to the right of the decimal point. Its value must always be less than or equal to the field's length.

The value of "scale" must be an integer from 0 to the number of digits specified by the "length" property. The maximum length is 32, which allows the scale to have up to 32 digits. The default value of length is 32.

A scale of 0 creates an integer number. A scale equal to the length creates a number that can only have a fractional value.

The "money" field type must have a scale of 2 or 4.

You may optionally use the "length" property to specify fewer than 32 total digits to limit the total number of digits available to the number. A length limit reduces the maximum size of the scale. For example, a length of 3 allows the scale of a "number" to be 0, 1, 2, or 3. 

Table 2. Example numbers allowed in "number" and "money" field types with a length of 4 and a scale from 0 to 4.

"length"

"scale"

Zero with Fixed Precision

Closest Positive Number to Zero

Closest Negative Number to Zero

Furthest Positive Number from Zero

Furthest Negative Number from Zero

Furthest Positive Fractional Number from Zero

Furthest Negative Fractional Number from Zero

Miscellaneous Examples

4

0

0

1

-1

9999

-9999

N/A

N/A

1234; 12

4

1

0.0

0.1

-0.1

999.9

-999.9

0.9

-0.9

123.4; 12.0

4

2

0.00

0.01

-0.01

99.99

-99.99

0.99

-0.99

12.34; 12.00

4

3

0.000

0.001

-0.001

9.999

-9.999

0.999

-0.999

1.234; 1.200

4

4

0.0000

0.0001

-0.0001

0.9999

-0.9999

0.9999

-0.9999

0.1234; 0.1200



Request Example

Create a table that contains all field types that use the "scale" property.

"fields": [
  {
    "name": "j",
    "type": "number",
    "scale": 32
  },
  {
    "name": "k",
    "type": "number",
    "scale": 4
  },
  {
    "name": "i",
    "type": "number",
    "length": 12,
    "scale": 2
  },
  {
    "name": "l",
    "type": "money",
    "scale": 2
  },
  {
    "name": "m",
    "type": "money",
    "scale": 4
  },
  {
    "name": "n",
    "type": "money",
    "length": 12,
    "scale": 2
  }
]

The "tableFileExtension" property is an optional string from 0 to 64 bytes. It specifies the file system extension to use for a table's data files. If omitted, it defaults to ".dat".

Note

If set to a zero-length string, then newly created data files will have no extension.

Example request

"params": {
  "tableName": "test1",
  "tableFileExtension": ".dat"
}

The required "tableName" property is a string containing the name of a table.

See table name in System limits for the table naming requirements and limitations.

Example request

"params": {
  "tableName": "ctreeTable"
}

The "transactionModel" property is an optional, case-insensitive, string enum. It defines how the server processes transactions for a table. The default is "logTransactions".

Possible values:
  • "logTransactions"

    This persists data to data files and writes transaction changes to transaction logs. It supports commit and rollback transactions and data replication. It will not lose data during an unplanned outage. It provides the most durability and the most capabilities, but is slower than the other settings.

  • "ramTransactions"

    This supports commit and rollback transactions in RAM while persisting data to data files. It does not use a transaction log, which makes it even faster, but an unplanned outage may lose or corrupt unwritten data.

  • "noTransactions"

    This does not support transactions but still persists data to disk, making it even faster. However, an unplanned outage may lose or corrupt unwritten data.

Example request

{
  "api": "db",
  "action": "createTable",
  "params": {
    "transactionModel": "noTransactions"
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

The required "type" property specifies the field's data type. It has no default value. See Data types for the limits, valid values, and whether "length" and "scale" are required.

Request example

"fields": [
  {
    "name": "j",
    "type": "number"
  }
]
Table 3. alterTable "result" properties summary

Property

Description

Type

Limits (inclusive)

data

contains an array or object that the server returns, such as records returned by a query. It is an empty array when no results are available.

array

Its contents are determined by the action

dataFormat

defines the format of the data in the "data" property.

string

"autoDetect"
"arrays"
"objects"


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".

There are three different (but similar) versions of the "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"
  }
}

You cannot modify a table while it is in use. When a table has no activity for a default of 2 seconds, it will be closed so you can modify it.

  • When a table is in use, the following actions return an error, such as -8 or 4012:

    • "alterTable"

    • "rebuildTables"

    • "deleteTables"

    • "createIndex"

    • "deleteIndexes"

    • "rebuildIndexes"

    • "runSqlStatements"

  • A table is in use when any account is performing one or more of the following actions with the table:

    • "insertRecords"

    • "updateRecords"

    • "deleteRecords"

    • "truncateRecords"

    • "getRecords..."

    • Has open cursors on the table.

    • Has open transactions on the table (such "createTransaction").

  • Modify the SQL_IDLE_WAKE startup configuration setting to change the number of seconds the server waits before closing a table. A larger number keeps the table open longer for better performance. A smaller number allows you to modify the table sooner.

  • Modify the SQL_IDLE_WAKE startup configuration setting to change the number of tables the server keeps open after they are no longer being actively used. A larger number caches more tables and improves performance. A smaller number allows you to modify tables sooner.