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