Beispiel #1
0
struct o_metadata * o_metadata_from_document(struct o_document *doc)
{
	struct o_metadata * meta = o_malloc(sizeof(struct o_metadata));
	struct o_document_value * schema = o_document_field_get(doc, "schema");
	meta->schema = o_schema_from_document((struct o_document *) o_document_value_get_link(schema));
	return meta;
}
Beispiel #2
0
void o_document_serialize_printer(struct o_document * doc, struct o_string_printer * printer)
{
	int names_count;
	char ** names = o_document_field_names(doc, &names_count);
	int i;
	for (i = 0; i < names_count; i++)
	{
		o_string_printer_print(printer, names[i]);
		o_string_printer_print(printer, ":");
		o_document_value_serialize(o_document_field_get(doc, names[i]), printer);
		if (i < names_count - 1)
			o_string_printer_print(printer, ",");
	}
}
void test_o_database_document_open_save_load_close()
{
	struct o_database_error_handler *errorHandler = o_database_error_handler_new(o_db_error_handler_function, 0);
	struct o_database_document * db = o_database_document_new_error_handler("remote:127.0.0.1/temp", errorHandler);
	o_database_document_open(db, "admin", "admin");
	struct o_document * doc = o_document_new();
	o_document_field_set(doc, "prova", o_document_value_string("prova"));
	struct o_record_id * id;
	o_database_document_save(db, doc, &id);
	struct o_document *readed_doc = o_database_document_load(db, id);
	struct o_document_value* readed_val = o_document_field_get(doc, "prova");
	assert_true(strcmp(o_document_value_get_string(readed_val), "prova") == 0, "the writed document not is the same of loaded");
	o_document_release(doc);
	o_document_release(readed_doc);
	o_database_document_close(db);
	o_database_document_free(db);
}