当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteConnection.exec方法代码示例

本文整理汇总了Java中com.almworks.sqlite4java.SQLiteConnection.exec方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteConnection.exec方法的具体用法?Java SQLiteConnection.exec怎么用?Java SQLiteConnection.exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.almworks.sqlite4java.SQLiteConnection的用法示例。


在下文中一共展示了SQLiteConnection.exec方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkCreateColumn

import com.almworks.sqlite4java.SQLiteConnection; //导入方法依赖的package包/类
/**
 * Check if the column exists in the table, if yes, check the type, if no
 * create it with the appropriate type.
 * 
 * @param db
 * @param columnsInTable
 *            A Map containing all columns which exists in the table and
 *            their type.
 * @param tablename
 *            The table which should be checked
 * @param columnname
 *            The column in this table which should be checked
 * @param type
 *            The desired type of the column
 * @throws SQLiteException
 * @throws InconsistentTableException
 *             If the column already exists in the table but the type is
 *             wrong.
 */
private static void checkCreateColumn(SQLiteConnection db, Map<String, String> columnsInTable, String tablename, String columnname, String type)
		throws SQLiteException, InconsistentTableException
{
	String columnnameLower = columnname.toLowerCase();
	String typeUpper = type.toUpperCase();

	if (columnsInTable.containsKey(columnnameLower))
	{
		String actualType = columnsInTable.get(columnnameLower);
		if (!actualType.equals(typeUpper))
		{
			throw new InconsistentTableException("Column " + tablename + "." + columnname + " should be " + typeUpper + " but is " + actualType);
		}
	} else
	{
		LOGGER.debug("Create SQL %s", "ALTER TABLE " + tablename + " ADD COLUMN " + columnname + " " + typeUpper + " DEFAULT NULL;");
		db.exec("ALTER TABLE " + tablename + " ADD COLUMN " + columnname + " " + typeUpper + " DEFAULT NULL;");
	}
}
 
开发者ID:StoragePerformanceAnalyzer,项目名称:SPA,代码行数:39,代码来源:SQLiteHelper.java

示例2: init

import com.almworks.sqlite4java.SQLiteConnection; //导入方法依赖的package包/类
public void init() throws Exception {
	if (!DATABASE_FILE.exists()) {
		File path = DATABASE_FILE.getParentFile();
		if (path != null) {
			path.mkdirs();
		}
		String schemaFilename = DbSchemaManager.SCHEMA_V2_FILENAME;
		log.info("Creating new SQLite schema from file: " + schemaFilename);
		SQLiteConnection sqliteConnection = getSQLiteConnection();
		List<String> schemaDDL = DbSchemaManager.getSchemaDDL(schemaFilename);
		for (String ddl : schemaDDL) {
			sqliteConnection.exec(ddl);
		}
	}
	else {
		//TODO: validate the existing schema
	}
}
 
开发者ID:jagornet,项目名称:dhcp,代码行数:19,代码来源:SqliteLeaseManager.java

示例3: deleteAllIAs

import com.almworks.sqlite4java.SQLiteConnection; //导入方法依赖的package包/类
/**
    * For unit tests only
    */
public void deleteAllIAs() {
	SQLiteConnection connection = null;
	SQLiteStatement statement = null;
	try {
		connection = getSQLiteConnection();
		connection.exec("delete from dhcplease");
	}
	catch (SQLiteException ex) {
		log.error("deleteAllIAs failed", ex);
		throw new RuntimeException(ex);
	}
	finally {
		closeStatement(statement);
		closeConnection(connection);
	}
}
 
开发者ID:jagornet,项目名称:dhcp,代码行数:20,代码来源:SqliteLeaseManager.java

示例4: updateTableFromEClass

import com.almworks.sqlite4java.SQLiteConnection; //导入方法依赖的package包/类
/**
 * Makes sure that all attributes in this eClass have corresponding columns
 * in the table
 * 
 * @param db
 *            The sqlite database connection
 * @param tablename
 *            The sql table which should be checked
 * @param eclass
 *            A EClass describing the columns which are needed.
 * @throws SQLiteException
 */
