Back to index

gcompris  8.2.2
Functions
gcompris_db.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int gc_db_init ()
void gc_db_exit ()
gboolean gc_db_check_boards ()
void gc_db_set_date (gchar *date)
void gc_db_set_version (gchar *version)
void gc_db_board_update (guint *board_id, guint *section_id, gchar *name, gchar *section, gchar *author, gchar *type, gchar *mode, int difficulty, gchar *icon, gchar *boarddir, gchar *mandatory_sound_file, gchar *mandatory_sound_dataset, gchar *filename, gchar *title, gchar *description, gchar *prerequisite, gchar *goal, gchar *manual, gchar *credit)
void gc_db_save_user (int *user_id, gchar *login, gchar *name, gchar *firstname, gchar *birthday, int class_id)
GList * gc_db_read_board_from_section (gchar *section)
GList * gc_menu_load_db (GList *boards)
GList * gc_db_get_board_id (GList *list)
void gc_db_remove_board (int board_id)
GcomprisProfilegc_db_get_profile_from_id (gint profile_id)
GcomprisProfilegc_db_profile_from_name_get (gchar *profile_name)
 Given a profile name, return a GcomprisProfile struct.
GList * gc_db_profiles_list_get ()
GcomprisClass * gc_db_get_class_from_id (gint class_id)
GList * gc_db_get_classes_list ()
GcomprisGroup * gc_db_get_group_from_id (gint group_id)
GList * gc_db_get_groups_list ()
GcomprisUser * gc_db_get_user_from_id (gint user_id)
GList * gc_db_get_users_list ()
GcomprisProfilegc_db_get_profile ()
GList * gc_db_users_from_group_get (gint group_id)
void gc_db_set_board_conf (GcomprisProfile *profile, GcomprisBoard *board, gchar *key, gchar *value)
GHashTable * gc_db_get_board_conf ()
GHashTable * gc_db_get_conf (GcomprisProfile *profile, GcomprisBoard *board)
GHashTable * gc_db_conf_with_table_get (int profile_id, int board_id, GHashTable *table)
GcomprisBoard * gc_db_get_board_from_id (int board_id)
int gc_db_is_activity_in_profile (GcomprisProfile *profile, char *activity_name)

Function Documentation

void gc_db_board_update ( guint *  board_id,
guint *  section_id,
gchar *  name,
gchar *  section,
gchar *  author,
gchar *  type,
gchar *  mode,
int  difficulty,
gchar *  icon,
gchar *  boarddir,
gchar *  mandatory_sound_file,
gchar *  mandatory_sound_dataset,
gchar *  filename,
gchar *  title,
gchar *  description,
gchar *  prerequisite,
gchar *  goal,
gchar *  manual,
gchar *  credit 
)

Definition at line 431 of file gcompris_db.c.

{
#ifdef USE_SQLITE

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  if (gcompris_db == NULL)
    g_error("Database is closed !!!");

  if (*board_id==0){
    /* board not yet registered */

    /* assume name is unique */

    request = g_strdup_printf(CHECK_BOARD(name));

    rc = sqlite3_get_table(gcompris_db,
                        request,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    g_free(request);

    if (nrow != 0){
      *board_id = atoi(result[1]);
      sqlite3_free_table(result);
    } else {

      /* get last board_id written */
      rc = sqlite3_get_table(gcompris_db,
                          MAX_BOARD_ID,
                          &result,
                          &nrow,
                          &ncolumn,
                          &zErrMsg
                          );

      if( rc!=SQLITE_OK ){
       g_error("SQL error: %s\n", zErrMsg);
      }

      if (result[1] == NULL)
       *board_id = 1;
      else
       *board_id = atoi(result[1]) + 1;

      sqlite3_free_table(result);

    }
  }

  /* get section_id */
  request = g_strdup_printf(SECTION_ID(section));

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  g_free(request);

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow == 0){

    /* get max section_id */

    rc = sqlite3_get_table(gcompris_db,
                        MAX_SECTION_ID,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );


    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    if (result[1] == NULL){
      *section_id = 1;
    } else {
      *section_id = atoi(result[1]) + 1;
    }
    sqlite3_free_table(result);
  } else {
    *section_id = atoi(result[1]);
    sqlite3_free_table(result);
  }

  request = sqlite3_mprintf( BOARD_INSERT,
                          *board_id,
                          name,
                          *section_id,
                          section,
                          author,
                          type,
                          mode,
                          difficulty,
                          icon,
                          boarddir,
                          mandatory_sound_file,
                          mandatory_sound_dataset,
                          filename,
                          title,
                          description,
                          prerequisite,
                          goal,
                          manual,
                          credit
                          );

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  sqlite3_free_table(result);

  sqlite3_free(request);

#endif
}

