Re: [gnome-db] database xml



First try :
-----------

After your suggestion to use "GdaXmlDatabase" to create a XML database,
I started to try the different functions available. Find hereunder my
first try and ... questions.
Once again sorry if my questions seems to be too simple but I am quite
new to programmation.

Thanks for help.

Phil


Small code used to create a new database (named "airports") and save it
on disk.

Here is the code :

/**********************************************************************/
/*  tutorial_005_02.c - libgda first use                              */
/*                      1. Creation of a new database.                */
/*                      2. Give it a name.                            */
/*                      3. Create tables with fields from models.     */
/*                      4. Save it.                                   */
/**********************************************************************/
#include <gnome.h>
#include <libgda/libgda.h>

/**********************************************************************/
/* "do_stuff" function                                                */
/**********************************************************************/
void do_stuff(void) {
  GdaXmlDatabase *database;
  GdaDataModel *airportModel;
  GdaDataModel *runwayModel;

  database = gda_xml_database_new();
  gda_xml_database_set_name(database, "airports");

  airportModel = gda_data_model_array_new(6);
  gda_data_model_set_column_title(airportModel, 0, "ICAO");
  gda_data_model_set_column_title(airportModel, 1, "IATA");
  gda_data_model_set_column_title(airportModel, 2, "NAME");
  gda_data_model_set_column_title(airportModel, 3, "LATITUDE");
  gda_data_model_set_column_title(airportModel, 4, "LONGITUDE");
  gda_data_model_set_column_title(airportModel, 5, "ELEVATION");
  gda_xml_database_new_table_from_model(database, "airport",
                                        airportModel, TRUE);

  runwayModel = gda_data_model_array_new(5);
  gda_data_model_set_column_title(runwayModel, 0, "ICAO");
  gda_data_model_set_column_title(runwayModel, 1, "RWY_ID");
  gda_data_model_set_column_title(runwayModel, 2, "QFU");
  gda_data_model_set_column_title(runwayModel, 3, "LENGHT");
  gda_data_model_set_column_title(runwayModel, 4, "WIDTH");
  gda_xml_database_new_table_from_model(database, "runway",
                                        runwayModel, TRUE);

  gda_xml_database_save(database, "/home/philippe/airports.db");

  gda_main_quit();
}

/**********************************************************************/
/* MAIN function                                                      */
/**********************************************************************/
int main(int argc, char **argv) {
  gda_init("Tutorial_005_02", "0.1", argc, argv);
  gda_main_run((GdaInitFunc)do_stuff, (gpointer)NULL);

  return EXIT_SUCCESS;
}

When looking to the saved file, I get the correct file (with strange
rights) :

---x-----T    1 philippe philippe       34 jui 29 19:01 airports.db*

These access rights lead to a problem when I want to overwrite or modify
the file as only root can do that.

Looking to the file content (as "root" - because of the access rights) :

<?xml version="1.0"?>
<database>
  <tables>
   <table name="airport">
    <field name="ICAO" caption="" gdatype="string" size="0" scale="0"
pkey="0" unique="0" isnull="1" auto_increment="0" references=""
position="0"/>
    <field name="IATA" caption="" gdatype="string" size="0" scale="0"
pkey="0" unique="0" isnull="1" auto_increment="0" references=""
position="1"/>
    <field name="NAME" caption="" gdatype="string" size="0" scale="0"
pkey="0" unique="0" isnull="1" auto_increment="0" references=""
position="2"/>
    <field name="LATITUDE" caption="" gdatype="string" size="0"
scale="0" pkey="0" unique="0" isnull="1" auto_increment="0"
references="" position="3"/>
    <field name="LONGITUDE" caption="" gdatype="string" size="0"
scale="0" pkey="0" unique="0" isnull="1" auto_increment="0"
references="" position="4"/>
    <field name="ELEVATION" caption="" gdatype="string" size="0"
scale="0" pkey="0" unique="0" isnull="1" auto_increment="0"
references="" position="5"/>
   </table>
   <table name="runway">
    <field name="ICAO" caption="" gdatype="string" size="0" scale="0"
pkey="0" unique="0" isnull="1" auto_increment="0" references=""
position="0"/>
    <field name="RWY_ID" caption="" gdatype="string" size="0" scale="0"
pkey="0" unique="0" isnull="1" auto_increment="0" references=""
position="1"/>
    <field name="QFU" caption="" gdatype="string" size="0" scale="0"
pkey="0" unique="0" isnull="1" auto_increment="0" references=""
position="2"/>
    <field name="LENGHT" caption="" gdatype="string" size="0" scale="0"
pkey="0" unique="0" isnull="1" auto_increment="0" references=""
position="3"/>
    <field name="WIDTH" caption="" gdatype="string" size="0" scale="0"
pkey="0" unique="0" isnull="1" auto_increment="0" references=""
position="4"/>
   </table>
  </tables>
</database>

The database is created with the tables, but with no name (what's the
utility of "gda_xml_database_set_name" ?).
I expected something like :

<?xml version="1.0"?>
<database name="airports">
...
</database>





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]