Child pages
  • Column Conversion

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Some scenarios require that a value be is stored in a database column in one form and written to and read from the database column in another form. Servoy supports this requirement with a feature called Column Conversion and called Column Conversion and it has three applications: String Serialization, Blob Serialization and Global Method Conversion.

Servoy also allows the contribution of a column converter by a java plugin.

...

Servoy supports object persistence using String Serialization, which involves the conversion of a runtime object into a string format, which can then persist be persisted in a database column. When the column is read from the database, the persistent string will be deserialized back into a runtime object. Because Servoy uses JavaScript as its scripting language, runtime objects will be serialized into standard JSON format.

...

Note

Remember that only by assigning an object to a data provider will you actually store the serialized string . You cannot be actually stored. It is not possible to set individual instance properties of an object to directly modify the serialized string.

Code Block
// For Example
my_data_provider.property = 'Foobar'; // This will have no effect on the data provider

// Instead
var obj = my_data_provider; // read the data provider into a runtime object
obj.property = 'Foo Bar';   // Modify the Object's instance properties
my_data_provider = obj;     // And reassign it to the data providerdatabaseManager.saveData();

Blob Serialization

Servoy provides Blob Serialization for persisting an object as a Blob. This involves converting the runtime object into a Blob, which is then persisted in the database column. When retrieving the column data from the database, the Blob is deserialized back into a runtime object.

See code example at String Serialization.

Note

Blob Serialization can only be used only for column type MEDIA.

Global Method Conversion

...

One can optionally specify the data type of the Object Value. This is useful in situations where the stored value is a different data type than the object value.

Example

The application talks to a database that is storing dates as 8-character text columns to support legacy applications. By setting the Converted Object Type setting to DATETIME, Servoy will treat the column as a date object. Moreover, the two conversion methods written by the developer should assume the Object Value is a Date object.

...