Java Code Examples for mil.nga.geopackage.db.master.SQLiteMasterType

The following examples show how to use mil.nga.geopackage.db.master.SQLiteMasterType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: geopackage-android   Source File: AlterTableUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Get the expected index count
 *
 * @param db        connection
 * @param tableName table name
 * @return index count
 */
private static int indexCount(GeoPackageCoreConnection db,
                              String tableName) {
    SQLiteMasterQuery indexQuery = SQLiteMasterQuery.createAnd();
    indexQuery.add(SQLiteMasterColumn.TBL_NAME, tableName);
    indexQuery.addIsNotNull(SQLiteMasterColumn.SQL);
    int count = SQLiteMaster.count(db, SQLiteMasterType.INDEX, indexQuery);
    return count;
}
 
Example 2
Source Project: geopackage-android   Source File: AlterTableUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Test the table schema counts
 *
 * @param db           connection
 * @param tableName    table name
 * @param tableCount   table count
 * @param indexCount   index count
 * @param triggerCount trigger count
 * @param viewCount    view count
 */
private static void testTableCounts(GeoPackageConnection db,
                                    String tableName, int tableCount, int indexCount, int triggerCount,
                                    int viewCount) {
    TestCase.assertEquals(tableCount,
            SQLiteMaster.count(db, SQLiteMasterType.TABLE, tableName));
    TestCase.assertEquals(indexCount, indexCount(db, tableName));
    TestCase.assertEquals(triggerCount,
            SQLiteMaster.count(db, SQLiteMasterType.TRIGGER, tableName));
    TestCase.assertEquals(viewCount,
            SQLiteMaster.countViewsOnTable(db, tableName));
}
 
Example 3
Source Project: geopackage-java   Source File: SQLExec.java    License: MIT License 5 votes vote down vote up
/**
 * Build a SQLite Master table query
 * 
 * @param tableName
 *            true to include table name
 * @param type
 *            SQLite Master type
 * @param name
 *            name LIKE value
 * @return SQL
 */
private static String buildSqlMasterQuery(boolean tableName,
		SQLiteMasterType type, String name) {

	StringBuilder sql = new StringBuilder("SELECT ");
	sql.append(SQLiteMasterColumn.NAME.name().toLowerCase());
	if (tableName) {
		sql.append(", ");
		sql.append(SQLiteMasterColumn.TBL_NAME.name().toLowerCase());
	}
	sql.append(" FROM ");
	sql.append(SQLiteMaster.TABLE_NAME);
	sql.append(" WHERE ");
	sql.append(SQLiteMasterColumn.TYPE.name().toLowerCase());
	sql.append(" = '");
	sql.append(type.name().toLowerCase());
	sql.append("' AND ");
	sql.append(SQLiteMasterColumn.NAME.name().toLowerCase());
	sql.append(" NOT LIKE 'sqlite_%'");

	if (name != null) {
		name = name.trim();
		if (!name.isEmpty()) {
			sql.append(" AND ");
			sql.append(SQLiteMasterColumn.NAME.name().toLowerCase());
			sql.append(" LIKE ");
			sql.append(CoreSQLUtils.quoteWrap(name));
		}
	}

	sql.append(" ORDER BY ");
	sql.append(SQLiteMasterColumn.NAME.name().toLowerCase());
	sql.append(";");

	return sql.toString();
}
 
Example 4
Source Project: geopackage-java   Source File: AlterTableUtils.java    License: MIT License 3 votes vote down vote up
/**
 * Get the expected index count
 * 
 * @param db
 *            connection
 * @param tableName
 *            table name
 * @return index count
 */
private static int indexCount(GeoPackageCoreConnection db,
		String tableName) {
	SQLiteMasterQuery indexQuery = SQLiteMasterQuery.createAnd();
	indexQuery.add(SQLiteMasterColumn.TBL_NAME, tableName);
	indexQuery.addIsNotNull(SQLiteMasterColumn.SQL);
	int count = SQLiteMaster.count(db, SQLiteMasterType.INDEX, indexQuery);
	return count;
}
 
Example 5
Source Project: geopackage-java   Source File: AlterTableUtils.java    License: MIT License 3 votes vote down vote up
/**
 * Test the table schema counts
 * 
 * @param db
 *            connection
 * @param tableName
 *            table name
 * @param tableCount
 *            table count
 * @param indexCount
 *            index count
 * @param triggerCount
 *            trigger count
 * @param viewCount
 *            view count
 */
private static void testTableCounts(GeoPackageConnection db,
		String tableName, int tableCount, int indexCount, int triggerCount,
		int viewCount) {
	TestCase.assertEquals(tableCount,
			SQLiteMaster.count(db, SQLiteMasterType.TABLE, tableName));
	TestCase.assertEquals(indexCount, indexCount(db, tableName));
	TestCase.assertEquals(triggerCount,
			SQLiteMaster.count(db, SQLiteMasterType.TRIGGER, tableName));
	TestCase.assertEquals(viewCount,
			SQLiteMaster.countViewsOnTable(db, tableName));
}
 
Example 6
Source Project: geopackage-core-java   Source File: GeoPackageCoreConnection.java    License: MIT License 2 votes vote down vote up
/**
 * Check if the table exists
 * 
 * @param tableName
 *            table name
 * @return true if exists
 */
public boolean tableExists(String tableName) {
	return SQLiteMaster.count(this, SQLiteMasterType.TABLE, tableName) > 0;
}