~ubuntu-branches/ubuntu/quantal/colord/quantal-proposed

« back to all changes in this revision

Viewing changes to src/cd-mapping-db.c

  • Committer: Package Import Robot
  • Author(s): Sjoerd Simons
  • Date: 2011-10-25 16:21:20 UTC
  • mto: (2.1.1 sid) (1.1.2)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20111025162120-0aypjqn1zx9n6vgf
Tags: upstream-0.1.13
ImportĀ upstreamĀ versionĀ 0.1.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
379
379
}
380
380
 
381
381
/**
 
382
 * cd_mapping_db_sqlite_timestamp_cb:
 
383
 **/
 
384
static gint
 
385
cd_mapping_db_sqlite_timestamp_cb (void *data,
 
386
                                   gint argc,
 
387
                                   gchar **argv,
 
388
                                   gchar **col_name)
 
389
{
 
390
        guint64 *timestamp = (guint64 *) data;
 
391
 
 
392
        /* should only be one entry */
 
393
        g_debug ("CdMappingDb: got sql entry %s", argv[0]);
 
394
        *timestamp = g_ascii_strtoull (argv[0], NULL, 10);
 
395
        return 0;
 
396
}
 
397
 
 
398
/**
 
399
 * cd_mapping_db_get_timestamp:
 
400
 *
 
401
 * Gets when the profile was added to the device.
 
402
 **/
 
403
guint64
 
404
cd_mapping_db_get_timestamp (CdMappingDb *mdb,
 
405
                             const gchar *device_id,
 
406
                             const gchar *profile_id,
 
407
                             GError  **error)
 
408
{
 
409
        gchar *error_msg = NULL;
 
410
        gchar *statement;
 
411
        gint rc;
 
412
        guint64 timestamp = G_MAXUINT64;
 
413
 
 
414
        g_return_val_if_fail (CD_IS_MAPPING_DB (mdb), FALSE);
 
415
        g_return_val_if_fail (mdb->priv->db != NULL, FALSE);
 
416
 
 
417
        g_debug ("CdMappingDb: get checksum for %s<->%s",
 
418
                 device_id, profile_id);
 
419
        statement = g_strdup_printf ("SELECT timestamp FROM mappings WHERE "
 
420
                                     "device = '%s' AND profile = '%s' "
 
421
                                     "LIMIT 1;", device_id, profile_id);
 
422
 
 
423
        /* query the checksum */
 
424
        rc = sqlite3_exec (mdb->priv->db,
 
425
                           statement,
 
426
                           cd_mapping_db_sqlite_timestamp_cb,
 
427
                           &timestamp,
 
428
                           &error_msg);
 
429
        if (rc != SQLITE_OK) {
 
430
                g_set_error (error,
 
431
                             CD_MAIN_ERROR,
 
432
                             CD_MAIN_ERROR_FAILED,
 
433
                             "SQL error: %s",
 
434
                             error_msg);
 
435
                sqlite3_free (error_msg);
 
436
                goto out;
 
437
        }
 
438
out:
 
439
        g_free (statement);
 
440
        return timestamp;
 
441
}
 
442
 
 
443
/**
382
444
 * cd_mapping_db_class_init:
383
445
 * @klass: The CdMappingDbClass
384
446
 **/