Function descriptions

Function “update_data()”

Estimated reading: 3 minutes
bool update_data(array $update, numeric $typ=null, array $relation=null, bool $nometa=null);

Function to modify data records (./limbas_src/gtab/gtab.lib).

Parameters:

$update

  • Through valid settings in the $update array, the contents of any number of table fields from multiple tables can be modified in the database with just one function call. For each table field to be changed, an array element is needed. The index of the array element specifies explicitly the table field. The value of the array element is the new table field content for this table field.
$update = array();
$update["$tableID_1,$fieldID_1,$datasetID_1"] = $value_1;
$update["$tableID_2,$fieldID_2,$datasetID_2"] = $value_2;
.
.
.
$update["$tableID_n,$fieldID_n,$datasetID_n"] = $value_n;

Replace the following variables with appropriate values:

  • $tableID_1, $tableID_2, …, $tableID_n: Tabellen-ID des Feldes, dessen Inhalt verändert werden soll.
  • $fieldID_1, $fieldID_2, …, $fieldID_n: Feld-ID des Feldes, dessen Inhalt verändert werden soll.
  • $datasetID_1, $datasetID_2, …, $datasetID_n: Datensatz-ID des Feldes, dessen Inhalt verändert werden soll.
  • $value_1, $value_2, …, $value_n: Neuer Inhalt für das spezifizierte Tabellenfeld

If $datasetID is set to 0, Limbas will automatically create a new record.

$typ

$relation

  • Created using init_relation(). This parameter will only be used if the first parameter ($update) has a $datasetID of 0. As mentioned above, Limbas will create a new record and if $relation is set, the newly created record will automatically be linked to the record specified in $relation.

$nometa

  • Only relevant if the files table is updated. If $nometa is set, the metadata of the file will not be updated.

Return Value:

  • True: The changes have been successfully applied to the database. Note, that any invalid settings in the $update-array are filtered out prior to the actual database update.
  • False: An error occurred when changing the data in the database.
  • datasetID: A 0 was passed as datasetID inside the $update array. Limbas has created an new record and returns the new record’s ID.
  • Array: An error occured when changing some of the records. The array’s key is the table ID. The value is the ID of the record where the error occured.

Date conversion

The date conversion of Limbas includes the database, GUI, export/import and API. The date is converted into the expected format from the database for the various output channels, as well as into the database from various sources. The formats can differ depending on the database and localization and should always be converted using the available Limbas functions. The local date is defined in the user settings of the user that is signed in. The result of get_gresult() is the native output of the database and can be converted into the local date format using get_date(). Conversly, the local date format is expected for storing using update_data() and therefore does not need to be converted. So if a value that was returned using get_data() is to be written back into the database using update_data(), it has to be converted using get_date() first. Furthermore:

  • get_date($date) : Function for converting to the user’s local date.
  • convert_date($date) : Function for converting to then natively store in the database using SQL

Examples:

Output of get_data() with PostgreSQL : ‘2023:05:25’

gresult = get_gresult(1);

...
[1] => Array
     (
          [0] => '2023:05:25'
gresult = get_gresult(1);

...
[1] => Array
     (
          [0] => '2023:05:25'
$update["1,1,1"] = get_date($gresult[1][1][0]);
update_data(update);
Share this Doc

Function “update_data()”

Or copy link

CONTENTS