Here is the caller graph for this function:

gboolean gc_db_check_boards ( )

Definition at line 381 of file gcompris_db.c.

{
#ifdef USE_SQLITE

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gboolean ret_value;

  rc = sqlite3_get_table(gcompris_db,
                      BOARDS_CHECK,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );
  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  ret_value = (strcmp(result[2],VERSION)==0) && (result[3] != NULL);

  sqlite3_free_table(result);

  return ret_value;
#else
  return FALSE;
#endif
}

Here is the caller graph for this function:

GHashTable* gc_db_conf_with_table_get ( int  profile_id,
int  board_id,
GHashTable *  table 
)

Definition at line 1313 of file gcompris_db.c.

{
  GHashTable *hash_conf = table;

#ifdef USE_SQLITE
  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;
  int i;

  request = g_strdup_printf(GET_CONF(profile_id,
                                 board_id));

  g_warning ( "Request get_conf : %s", request);

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);

  for ( i=ncolumn; i < (nrow +1)*ncolumn; i+=2){
    if (strcmp(result[i+1],"NULL")!=0){
      /* "NULL" values are ignored */
      g_hash_table_replace (hash_conf,
                         g_strdup(result[i]),
                         g_strdup(result[i+1]));
      g_warning("get_conf: put key %s value %s in the hash",
              result[i],
              result[i+1]);
    }
  }

  sqlite3_free_table(result);
#endif
  return hash_conf;
}

Here is the caller graph for this function:

void gc_db_exit ( )

Definition at line 307 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  sqlite3_close(gcompris_db);
  g_warning("Database closed");
#endif
}

Here is the caller graph for this function:

GHashTable* gc_db_get_board_conf ( )

Definition at line 1373 of file gcompris_db.c.

{
  GHashTable *hash_result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);

  /* priority order : board + Profile conf, else profile Default (all boards) conf, if not  Default profile + board */

  /* conf values for default profile and current board */
  hash_result = gc_db_conf_with_table_get(1,
                                     gc_board_get_current()->board_id,
                                     hash_result);

  /* conf values for profile (board independant) */
  if(gc_profile_get_current()) {
    hash_result = gc_db_conf_with_table_get(gc_profile_get_current()->profile_id,
                                       -1,
                                       hash_result);

    /* conf value for current profile and current board */
    hash_result = gc_db_conf_with_table_get(gc_profile_get_current()->profile_id,
                                       gc_board_get_current()->board_id,
                                       hash_result);
  }

  return hash_result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

GcomprisBoard* gc_db_get_board_from_id ( int  board_id)

Definition at line 1642 of file gcompris_db.c.

{
#ifdef USE_SQLITE

  GcomprisProperties *properties = gc_prop_get();

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  int i;
  gchar *request;

  request = g_strdup_printf(BOARDS_READ_FROM_ID(board_id));

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);

  /* first ncolumns are columns labels. */
  i = ncolumn;

  GcomprisBoard *gcomprisBoard = NULL;

  gcomprisBoard = g_malloc0 (sizeof (GcomprisBoard));


  gcomprisBoard->plugin=NULL;
  gcomprisBoard->previous_board=NULL;
  gcomprisBoard->board_ready=FALSE;
  gcomprisBoard->canvas=gc_get_canvas();

  gcomprisBoard->gmodule      = NULL;
  gcomprisBoard->gmodule_file = NULL;

  /* From DB we have only package_data_dir. */
  gcomprisBoard->board_dir = g_strdup_printf(properties->package_data_dir);

  /* Fixed since I use the canvas own pixel_per_unit scheme */
  gcomprisBoard->width  = BOARDWIDTH;
  gcomprisBoard->height = BOARDHEIGHT;


  gcomprisBoard->board_id = board_id;
  gcomprisBoard->name = g_strdup(result[i++]);
  gcomprisBoard->section_id = atoi(result[i++]);
  gcomprisBoard->section = g_strdup(result[i++]);
  gcomprisBoard->author = g_strdup(result[i++]);
  gcomprisBoard->type = g_strdup(result[i++]);
  gcomprisBoard->mode = g_strdup(result[i++]);
  gcomprisBoard->difficulty = g_strdup(result[i++]);
  gcomprisBoard->icon_name = g_strdup(result[i++]);
  gcomprisBoard->boarddir = g_strdup(result[i++]);
  gcomprisBoard->mandatory_sound_file = g_strdup(result[i++]);
  gcomprisBoard->mandatory_sound_dataset = g_strdup(result[i++]);
  gcomprisBoard->filename = g_strdup(result[i++]);
  gcomprisBoard->title =  reactivate_newline(gettext(result[i++]));
  gcomprisBoard->description  = reactivate_newline(gettext(result[i++]));
  gcomprisBoard->prerequisite = reactivate_newline(gettext(result[i++]));
  gcomprisBoard->goal = reactivate_newline(gettext(result[i++]));
  gcomprisBoard->manual = reactivate_newline(gettext(result[i++]));
  gcomprisBoard->credit = reactivate_newline(gettext(result[i++]));

  sqlite3_free_table(result);

  return gcomprisBoard;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