private static void updateTableFromEClass(SQLiteConnection db, String tablename, EClass eclass) throws SQLiteException
{
	Map<String, String> columnsInTable = getColumnsInTable(db, tablename);

	for (EAttribute ea : eclass.getEAllAttributes())
	{
		String columnname = ea.getName();
		String type = ecoreToSQLType(ea.getEAttributeType());

		checkCreateColumn(db, columnsInTable, tablename, columnname, type);
	}

	for (EReference er : eclass.getEAllReferences())
	{
		EClass contClass = er.getEReferenceType();
		String contClassTableName = tablename + contClass.getName();
		// Create operation specific table + auto increment
		LOGGER.debug("Create SQL %s", "CREATE TABLE IF NOT EXISTS " + contClassTableName
				+ "(runId INTEGER NOT NULL, FOREIGN KEY(runId) REFERENCES " + tablename + "(runId));");
		//LOGGER.debug("Create SQL %s", "CREATE INDEX IF NOT EXISTS " + contClassTableName + "RunIdIdx ON " + contClassTableName + "(id);");
		db.exec("CREATE TABLE IF NOT EXISTS " + contClassTableName
				+ "(runId INTEGER NOT NULL, FOREIGN KEY(runId) REFERENCES " + tablename + "(runId));");
		//db.exec("CREATE INDEX IF NOT EXISTS " + contClassTableName + "RunIdIdx ON " + contClassTableName + "(id);");
		updateTableFromEClass(db, contClassTableName, contClass);
	}
}
 
开发者ID:StoragePerformanceAnalyzer,项目名称:SPA,代码行数:39,代码来源:SQLiteHelper.java

示例5: connectToDB

import com.almworks.sqlite4java.SQLiteConnection; //导入方法依赖的package包/类
public Boolean connectToDB() {
    try {
        Boolean needToPopulateDBFile = false;

        File dbFile = new File(DB_NAME);
        logger.log("opening database file " + DB_NAME);
        if (dbFile.exists() == false) {
            logger.log("database file not found, will create one");
            dbFile.createNewFile();
            logger.log("database file created");
            needToPopulateDBFile = true;
        }
        db = new SQLiteConnection(dbFile);
        db.open(true);

        // Pre-populate Database with tables if database is not there
        if (needToPopulateDBFile) {
            logger.log("need to populate new database file");
            // Begin transaction
            String command = "BEGIN TRANSACTION;";
            logger.logDB(command);
            db.exec(command);

            command = "CREATE TABLE InfoSource(id INTEGER PRIMARY KEY, source TEXT);";
            logger.logDB(command);
            db.exec(command);

            command = "INSERT INTO InfoSource(id, source) VALUES (1, \"NASDAQ\");";
            logger.logDB(command);
            db.exec(command);

            command = "INSERT INTO InfoSource(id, source) VALUES (2, \"NYSE\");";
            logger.logDB(command);
            db.exec(command);

            command = "INSERT INTO InfoSource(id, source) VALUES (3, \"LON\");";
            logger.logDB(command);
            db.exec(command);

            command = "INSERT INTO InfoSource(id, source) VALUES (4, \"SWX\");";
            logger.logDB(command);
            db.exec(command);

            command = "INSERT INTO InfoSource(id, source) VALUES (5, \"INDEXES\");";
            logger.logDB(command);
            db.exec(command);
            
            command = "CREATE TABLE Symbols(id INTEGER PRIMARY KEY, source, symbol TEXT, name TEXT, UNIQUE(source, symbol) ON CONFLICT IGNORE, FOREIGN KEY(source) REFERENCES InfoSource(id));";
            logger.logDB(command);
            db.exec(command);

            // Pre-populate the stock exchange symbols

            // NASDAQ
            Map<String, String> stockSymbols = this.loadStockSymbolsFromFile();
            this.saveStockSymbolsToDB(stockSymbols);

            command = "END TRANSACTION;";
            logger.logDB(command);
            db.exec(command);
        }

    } catch (Exception e) {
        logger.logException(e);
        logger.logError("returning false on connectToDB");
        return false;
    }
    logger.logSuccess("return true on connectToDB");
    return true;
}
 
开发者ID:rrodrigoa,项目名称:SmartStocks,代码行数:71,代码来源:Controller.java

示例6: createTables

import com.almworks.sqlite4java.SQLiteConnection; //导入方法依赖的package包/类
/**
 * Creates actual tables. Method takes table template and inserts it into
 * the database with the corresponding benchmark prefix.
 * 
 * @param db
 *            The SQLite Database connection
 * @param prefix
 *            Benchmark prefix
 * @throws SQLiteException
 */
private void createTables(SQLiteConnection db, String prefix) throws SQLiteException
{
	// Create the two tables, one for independent and one for dependent vars
	String schema = SQLiteDataStore.getSchema("table").replace("{{TEMPLATE}}", prefix);
	db.exec(schema);
}
 
开发者ID:StoragePerformanceAnalyzer,项目名称:SPA,代码行数:17,代码来源:SQLiteHelper.java


注:本文中的com.almworks.sqlite4java.SQLiteConnection.exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。