mil.nga.geopackage.db.master.SQLiteMasterQuery Java Examples

The following examples show how to use mil.nga.geopackage.db.master.SQLiteMasterQuery. 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 File: AlterTableUtils.java    From geopackage-android with 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 File: CoreSQLUtils.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create a new name by replacing a case insensitive value with a new value.
 * If no replacement is done, create a new name in the form name_#, where #
 * is either 2 or one greater than an existing name number suffix. When a db
 * connection is provided, check for conflicting SQLite Master names and
 * increment # until an available name is found.
 * 
 * @param db
 *            optional connection, used for SQLite Master name conflict
 *            detection
 * @param name
 *            current name
 * @param replace
 *            value to replace
 * @param replacement
 *            replacement value
 * @return new name
 * @since 3.3.0
 */
public static String createName(GeoPackageCoreConnection db, String name,
		String replace, String replacement) {

	// Attempt the replacement
	String newName = name.replaceAll("(?i)" + replace, replacement);

	// If no name change was made
	if (newName.equals(name)) {

		String baseName = newName;
		int count = 1;

		// Find any existing end number: name_#
		int index = baseName.lastIndexOf("_");
		if (index >= 0 && index + 1 < baseName.length()) {
			String numberPart = baseName.substring(index + 1);
			if (NUMBER_PATTERN.matcher(numberPart).matches()) {
				baseName = baseName.substring(0, index);
				count = Integer.valueOf(numberPart);
			}
		}

		// Set the new name to name_2 or name_(#+1)
		newName = baseName + "_" + (++count);

		if (db != null) {
			// Check for conflicting SQLite Master table names
			while (SQLiteMaster.count(db, SQLiteMasterQuery
					.create(SQLiteMasterColumn.NAME, newName)) > 0) {
				newName = baseName + "_" + (++count);
			}
		}

	}

	return newName;
}
 
Example #3
Source File: AlterTableUtils.java    From geopackage-java with 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;
}