GList* gc_db_get_board_id ( GList *  list)

Definition at line 695 of file gcompris_db.c.

{
#ifdef USE_SQLITE

  GList *board_id_list = list;

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  int i;

  rc = sqlite3_get_table(gcompris_db,
                      BOARD_ID_READ,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  /* first ncolumns are columns labels. */
  i = ncolumn;

  while (i < (nrow +1)*ncolumn) {
    int *board_id = g_malloc(sizeof(int));

    *board_id = atoi(result[i++]);
    board_id_list = g_list_append(board_id_list, board_id);
  }

  return  board_id_list;

#else
  return list;
#endif
}

Here is the caller graph for this function:

GcomprisClass* gc_db_get_class_from_id ( gint  class_id)

Definition at line 1137 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  int i;
  GcomprisClass *class = NULL;

  request = g_strdup_printf(CLASS_FROM_ID(class_id));
  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);

  if (nrow == 0){
    g_warning("No class with id %d", class_id);
    return NULL;
    return NULL;
  } else {
    i = ncolumn;

    class = g_malloc0(sizeof(GcomprisClass));

    class->class_id = class_id;
    class->name = g_strdup(result[i++]);
    class->description = g_strdup(result[i++]);
    class->wholegroup_id = atoi(result[i++]);
  }

  /* Group _ids */

  GList *group_ids = NULL;

  request = g_strdup_printf(GROUPS_IN_CLASS(class_id));

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);

  if (nrow == 0){
    g_error("No groups found for class id %d: there must be at least one for the whole class with id (%d)",
           class_id, class->wholegroup_id);
    g_free(class);
    class = NULL;
  } else {

    i = ncolumn;
    while (i < (nrow +1)*ncolumn) {
      int *group_id = g_malloc(sizeof(int));

      *group_id = atoi(result[i++]);
      group_ids = g_list_append(group_ids, group_id);
    }
    class->group_ids = group_ids;
  }

  return class ;
#else
  return NULL;
#endif
}

Here is the caller graph for this function:

Definition at line 1782 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  GList *classes_list = NULL;

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  int i;
  GcomprisClass *class = NULL;

  rc = sqlite3_get_table(gcompris_db,
                      GET_ALL_CLASSES,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow == 0){
    g_warning("No groups !");
    return NULL;
  } else {
    i = ncolumn;

    while ( i < (nrow +1)*ncolumn) {
      class = g_malloc0(sizeof(GcomprisClass));

      class->class_id =  atoi(result[i++]);
      class->name = g_strdup(result[i++]);
      class->description = g_strdup(result[i++]);
      class->wholegroup_id = atoi(result[i++]);

      classes_list = g_list_append(classes_list, class);
    }
  }

  return classes_list;

#else
  return NULL;
#endif
}

Here is the caller graph for this function:

GHashTable* gc_db_get_conf ( GcomprisProfile profile,
GcomprisBoard *  board 
)

Definition at line 1362 of file gcompris_db.c.

{
  GHashTable *hash_result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);

#ifdef USE_SQLITE
  return gc_db_conf_with_table_get( profile->profile_id, board->board_id, hash_result) ;
#else
  return hash_result;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

GcomprisGroup* gc_db_get_group_from_id ( gint  group_id)

