1
我们正在为多人游戏开发数据库后端。服务器用C#编写,并通过Npgsql与Postgres数据库通信。现在Npgsql:准备好的语句如何准备
,手册说明了如何使用准备好的语句:
NpgsqlCommand command = new NpgsqlCommand("select * from tablea where column1 = :column1", conn);
// Now add the parameter to the parameter collection of the command specifying its type.
command.Parameters.Add(new NpgsqlParameter("column1", NpgsqlDbType.Integer);
// Now, prepare the statement.
command.Prepare();
// Now, add a value to it and later execute the command as usual.
command.Parameters[0].Value = 4;
,并且声明准备语句是有效的只有内部数据库会话。 我现在有两个问题:
1.)如果我使用相同的命令文本和参数类型创建一个新的NpgsqlCommand对象,或者必须保留该对象并只更改该对象,服务器是否会认识到此命令已准备就绪变量再次执行之前?在该示例中,命令对象在查询之后被放置。
2)将准备好的语句可能提高性能,尽管我们只有在这种风格的简单语句:
SELECT f1,f2 FROM t1
UPDATE t1 SET f1=1, f2=2
这可能是数百个相同样式的查询的连续执行 - 目前正在创建每个查询都有一个新的NpgsqlCommand(以及来自NpgSql池的NpgsqlConnection)对象。
谢谢!
复制是用于读/写文件,不是吗?在这种情况下,因为我们将所有数据都保存在内存中,所以没有用,但是感谢提供准备语句的性能不佳的提示 – Tarnschaf 2010-12-21 01:05:22