GdaDdlCreator

GdaDdlCreator — Object to constract database representation from an xml file or by reading the existing datatabase

Stability Level

Stable, unless otherwise indicated

Properties

gchar * schema-name Read / Write

Object Hierarchy

    GObject
    ╰── GdaDdlCreator

Includes

#include <libgda/libgda.h>

Description

This is a main object that represents overall database. In can be constracted from an xml file using gda_ddl_creator_parse_file() or gda_ddl_creator_parse_file_from_path(). It can also be constracted from an open connection using gda_ddl_creator_parse_cnc(). The database can be updated using gda_ddl_creator_perform_operation() and dumped to a file using gda_ddl_creator_write_to_path() and gda_ddl_creator_write_to_file().

Functions

gda_ddl_creator_error_quark ()

GQuark
gda_ddl_creator_error_quark (void);

gda_ddl_creator_new ()

GdaDdlCreator *
gda_ddl_creator_new (void);

Create new instance of GdaDdlCreator. The object can be destroyed using gda_ddl_creator_free() method.

Returns

a new instance of GdaDdlCreator

Since: 6.0


gda_ddl_creator_free ()

void
gda_ddl_creator_free (GdaDdlCreator *self);

Convenient method to delete the object and free the memory.

Parameters

self

a GdaDdlCreator object

 

Since: 6.0


gda_ddl_creator_parse_file_from_path ()

gboolean
gda_ddl_creator_parse_file_from_path (GdaDdlCreator *self,
                                      const gchar *xmlfile,
                                      GError **error);

This method reads information from xmlfile and populate self object. The xmlfile should correspond to the following DTD format:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!ELEMENT schema (table+, view*)>
<!ATTLIST schema name           CDATA   #IMPLIED>

<!ELEMENT table (comment?,column+, fkey*)>
<!ATTLIST table temptable       (TRUE|FALSE)    "FALSE">
<!ATTLIST table name            CDATA           #REQUIRED>
<!ATTLIST table space           CDATA           #IMPLIED>

<!ELEMENT column (comment?, value?, check?)>
<!ATTLIST column name           CDATA           #REQUIRED>
<!ATTLIST column type           CDATA           #REQUIRED>
<!ATTLIST column pkey           (TRUE|FALSE)    "FALSE">
<!ATTLIST column unique         (TRUE|FALSE)    "FALSE">
<!ATTLIST column autoinc        (TRUE|FALSE)    "FALSE">
<!ATTLIST column nnul           (TRUE|FALSE)    "FALSE">

