AIR和SQLite:如果表存在的条件条件、存在、AIR、SQLite

2023-09-09 21:45:47 作者:掌灯师

我如何在AS3一个布尔值是否一个表或数据库中的一个条目存在?

How do I get a Boolean value in AS3 whether a table or an entry exists in the database?

推荐答案

至于反对与SQL手动找到它,你应该使用内置的架构信息类/功能。这里是它如何工作的例子。

As opposed to finding it manually with SQL you should use the built in Schema information classes/functions. Here is an example of how it would work.

public function doesTableExist(connection:SQLConnection, tableName:String):Boolean
{
    connection.loadSchema();
    var schema:SQLSchemaResult = connection.getSchemaResult();

    for each (var table:SQLTableSchema in schema.tables)
    {
        if (table.name.toLowerCase() == tableName.toLowerCase())
        {
            return true;
        }
    }
    return false;
}