Definition at line 1586 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  GList *groups_list = NULL;

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  int i;
  GcomprisGroup *group = NULL;

  rc = sqlite3_get_table(gcompris_db,
                      GET_ALL_GROUPS,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow == 0){
    g_warning("No groups !");
    return NULL;
  } else {
    i = ncolumn;

    while ( i < (nrow +1)*ncolumn) {
      group = g_malloc0(sizeof(GcomprisGroup));

      group->group_id =  atoi(result[i++]);
      group->name = g_strdup(result[i++]);
      group->class_id = atoi(result[i++]);
      group->description = g_strdup(result[i++]);

      group->user_ids = gc_db_users_from_group_get(group->group_id);

      groups_list = g_list_append(groups_list, group);
    }
  }

  return groups_list;

#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 991 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  int profile_id;

  rc = sqlite3_get_table(gcompris_db,
                      GET_ACTIVE_PROFILE_ID,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  profile_id = atoi(result[1]);

  sqlite3_free_table(result);

  return gc_db_get_profile_from_id(profile_id);

#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 820 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  GcomprisProfile *profile = NULL;

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  int i;
  GList *ids;
  /* get section_id */
  request = g_strdup_printf(GET_PROFILE(profile_id));


  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow != 0){
    profile = g_malloc0(sizeof(GcomprisProfile));

    profile->profile_id = profile_id;


    profile->name = g_strdup(result[3]);
    profile->directory = g_strdup(result[4]);
    profile->description = g_strdup(result[5]);
    sqlite3_free_table(result);
    g_free(request);

    request = g_strdup_printf(GET_GROUPS_IN_PROFILE(profile->profile_id));

    rc = sqlite3_get_table(gcompris_db,
                        request,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    g_free(request);

    if (nrow == 0){
      g_warning("No users' groups for profile %s", profile->name);
      profile->group_ids = NULL;
    } else {
      ids = NULL;

      i = ncolumn;
      while (i < (nrow +1)*ncolumn) {
       int *group_id = g_malloc(sizeof(int));

       *group_id = atoi(result[i++]);
       ids = g_list_append(ids, group_id);
      }
      profile->group_ids = ids;
    }
    sqlite3_free_table(result);

    request = g_strdup_printf(GET_ACTIVITIES_OUT_OF_PROFILE(profile->profile_id));
    rc = sqlite3_get_table(gcompris_db,
                        request,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    g_free(request);

    if (nrow == 0){
      g_warning("No activities for profile %s", profile->name);
      profile->activities = NULL;
    } else {
      ids = NULL;

      i = ncolumn;
      while (i < (nrow +1)*ncolumn) {
       int *board_id = g_malloc(sizeof(int));

       *board_id = atoi(result[i++]);
       ids = g_list_append(ids, board_id);
      }
      profile->activities = ids;
    }
    sqlite3_free_table(result);
  }

  return profile;
#else
  return NULL;
#endif
}

Here is the caller graph for this function:

GcomprisUser* gc_db_get_user_from_id ( gint  user_id)

Definition at line 1082 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;
  int i;
  GcomprisUser *user = NULL;

  request = g_strdup_printf(USER_FROM_ID(user_id));
  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);

  if (nrow == 0){
    g_warning("No user with id  %d", user_id);
    return NULL;
  } else {
    i = ncolumn;
    user = g_malloc0(sizeof(GcomprisUser));

    user->user_id = user_id;
    user->login = g_strdup(result[i++]);
    user->lastname = g_strdup(result[i++]);
    user->firstname = g_strdup(result[i++]);
    user->birthdate = g_strdup(result[i++]);
    user->class_id = atoi(result[i++]);
  }


  return user ;
#else
  return NULL;
#endif
}

Here is the caller graph for this function:

Definition at line 1727 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  GList *users_list = NULL;

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  int i;
  GcomprisUser *user = NULL;

  rc = sqlite3_get_table(gcompris_db,
                      GET_ALL_USERS,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow == 0){
    g_warning("No users !");
    return NULL;
  } else {
    i = ncolumn;

    while ( i < (nrow +1)*ncolumn) {
      user = g_malloc0(sizeof(GcomprisUser));

      user->user_id =  atoi(result[i++]);
      user->login = g_strdup(result[i++]);
      user->firstname = g_strdup(result[i++]);
      user->lastname = g_strdup(result[i++]);
      user->birthdate = g_strdup(result[i++]);
      user->class_id = atoi(result[i++]);

      users_list = g_list_append(users_list, user);
    }
  }

  return users_list;