<!ELEMENT comment       (#PCDATA)>
<!ELEMENT value         (#PCDATA)>
<!ATTLIST value size            CDATA          #IMPLIED>
<!ATTLIST value scale           CDATA          #IMPLIED>

<!ELEMENT check         (#PCDATA)>

<!ELEMENT fkey (fk_field?)>
<!ATTLIST fkey reftable CDATA #IMPLIED>
<!ATTLIST fkey onupdate (RESTRICT|CASCADE|SET_NULL|NO_ACTION|SET_DEFAULT)       #IMPLIED>
<!ATTLIST fkey ondelete (RESTRICT|CASCADE|SET_NULL|NO_ACTION|SET_DEFAULT)       #IMPLIED>

<!ELEMENT fk_field (#PCDATA)>
<!ATTLIST fk_field name         CDATA           #REQUIRED>
<!ATTLIST fk_field reffield     CDATA           #REQUIRED>

<!ELEMENT view (definition)>
<!ATTLIST view name             CDATA           #REQUIRED>
<!ATTLIST view replace          (TRUE|FALSE)    "FALSE">
<!ATTLIST view temp             (TRUE|FALSE)    "FALSE">
<!ATTLIST view ifnotexists      (TRUE|FALSE)    "TRUE">

<!ELEMENT definition (#PCDATA)>

Up to day description of the xml file schema can be found in DTD file [libgda-ddl-creator.dtd] (https://gitlab.gnome.org/GNOME/libgda/blob/master/libgda/libgda-ddl-creator.dtd)

The given xmlfile will be checked before parsing and FALSE will be returned if fails. The xmlfile will be validated internally. The same method can be used to validate xmlfile before parsing it.

Parameters

self

an instance of GdaDdlCreator

 

xmlfile

xml file to parse

 

error

Error container

 

gda_ddl_creator_parse_file ()

gboolean
gda_ddl_creator_parse_file (GdaDdlCreator *self,
                            GFile *xmlfile,
                            GError **error);

For detailed description see gda_ddl_creator_parse_file_from_path()

Parameters

self

an instance of GdaDdlCreator

 

xmlfile

xml file as GFile instance

 

error

Error container

 

Since: 6.0


gda_ddl_creator_get_tables ()

const GList *
gda_ddl_creator_get_tables (GdaDdlCreator *self);

Parameters

self

a GdaDdlCreator object

 

Returns

a list of tables.

[element-type Gda.DdlTable][transfer none]

Since: 6.0


gda_ddl_creator_get_views ()

const GList *
gda_ddl_creator_get_views (GdaDdlCreator *self);

Parameters

self

a GdaDdlCreator object

 

Returns

a list of views.

[element-type Gda.DdlView][transfer none]

Since: 6.0


gda_ddl_creator_parse_cnc ()

gboolean
gda_ddl_creator_parse_cnc (GdaDdlCreator *self,
                           GdaConnection *cnc,
                           GError **error);

Parse cnc to populate self object.

Parameters

self

a GdaDdlCreator instance

 

cnc

Connection to parse

 

error

error storage object

 

Returns

Returns TRUE if succeeded, FALSE otherwise.


gda_ddl_creator_append_table ()

void
gda_ddl_creator_append_table (GdaDdlCreator *self,
                              const GdaDdlTable *table);

This method append table to the total list of all tables stored in self .

Parameters

self

a GdaDdlCreator instance

 

table

table to append

 

Since: 6.0


gda_ddl_creator_append_view ()

void
gda_ddl_creator_append_view (GdaDdlCreator *self,
                             const GdaDdlView *view);

This method append view to the total list of all views stored in self .

Parameters

self

a GdaDdlCreator instance

 

view

view to append

 

Since: 6.0


gda_ddl_creator_perform_operation ()

gboolean
gda_ddl_creator_perform_operation (GdaDdlCreator *self,
                                   GdaConnection *cnc,
                                   GError **error);

After population self with all data this method may be called to trigger code and modify user database. This is the main method to work with database. For retrieving information from database to an xml file use gda_ddl_creator_parse_cnc() and gda_ddl_buildable_write_xml().

Connection should be opened to use this method. See gda_connection_open() method for reference.

Only table can be created. Views are ignored

Each table from database compared with each table in the GdaDdlCreator instance. If the table doesn't exist in database, it will be created (CREATE_TABLE). If table exists in the database and xml file, all columns will be checked. If columns are present in xml file but not in the database it will be created (ADD_COLUMN). If column exists but has different parameters, e.g. nonnull it will not be modified.

Note: Pkeys are not checked. This is a limitation that should be removed. The corresponding issue was open on gitlab page.

Parameters

self

a GdaDdlCreator object

 

cnc

a connection object to work with

 

error

object to store error

 

gda_ddl_creator_write_to_file ()

gboolean
gda_ddl_creator_write_to_file (GdaDdlCreator *self,
                               GFile *file,
                               GError **error);

This method writes database description as xml file. Similar to gda_ddl_creator_write_to_path()

Parameters

self

a GdaDdlCreator instance

 

file

a GFile to write database description

 

error

container to hold error

 

Returns

TRUE if no error occurred, FALSE otherwise.

Since: 6.0


gda_ddl_creator_write_to_path ()

gboolean
gda_ddl_creator_write_to_path (GdaDdlCreator *self,
                               const gchar *path,
                               GError **error);

Save content of self to a user friendly xml file.

Parameters

self

a GdaDdlCreator instance

 

path

path to xml file to save GdaDdlCreator

 

error

container to hold an error

 

Returns

TRUE is no error, FLASE otherwise.

Since: 6.0

Types and Values

GDA_TYPE_DDL_CREATOR

#define GDA_TYPE_DDL_CREATOR (gda_ddl_creator_get_type())

struct GdaDdlCreatorClass

struct GdaDdlCreatorClass {
    GObjectClass parent;
};

enum GdaDdlCreatorError

These error are primary for developers to troubleshoot the problem rather than for user.

Members

GDA_DDL_CREATOR_CONTEXT_NULL

Context is NULL. Should not be NULL for normal operation.

 

GDA_DDL_CREATOR_DOC_NULL

xmlDocPtr is NULL.

 

GDA_DDL_CREATOR_INVALID_XML

Sets if xml check fails. Xml file structure doesn't match with DTD file

 

GDA_DDL_CREATOR_INVALID_SCHEMA

Sets if the used schema is invalid.

 

GDA_DDL_CREATOR_SERVER_OPERATION

Sets if server operation is NULL.

 

GDA_DDL_CREATOR_FILE_READ

Sets if xml file is not readable

 

GDA_DDL_CREATOR_PARSE_CONTEXT

Sets if an error with context during parsing an xml file

 

GDA_DDL_CREATOR_PARSE

Sets if parsing reports an error

 

GDA_DDL_CREATOR_PARSE_CHUNK

If set, error with parse chunk algorithm.

 

GDA_DDL_CREATOR_CONNECTION_CLOSED

Connection is not open.

 

GDA_DDL_CREATOR_ERROR

#define GDA_DDL_CREATOR_ERROR gda_ddl_creator_error_quark()

GdaDdlCreator

typedef struct _GdaDdlCreator GdaDdlCreator;

Property Details

The “schema-name” property

  “schema-name”              gchar *

Name of the schema.

Flags: Read / Write

Default value: NULL