Переглянути джерело

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();

Завантаження…
Відмінити
Зберегти