Exemple #1
0
	/**
	 * Destructor.
	 */
	DatabaseManager::~DatabaseManager()
	{
		maDBClose(mDatabase);
	}
Exemple #2
0
int testdb2()
{
	int db = maDBOpen("c:\\cprog\\testdb.db");
	if (db < 1)
	{
		printf("maDBOpen failed\n");
	}

	maDBExecSQL(db, "DROP TABLE pet");

	int result = maDBExecSQL(db,
		"CREATE TABLE pet (name TEXT(50), age INTEGER, playfulness DOUBLE)");
	if (0 != result)
	{
		printf("CREATE TABLE failed\n");
	}

	result = maDBExecSQL(db, "INSERT INTO pet VALUES ('Kurre', 13, 0.65)");
	if (0 != result)
	{
		printf("INSERT 1 failed\n");
	}
	result = maDBExecSQL(db, "INSERT INTO pet VALUES ('Vilma', 10, 0.999)");
	if (0 != result)
	{
		printf("INSERT 2 failed\n");
	}

	// Test to get the number of rows.
	MAHandle cursor1 = maDBExecSQL(db, "SELECT COUNT(*) FROM (SELECT * FROM pet)");
	if (cursor1 < 1)
	{
		printf("SELECT COUNT failed\n");
	}
	maDBCursorNext(cursor1);
	int numberOfRows;
	maDBCursorGetColumnInt(cursor1, 0, &numberOfRows);
	printf("Number of rows: %d\n", numberOfRows);
	maDBCursorDestroy(cursor1);

	MAHandle cursor = maDBExecSQL(db, "SELECT * FROM pet");
	if (cursor < 1)
	{
		printf("SELECT failed\n");
	}

	// Print all rows.
	char name[51];
	int age;
	double playfulness;
	while (0 == maDBCursorNext(cursor))
	{
		int length = maDBCursorGetColumnText(cursor, 0, name, 50);
		printf("length: %d\n", length);
		if (length <= 50)
		{
			name[length] = 0;
		}
		else
		{
			strcpy(name, "ERROR: name buffer too small");
		}
		maDBCursorGetColumnInt(cursor, 1, &age);
		maDBCursorGetColumnDouble(cursor, 2, &playfulness);
		printf("%s %d %f\n", name, age, playfulness);
	}

	// Free the cursor.
	maDBCursorDestroy(cursor);

	// Close the database.
	maDBClose(db);
}