Skip to main content

"listDatabases"

JSON DB "listDatabases" action retrieves all databases on the server

The "listDatabases" action retrieves databases on the server. You can optionally filter which databases are returned by specifying a complete or partial database name. The results are sorted in ascending order by default.

Request examples

Minimal request

{
    "api":"db",
    "action": "listDatabases",
    "authToken": "replaceWithAuthTokenFromCreateSession"
}
{
  "api": "db",
  "apiVersion": "1.0",
  "requestId": "2",
  "authToken": "replaceWithAuthTokenFromCreateSession",
  "action": "listDatabases",
  "params": {
    "partialDatabaseName": "ctr",
    "skipRecords": 0,
    "maxRecords": 20
  },
  "responseOptions": {
    "binaryFormat": "hex",
    "dataFormat": "objects",
    "numberFormat": "string"
  },
  "debug": "max"
}
{
  "authToken": "replaceWithValidAuthtoken",
  "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": "ctreeSQL",
        "path": ".\\ctreeSQL.dbs\\SQL_SYS",
        "uid": 999
      },
      {
        "databaseName": "faircom",
        "path": ".\\faircom.dbs\\SQL_SYS",
        "uid": 1001
      }
    ]
  },
  "requestId": "1",
  "debugInfo": {
    "request": {
      "authToken": "replaceWithValidAuthtoken",
      "api": "db",
      "action": "listDatabases",
      "requestId": "1",
      "debug": "max"
    },
    "serverSuppliedValues": {
      "databaseName": null,
      "ownerName": null
    },
    "errorData": {
      "errorData": null
    },
    "warnings": []
  },
  "errorCode": 0,
  "errorMessage": ""
}
{
  "authToken": "replaceWithValidAuthtoken",
  "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": "ctreeSQL",
        "path": ".\\ctreeSQL.dbs\\SQL_SYS",
        "uid": 999
      }
    ]
  },
  "requestId": "2",
  "debugInfo": {
    "request": {
      "authToken": "replaceWithValidAuthtoken",
      "api": "db",
      "action": "listDatabases",
      "params": {
        "partialDatabaseName": "ctr",
        "skipRecords": 0,
        "maxRecords": 20
      },
      "apiVersion": "1.0",
      "requestId": "2",
      "responseOptions": {
        "binaryFormat": "hex",
        "dataFormat": "objects",
        "numberFormat": "string"
      },
      "debug": "max"
    },
    "serverSuppliedValues": {
      "databaseName": null,
      "ownerName": null
    },
    "errorData": {
      "errorData": null
    },
    "warnings": []
  },
  "errorCode": 0,
  "errorMessage": ""
}

Use the listDatabases API action to retrieve all databases on the server

API actionsJSON DB APIjsonActionlist databaseslistDatabases

The "params" property is an object that contains an action's parameters. Each action defines its own required and optional properties.

Property summary

Table 1. "params" property summaries

Element

Description

Default

Type

Limits (inclusive)

maxRecords

specifies the maximum number of records to return from an action. -1 returns all records

20

integer

-1 to 65535

partialDatabaseName

filters the returned databases by applying partial matches to the beginning of database names

""

string

0 to 64 bytes

skipRecords

specifies the number of records to skip over in the results before returning records

0

integer

0 to 9223372036854775807



The "maxRecords" is an optional integer from -1 to 65,535 that sets the maximum number of records to return from an action. It is used in query actions to paginate the query results when returning records directly. The default for most actions is to return 20 records.

Important

-1 returns all records and should be used very carefully because a large query can return so many records that it eventually times out and wastes server and client resources.

  • When present, "maxRecords" works in conjunction with the "skipRecords" (and, when applicable, "reverseOrder") properties to paginate results.

  • "maxRecords" returns an error when "returnCursor" is true.

    Note

    This does not apply to the actions where "returnCursor" is not present.

  • When returning a cursor, retrieve records using the "getRecordsFromCursor" action.

  • A value of 0 for "maxRecords" is not useful because it causes the action to return no records.

  • "maxRecords" is ignored by the "getRecordsByIds" action.

The "partialDatabaseName" property filters the returned databases by applying partial matches to the beginning of database names. It is an optional string from 0 to 64 bytes. It defaults to an empty string.

  • The "listDatabases" action returns databases with names that match the beginning of this string.

  • A zero-length string matches all database names.

  • Since it defaults to an empty string you can omit the "partialDatabaseName" property to return all databases.

The "skipRecords" property is an optional integer from 0 to 9,223,372,036,854,775,807. It is used in query actions to paginate the query results when returning records directly. It defaults to 0.

  • It specifies the number of records to skip over in the results before returning records.

  • It works with "maxRecords" and "reverseOrder".

  • It is ignored when "returnCursor" is true.

    Note

    This does not apply to the actions where "returnCursor" is not present.

Properties summary

Table 2. "result" properties summary

Property

Description

Type

Limits (inclusive)

data

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

array

Its contents are determined by the action

dataFormat

specifies the format of the data in the "data" property

string

"autoDetect"
"arrays"
"objects"

fields

specifies an array of objects set by the server, where each object is the definition of a field in a table defining the details of each field returned by a query

array

fields
.autoValue

specifies when and how the server automatically sets the field value

string

"none"
"incrementOnInsert"
"timestampOnInser"
"timestampOnUpdate"
"timestampOnUpdateAndInsert"
"changeid"
fields
.defaultValue

specifies the default value of a field

string

0 to 65,500 bytes

fields
.length

specifies the length of a field's value in a record

integer

1 to 65500 

fields
.name

specifies the new name of the field

string

0 to 64 bytes

fields
.nullable

allows a field to contain a NULL value when true

Boolean

true
false
fields
.primaryKey

adds a field to the specified ordinal position of the table's primary key when > 0

integer

0 to 32

fields
.scale

specifies the number of places to the right of the decimal point

integer

0 to 32

fields
.type

specifies the type of field

string

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


The "dataFormat" property is an optional, case-insensitive string enum that defines the format of the response in 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 inside "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 causes the server to automatically detect 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.

The "fields" property is a required array of field-type objects. There is one object for each top-level field in the array. Each object identifies the actual data type of the field as stored in the database.

A field-type object is used when creating a table. It contains one object for each field definition returned in the data.

Full request example

"fields": 
[
    {
      "name": "name",
      "type": "varchar",
      "length": 50,
      "scale": null,
      "defaultValue": null,
      "nullable": false,
      "primaryKey":1
   }
]

Full response example

"fields":
[
  {
      "name": "id",
      "type": "bigint",
      "length": null,
      "scale": null,
      "autoValue": "none",
      "defaultValue": null,
      "nullable": false,
      "primaryKey": 1
  }
]

This property controls when and how the server automatically sets the field value.

Specify only one of these values per field.

  • "none" indicates the server does not automatically set the field's value.

  • "incrementOnInsert" indicates 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 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".

  • "timestampOnUpdate" indicates the server automatically sets a field’s value to the current date and time of an update. It applies only to timestamp fields.

  • "timestampOnUpdateAndInsert" indicates 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.