Top |
GdaDdlCreatorGdaDdlCreator — Object to constract database representation from an xml file or by reading the existing datatabase |
Functions
Types and Values
#define | GDA_TYPE_DDL_CREATOR |
struct | GdaDdlCreatorClass |
enum | GdaDdlCreatorError |
#define | GDA_DDL_CREATOR_ERROR |
GdaDdlCreator |
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_new ()
GdaDdlCreator *
gda_ddl_creator_new (void
);
Create new instance of GdaDdlCreator. The object can be destroyed using gda_ddl_creator_free()
method.
Since: 6.0
gda_ddl_creator_free ()
void
gda_ddl_creator_free (GdaDdlCreator *self
);
Convenient method to delete the object and free the memory.
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.
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
);
Since: 6.0
gda_ddl_creator_get_views ()
const GList *
gda_ddl_creator_get_views (GdaDdlCreator *self
);
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.
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
.
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
.
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 |
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 |
Since: 6.0
Types and Values
enum GdaDdlCreatorError
These error are primary for developers to troubleshoot the problem rather than for user.
Members
xmlDocPtr is |
||
Sets if xml check fails. Xml file structure doesn't match with DTD file |
||
Sets if the used schema is invalid. |
||
Sets if server operation is |
||
Sets if xml file is not readable |
||
Sets if an error with context during parsing an xml file |
||
Sets if parsing reports an error |
||
If set, error with parse chunk algorithm. |
||
Connection is not open. |
Property Details
The “schema-name”
property
“schema-name” gchar *
Name of the schema.
Flags: Read / Write
Default value: NULL