#else
  return NULL;
#endif
}

Here is the caller graph for this function:

int gc_db_init ( )

Definition at line 115 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  gboolean creation = FALSE;
  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  GcomprisProperties *properties = gc_prop_get();

  if (!g_file_test(properties->database, G_FILE_TEST_EXISTS))
    creation = TRUE;
  else {
    /* we have to check this file is not empty,
       because bug in administration */
    struct stat buf;

    if (stat(properties->database, &buf)!=0)
      g_error("Can't stat %s", properties->database);

    /* if size of file is null, we recreate the tables */
    if (buf.st_size == 0){
      creation = TRUE;
      g_warning("Database file is empty! Trying to create table...");
    }
  }

  rc = sqlite3_open(properties->database, &gcompris_db);
  if( rc ){
    g_error("Can't open database: %s\n", sqlite3_errmsg(gcompris_db));
    sqlite3_close(gcompris_db);
    exit(1);
  }

  g_warning("Database %s opened", properties->database);

  if (creation){
    /* create all tables needed */
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_USERS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_CLASS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_GROUPS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_USERS_IN_GROUPS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_GROUPS_IN_PROFILES, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_ACTIVITIES_OUT, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_PROFILES, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_BOARDS_PROFILES_CONF, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_BOARDS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,CREATE_TABLE_INFO, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    /* CREATE TRIGGERS */
    rc = sqlite3_exec(gcompris_db,TRIGGER_DELETE_CLASS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,TRIGGER_DELETE_GROUPS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,TRIGGER_DELETE_PROFILES, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,TRIGGER_DELETE_USERS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,TRIGGER_INSERT_USERS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    rc = sqlite3_exec(gcompris_db,TRIGGER_UPDATE_USERS, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    g_warning("Database tables created");

    request = g_strdup_printf(SET_VERSION(VERSION));

    rc = sqlite3_get_table(gcompris_db,
                        request,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    rc = sqlite3_exec(gcompris_db,SET_DEFAULT_PROFILE, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    rc = sqlite3_exec(gcompris_db,ACTIVATE_DEFAULT_PROFILE, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }


    request = g_strdup_printf("INSERT INTO class (class_id, name, teacher, wholegroup_id) VALUES ( 1, \'%s\', \'(%s)\', 1);",
                           _("Unaffected"),
                           _("Users without a class"));

    rc = sqlite3_exec(gcompris_db, request, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    rc = sqlite3_exec(gcompris_db,SET_DEFAULT_GROUP, NULL,  0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }


    sqlite3_free_table(result);

    g_free(request);

  } else {
    /* Check the db integrity */
    rc = sqlite3_get_table(gcompris_db,
                        PRAGMA_INTEGRITY,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }
    if (!(strcmp(result[1],"ok")==0))
      g_error("DATABASE integrity check returns %s \n", result[1]);
    g_warning("Database Integrity ok");
    sqlite3_free_table(result);

    rc = sqlite3_get_table(gcompris_db,
                        CHECK_VERSION,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );
    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    if (strcmp(result[1],VERSION)!=0)
      g_warning("Running GCompris is %s, but databse vrsion is %s", VERSION, result[1]);
    sqlite3_free_table(result);
  }

  return TRUE;
#else
  return FALSE;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gc_db_is_activity_in_profile ( GcomprisProfile profile,
char *  activity_name 
)

Definition at line 1836 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  request = g_strdup_printf(DB_IS_ACTIVITY_IN_PROFILE_ID(profile->profile_id, activity_name));

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  g_free(request);

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow == 0){
    /* IS IN THE PROFILE */
    return TRUE;
  }

  /* IS NOT IN THE PROFILE */
  return FALSE;

#else
  return TRUE;
#endif
}

Here is the caller graph for this function:

GcomprisProfile* gc_db_profile_from_name_get ( gchar *  profile_name)

Given a profile name, return a GcomprisProfile struct.

Parameters:
profile_name,:the profile to retrieve.
Returns:
*GcomprisProfile

Definition at line 941 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  GcomprisProfile *profile = NULL;

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  /* get section_id */
  request = g_strdup_printf(GET_PROFILE_FROM_NAME(profile_name));

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow != 0){
    gint profile_id;

    profile_id  = atoi(result[3]);

    g_free(request);

    profile = gc_db_get_profile_from_id(profile_id);

  }


  return profile;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1403 of file gcompris_db.c.

{
#ifdef USE_SQLITE


  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  int i;
  GList *profiles_list = NULL;

  char **result_;
  int nrow_;
  int ncolumn_;

  int i_;
  GList *ids_;


  rc = sqlite3_get_table(gcompris_db,
                      GET_ALL_PROFILES,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow == 0)
    return NULL;

  i = ncolumn;
  while (i < (nrow +1)*ncolumn) {
    GcomprisProfile *profile = g_malloc0(sizeof(GcomprisProfile));

    profile->profile_id = atoi(result[i++]);

    profile->name = g_strdup(result[i++]);
    profile->directory = g_strdup(result[i++]);
    profile->description = g_strdup(result[i++]);

    request = g_strdup_printf(GET_GROUPS_IN_PROFILE(profile->profile_id));

    rc = sqlite3_get_table(gcompris_db,
                        request,
                        &result_,
                        &nrow_,
                        &ncolumn_,
                        &zErrMsg
                        );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    g_free(request);

    if (nrow_ == 0){
      g_warning("No users groups for profile %s", profile->name);
      profile->group_ids = NULL;
    } else {
      ids_ = NULL;

      i_ = ncolumn_;
      while (i_ < (nrow_ +1)*ncolumn_) {
       int *group_id = g_malloc(sizeof(int));

       *group_id = atoi(result_[i_++]);
       ids_ = g_list_append(ids_, group_id);
      }
      profile->group_ids = ids_;
    }

    sqlite3_free_table(result_);

    request = g_strdup_printf(GET_ACTIVITIES_OUT_OF_PROFILE(profile->profile_id));
    rc = sqlite3_get_table(gcompris_db,
                        request,
                        &result_,
                        &nrow_,
                        &ncolumn_,
                        &zErrMsg
                        );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    g_free(request);

    if (nrow_ == 0){
      g_warning("No activities out for profile %s", profile->name);
      profile->activities = NULL;
    } else {
      ids_ = NULL;

      i_ = ncolumn_;
      while (i_ < (nrow_ +1)*ncolumn_) {
       int *board_id = g_malloc(sizeof(int));

       *board_id = atoi(result_[i_++]);
       ids_ = g_list_append(ids_, board_id);
      }
      profile->activities = ids_;
    }

    sqlite3_free_table(result_);
    profiles_list = g_list_append( profiles_list, profile);
  }

  sqlite3_free_table(result);

  return profiles_list;
#else
  return NULL;
#endif
}

Here is the caller graph for this function:

GList* gc_db_read_board_from_section ( gchar *  section)

Definition at line 686 of file gcompris_db.c.

{
  return NULL;
}
void gc_db_remove_board ( int  board_id)

Definition at line 740 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  g_warning("Supress board %d from db.", board_id);

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  /* get section_id */
  request = g_strdup_printf(DELETE_BOARD("boards",board_id));

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);


  /* get section_id */
  request = g_strdup_printf(DELETE_BOARD("board_profile_conf",board_id));

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);


  /* get section_id */
  request = g_strdup_printf(DELETE_BOARD("activities_out",board_id));

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);
#endif
}

