Example #1
0
//------------------------------------------------------------------------
bool PresetFile::prepareMetaInfoUpdate ()
{
	TSize writePos = 0;
	const Entry* e = getEntry (kMetaInfo);
	if (e)
	{
		// meta info must be the last entry!	
		if (e != getLastEntry ())
			return false;

		writePos = e->offset;
		entryCount--;
	}
	else
	{
		// entries must be sorted ascending by offset!
		e = getLastEntry ();
		writePos = e ? e->offset + e->size : kHeaderSize;
	}

	return seekTo (writePos);
}
Example #2
0
/**************************************************************************************************
/ Retrieve entries from database starting with the entry immediately following the most recent entry retrieved during the previeous session.
/ Parameters: MYSQL *conn
/ Return: int 0 if successful; int <> 0 if error.
**************************************************************************************************/
int dbread(MYSQL *conn)
{

    MYSQL_RES *result;
    MYSQL_ROW row;
    int i;
    char *query, *entry;

    char* lastEntry = getLastEntry(conn);
    entry = "SELECT mote, cattribute, dattribute, SNOWDATA.epoch, mytime, myindex "
            "FROM SNOWDATA "
            "WHERE SNOWDATA.myindex > %s "
            "ORDER BY SNOWDATA.myindex";

    asprintf(&query, entry, lastEntry);
    if (mysql_query(conn, query) != 0){
        printf("SQL Error: %d, %s%c", mysql_errno(conn), mysql_error(conn), '\n');
    }

    result = mysql_store_result(conn);
    int num_fields = mysql_num_fields(result);
    while ((row = mysql_fetch_row(result))){
        for(i = 0; i < (num_fields - 3); i++){
            printf("%s\t", row[i] ? row[i] : "NULL");
        }
        printf("%s\n", row[num_fields - 3] ? row[num_fields - 3] : "NULL");
        entry = "INSERT INTO LATESTQUERY(myindex) VALUES('%s')";
        asprintf(&query, entry, row[5]);
    }

    if(mysql_query(conn, query) != 0){
        printf("SQL Error: %d, %s%c", mysql_errno(conn), mysql_error(conn), '\n');
        mysql_query(conn, query);
    }

    mysql_free_result(result);
//    free(entry);

    return 0;
}