swift “Any”类型的值没有成员“int”,无法从PostgresClientKit提取行数

7fhtutme  于 2023-02-15  发布在  Swift
关注(0)|答案(1)|浏览(128)

我尝试使用PostgresClientKit从PostgreSQL数据库中获取行数,但我收到以下错误:类型为"Any"的值没有成员"int"。
这是密码

let rows = fetchSQL(statement: "SELECT count(*) FROM ag_graph WHERE name='" + graphName + "'", connection: connection);
        
        let row_counts = rows[0] as! [Any];
        let count = try row_counts[0].int();
        if count < 1{
            // My Code
        }

我试过打印行。它是
1
fetchSQL函数的定义如下

func fetchSQL(statement:String, connection:Connection)-> [Any]{
    var rows:[Any] = [];
    do{
        let statement = try connection.prepareStatement(text: statement)
        defer { statement.close() }
        
        let cursor = try statement.execute()
        defer { cursor.close() }

        for row in cursor {
            rows.append(try row.get().columns);
        }
    }catch{
        print(error)
    }
    
    return rows;
}
jmo0nnb3

jmo0nnb31#

这样试试,可能会有帮助。

let rows = fetchSQL(statement: "SELECT count(*) FROM ag_graph WHERE name='" + graphName + "'", connection: connection);
            print(rows)
            let row_counts = rows[0] as! [PostgresValue];
            let count = try row_counts[0].int();
            if count < 1{
                // your code
            }

相关问题