Here is the caller graph for this function:

void gc_db_save_user ( int *  user_id,
gchar *  login,
gchar *  name,
gchar *  firstname,
gchar *  birthday,
int  class_id 
)
void gc_db_set_board_conf ( GcomprisProfile profile,
GcomprisBoard *  board,
gchar *  key,
gchar *  value 
)

Definition at line 1233 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  request = sqlite3_mprintf(CHECK_CONF,
                         profile->profile_id,
                         board->board_id,
                         key);

  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  sqlite3_free(request);

  if (nrow == 0){
    request = sqlite3_mprintf(INSERT_KEY,
                           profile->profile_id,
                           board->board_id,
                           key,
                           value);

    rc = sqlite3_get_table(gcompris_db,
                        request,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    sqlite3_free(request);
  } else {
    request = sqlite3_mprintf(UPDATE_KEY,
                           value,
                           profile->profile_id,
                           board->board_id,
                           key
                           );

    rc = sqlite3_get_table(gcompris_db,
                        request,
                        &result,
                        &nrow,
                        &ncolumn,
                        &zErrMsg
                        );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    sqlite3_free(request);
  }
#endif
}

Here is the caller graph for this function:

void gc_db_set_date ( gchar *  date)

Definition at line 318 of file gcompris_db.c.

