通过 PetaPoco 使用"desc 表名"命令查询表列



我想获取Mysql数据库中表的列信息,我使用micro-orm库PetaPoco。我的代码如下:

var cols=db.Query<dynamic>("desc t_sometable").ToList();

但它抛出了一个例外,说

You have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc t_sometable' at line 1

我是PetaPoco的新手。谁能帮我解决这个问题?

您需要添加一个分号。 这可以防止 PetaPoco 尝试将列名称添加到它认为将是 Select 的内容中

var cols=db.Query<dynamic>(";desc t_sometable").ToList();

https://github.com/CollaboratingPlatypus/PetaPoco/issues/22

最新更新