瀏覽代碼

Optimization of item_history()

Neal Wilson 11 年之前
父節點
當前提交
2ca47cab56
共有 1 個文件被更改,包括 2 次插入1 次删除
  1. 2
    1
      config/Windows/navigation.xml

+ 2
- 1
config/Windows/navigation.xml 查看文件

@@ -275,8 +275,9 @@ type="push" />
275 275
 			query.exec("CREATE TYPE transaction_type AS (type text, quantity numeric)");
276 276
 			query.exec("CREATE FUNCTION update_balance(numeric, transaction_type) RETURNS numeric AS $$ BEGIN CASE $2.type WHEN 'PURCHASE', 'MAKE' THEN RETURN $1 + $2.quantity; WHEN 'INVENTORY' THEN RETURN $2.quantity; WHEN 'USE', 'SALE', 'LOSS' THEN RETURN $1 - $2.quantity; END CASE; END; $$ LANGUAGE plpgsql STRICT");
277 277
 			query.exec("CREATE AGGREGATE transaction_balance (BASETYPE = transaction_type, SFUNC = update_balance, STYPE = numeric, INITCOND = '0')");
278
-			query.exec("CREATE OR REPLACE FUNCTION item_history(bigint) RETURNS SETOF item_transaction_with_balance AS $$ SELECT time, item, quantity, cost, vendor, customer, type, transaction_balance((type, quantity)::transaction_type) OVER (PARTITION BY item ORDER BY time ASC) AS balance FROM all_transactions WHERE item = $1; $$ LANGUAGE SQL");
278
+			query.exec("CREATE OR REPLACE FUNCTION item_history(bigint) RETURNS SETOF item_transaction_with_balance AS $$ SELECT time, item, quantity, cost, vendor, reason, customer, type, transaction_balance((type, quantity)::transaction_type) OVER (PARTITION BY item ORDER BY time ASC) AS balance FROM all_transactions WHERE item = $1; $$ LANGUAGE SQL");
279 279
 			query.exec("DROP FUNCTION calculate_inventory_balance()");
280
+			query = query.invalidate();
280 281
 		};
281 282
 		
282 283
 		query = new QSqlQuery();

Loading…
取消
儲存