{
#ifdef USE_SQLITE

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  request = g_strdup_printf(BOARDS_SET_DATE(date));
  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );
  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }
  g_free(request);

  sqlite3_free_table(result);

#endif
}

Here is the caller graph for this function:

void gc_db_set_version ( gchar *  version)

Definition at line 350 of file gcompris_db.c.

{
#ifdef USE_SQLITE

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  request = g_strdup_printf(BOARDS_UPDATE_VERSION(version));
  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );
  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }
  g_free(request);

  sqlite3_free_table(result);

#endif
}

Here is the caller graph for this function:

GList* gc_db_users_from_group_get ( gint  group_id)

Definition at line 1027 of file gcompris_db.c.

{
#ifdef USE_SQLITE
  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  int i;
  GList *users = NULL;

  request = g_strdup_printf(USERS_FROM_GROUP(group_id));
  rc = sqlite3_get_table(gcompris_db,
                      request,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  g_free(request);

  if (nrow == 0){
    g_warning("No users in the group id %d", group_id);
  } else {
    i = ncolumn;
    while (i < (nrow +1)*ncolumn) {
      GcomprisUser *user = g_malloc0(sizeof(GcomprisUser));

      user->user_id = atoi(result[i++]);
      user->login = g_strdup(result[i++]);
      user->lastname = g_strdup(result[i++]);
      user->firstname = g_strdup(result[i++]);
      user->birthdate = g_strdup(result[i++]);
      user->class_id = atoi(result[i++]);

      users = g_list_append(users, user);
    }
  }

  return users;
#else
  return NULL;
#endif
}

Here is the caller graph for this function:

GList* gc_menu_load_db ( GList *  boards)

Definition at line 603 of file gcompris_db.c.

{
#ifdef USE_SQLITE

  GcomprisProperties *properties = gc_prop_get();

  GList *boards = boards_list;

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  int i;

  rc = sqlite3_get_table(gcompris_db,
                      BOARDS_READ,
                      &result,
                      &nrow,
                      &ncolumn,
                      &zErrMsg
                      );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  /* first ncolumns are columns labels. */
  i = ncolumn;

  while (i < (nrow +1)*ncolumn) {
    GcomprisBoard *gcomprisBoard = NULL;

    gcomprisBoard = g_malloc0 (sizeof (GcomprisBoard));

    gcomprisBoard->plugin=NULL;
    gcomprisBoard->previous_board=NULL;
    gcomprisBoard->board_ready=FALSE;
    gcomprisBoard->canvas=gc_get_canvas();

    gcomprisBoard->gmodule      = NULL;
    gcomprisBoard->gmodule_file = NULL;

    /* From DB we have only package_data_dir. */
    gcomprisBoard->board_dir = g_strdup(properties->package_data_dir);

    /* Fixed since I use the canvas own pixel_per_unit scheme */
    gcomprisBoard->width  = BOARDWIDTH;
    gcomprisBoard->height = BOARDHEIGHT;


    gcomprisBoard->board_id = atoi(result[i++]);
    gcomprisBoard->name = g_strdup(result[i++]);
    gcomprisBoard->section_id = atoi(result[i++]);
    gcomprisBoard->section = g_strdup(result[i++]);
    gcomprisBoard->author = g_strdup(result[i++]);
    gcomprisBoard->type = g_strdup(result[i++]);
    gcomprisBoard->mode = g_strdup(result[i++]);
    gcomprisBoard->difficulty = g_strdup(result[i++]);
    gcomprisBoard->icon_name = g_strdup(result[i++]);
    gcomprisBoard->boarddir = g_strdup(result[i++]);
    gcomprisBoard->mandatory_sound_file = g_strdup(result[i++]);
    gcomprisBoard->mandatory_sound_dataset = g_strdup(result[i++]);
    gcomprisBoard->filename = g_strdup(result[i++]);
    gcomprisBoard->title =  reactivate_newline(gettext(result[i++]));
    gcomprisBoard->description  = reactivate_newline(gettext(result[i++]));
    gcomprisBoard->prerequisite = reactivate_newline(gettext(result[i++]));
    gcomprisBoard->goal = reactivate_newline(gettext(result[i++]));
    gcomprisBoard->manual = reactivate_newline(gettext(result[i++]));
    gcomprisBoard->credit = reactivate_newline(gettext(result[i++]));

    boards = g_list_append(boards, gcomprisBoard);
  }

  sqlite3_free_table(result);

  return boards;

#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function: