Difference between revisions of "VbzCart/queries"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(→‎qryCat_Items: found the problem -- function usage syntax)
(→‎new queries: many more queries no longer in db)
 
(237 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
[[VbzCart]]: [[VbzCart data views|data views]]
 
[[VbzCart]]: [[VbzCart data views|data views]]
 
==Overview==
 
==Overview==
"Views" in [[MySQL]] are like SELECT "queries" in [[MS Access]], i.e. they pull data from existing tables and are themselves usable as data sources in much the same way that tables are (and in which result sets from functions are not).
+
What [[MS Access]] calls "queries" are called "views" in [[MySQL]], i.e. they pull data from existing tables and are themselves usable as data sources in much the same way that tables are (and in which result sets from functions are not).
==Views==
+
 
 
Some common prefixes:
 
Some common prefixes:
 
* '''qryCbx_''': queries used for filling comboboxes. The unique ID will always be the first field, and the text to display will always be the second field; additional fields may be provided for use in further '''qryCbx_''' queries which show a subset of the results.
 
* '''qryCbx_''': queries used for filling comboboxes. The unique ID will always be the first field, and the text to display will always be the second field; additional fields may be provided for use in further '''qryCbx_''' queries which show a subset of the results.
 
* '''qryCat_''': queries which build catalog numbers or information by joining multiple tables. (In Access, the convention was '''qryCatNum_'''.)
 
* '''qryCat_''': queries which build catalog numbers or information by joining multiple tables. (In Access, the convention was '''qryCatNum_'''.)
===qryCat_Depts===
+
==by category==
<mysql>
+
===Inactive===
CREATE OR REPLACE VIEW qryCat_Depts AS
+
* [[/deprecated]]: queries we're trying to [[/discarded|get rid of]], once we're sure nothing uses them
  SELECT
+
* [[/discarded]]: queries apparently no longer in use
    d.ID,
+
 
    d.Name,
+
===Catalog===
    d.Sort,
+
* [[/qryCat_Depts]]
    d.CatKey,
+
* '''Title'''-centric:
    d.ID_Supplier,
+
** [[/qryTitles_Item_info]]
    CONCAT_WS('-',s.CatKey,d.CatKey) AS CatNum
+
** [[/qryTitles_ItTyps_grpItems]]
  FROM depts AS d LEFT JOIN suppliers AS s ON d.ID_Supplier=s.ID;</mysql>
+
** [[/qryTitles_ItTyps_ItTyps]]
===qryCat_Titles===
+
** [[/qryTitles_ItTyps_Titles]]
<sql>CREATE OR REPLACE VIEW qryCat_Titles AS
+
** [[/qryTitles_Imageless]] - titles with no active images
  SELECT
+
** [[/qryCat_Titles]]
    t.ID,
+
** [[/qryCat_Titles_Item_stats]] -- item/stock statistics
    t.Name,
+
** [[/qryCat_Titles_Item_count]] -- simpler query for maintenance
    CONCAT_WS('-',d.CatNum,t.CatKey) AS CatNum,
+
** [[/qryCat_Titles_web]]
    d.ID_Supplier,
+
** [[/qryCbx_Titles]]
    t.ID_Dept,
+
* '''Item'''-centric:
    t.DateAdded,
+
** [[/qryCat_Items_Stock]]: cat_items with stock info
    t.RstkMin AS QtyMin_Rstk,
+
* '''ItTyp'''-centric:
    t.Notes,
+
** [[/qryItTypsDepts_grpItems]]
    t.Supplier_CatNum AS Supp_CatNum
+
** [[/qryItTypsDepts_ItTyps]]
  FROM titles AS t LEFT JOIN qryCat_Depts AS d ON t.ID_Dept=d.ID;</sql>
+
* '''Image'''-centric:
===qryCat_Items===
+
** [[/qryImgs_byTitle]]: Image info by Title
<sql>SELECT
+
* [[/qryCat_pages]]: maps http path info to catalog entities
  i.ID,
+
====Catalog Items====
  i.ID_Title,
+
* [[/qryCbx_Items_data]]
  (t.ID IS NOT NULL) AS TitleExists,
+
** [[/qryCbx_Items]]
  t.ID_Supplier,
+
** [[/qryCbx_Items_active]]
  i.PriceSell,
+
** [[/qryCbx_Items_for_sale]]
  i.PriceList,
+
** [[/qryCbx_Items_opt]]: abbreviated version for contexts where Title is already known
  i.PriceBuy,
+
* [[/qryItems_prices]]: what uses this?
  i.CatNum,
+
====Catalog Sources====
  t.CatNum AS Title_CatNum,
+
* [[/qryCtg_Sources_active]]
  t.Name AS Title_Name,
+
* [[/qryCtg_Items_updates]]
  i.ID_ItTyp,
+
* [[/qryCtg_Items_updates_joinable]]
  i.ID_ItOpt,
+
* [[/qryCtg_Items_active]]
  i.ItOpt_Descr,
+
* <s>[[/qryCtg_build_sub]]</s>
  i.ItOpt_Sort,
+
* <s>[[/qryCtg_build]]</s>
  CONCAT(t.Name, IF
+
* '''[[VbzCart catalog building|building]] process''':
      (i.ItOpt_Descr IS NULL,'',CONCAT(
+
** [[/qryCtg_Items_forUpdJoin]]
        ' (',i.ItOpt_Descr,')'
+
** [[/qryCtg_Upd_join]]
        )
+
** [[/qryCtg_src_dups]]
      )
+
** [[/qryCtgCk_dup_keys]]
    ) AS Descr,
+
 
  i.Supp_CatNum,
+
====Catalog Topics====
  i.isForSale,
+
* '''titles x topics''':
  i.isPulled,
+
** [[/qryTitleTopic_Titles]]: more title information
  i.QtyMin_Stk,
+
** [[/qryTitleTopic_Topics]]: more topic information
  t.QtyMin_Rstk AS QtyMin_Rstk_Title
+
** [[/qryTitleTopic_Title_avail]]: title availability information
FROM cat_items AS i LEFT JOIN qryCat_Titles AS t on i.ID_Title=t.ID
+
===Ordering===
ORDER BY t.ID IS NOT NULL, i.CatNum, i.ItOpt_Sort;</sql>
+
====Carts====
 +
* [[/qryCarts_info]]
 +
** [[/qrySub_Carts_info_data]]
 +
** [[/qrySub_Carts_info_items]]
 +
====Customers====
 +
* [[/qryCustAddrs]]
 +
* [[/qryCbx_CustNames]]
 +
====Orders====
 +
* [[/qryCbx_Orders]]
 +
* [[/qryOrderLines_notPkgd]]
 +
* [[/qryOrders_Active]]
 +
* [[/qryOrderLines_Active]]
 +
* [[/qtyOrderItems_Active]]
 +
* [[/qry_PkgItem_qtys_byOrder]]
 +
* [[/qryOrdItms_Pkg_qtys]]
 +
* [[/qryOrdItms_open]]
 +
* [[/qryItms_open]]
 +
* [[/qryItms_to_restock_union]]
 +
* [[/qryItms_to_restock]]
 +
====Packages====
 +
* [[/qryPkgLines_byOrdLine_andItem]]
 +
* [[/qryOrdLines_PkgdQtys]]
 +
* [[/qryOrdLines_open]]
 +
* [[/qryOrders_Pulled]]
 +
* [[/qryPkgs_Pull_status]]
 +
* for reports:
 +
** [[/qryRpt_Pkg_Lines]]
 +
*** [[/qryPkgLines_qtys_done]]
 +
*** <s>[[/qryPkgLines_qtys_done_ord_sum]]</s> - not used
 +
** [[/qryRpt_Pkg_Trx]]
 +
 
 +
====Restocks====
 +
* '''all restock requests''':
 +
** [[/qryRstks_info]]
 +
** [[/qryRstkReq_Item_Rcd_status]]
 +
** [[/qryRstkReq_Item_status]]
 +
*** [[/qryRstkReq_Item_status_Req_info]]
 +
*** [[/qryRstkReq_Items_expected]]: show only expected items
 +
** [[/qryCbx_RstkReq]]
 +
*** [[/qryRstkReq_by_status]]
 +
*** [[/qryRstkReq_by_PurchOrd]]
 +
* '''filtered by status''':
 +
** [[/qryRstks_active]]: not terminated = !(closed, orphaned or killed - see {{l/vc/term|restock/status}})
 +
*** [[/qryRstks_unsent]]: created but not ordered yet
 +
**** [[/qryRstkItms_unsent]]
 +
***** [[/qryRstkItms_unsent_for_order]]
 +
** [[/qryRstks_inactive]]: all the rest
 +
 
 +
====Shipping====
 +
* [[/qryPkgs_status]]
 +
 
 +
===Stock===
 +
====new queries====
 +
* [[/qryStk_Bins_w_info]]
 +
* [[/qryStk_lines_remaining]]
 +
** [[/qryStk_lines_remaining_byBin]]
 +
** [[/qryStk_lines_remaining_forSale]]
 +
*** [[/qryStkItms_for_sale]]
 +
 
 +
* [[/qryStk_items_remaining]]
 +
* [[/qryStk_byItem_byBin]]
 +
 
 +
* [[/qryStk_lines_Title_info]]
  
* '''MySQL note''': Functions (or CONCAT, anyway) apparently do not like being separated from their opening parenthesis; it seems to resolve the function name as a field name, and (generally) will report that there is no such field.
+
====old queries====
 +
This was the first batch of queries I created, before I had decided to go with the qry prefix as in Access.
 +
* [[/v_stk_titles_remaining]]
 +
* [[/v_stk_byItemAndBin_wItemInfo]]
  
===qryCbx_Items===
+
===Caching===
<sql>SELECT
+
Caching should only be used for catalog display.
  i.ID,
+
* [[/qryCache_Flow_Procs]]
  CONCAT(
 
    IF(i.isPulled,CONCAT('!PULLED (',i.ID,')'),''),
 
    i.CatNum,
 
    IF(i.Supp_CatNum IS NULL,'',CONCAT('[',i.SuppCatNum,']')),
 
    IF(i.isForSale,'',' n/a'),
 
    i.Descr)
 
      AS Descr,
 
  i.isForSale
 
FROM qryCat_Items AS i
 
ORDER BY NOT i.isPulled, i.isForSale, i.CatNum;</sql>
 

Latest revision as of 23:12, 3 March 2016

Navigation

VbzCart: data views

Overview

What MS Access calls "queries" are called "views" in MySQL, i.e. they pull data from existing tables and are themselves usable as data sources in much the same way that tables are (and in which result sets from functions are not).

Some common prefixes:

  • qryCbx_: queries used for filling comboboxes. The unique ID will always be the first field, and the text to display will always be the second field; additional fields may be provided for use in further qryCbx_ queries which show a subset of the results.
  • qryCat_: queries which build catalog numbers or information by joining multiple tables. (In Access, the convention was qryCatNum_.)

by category

Inactive

Catalog

Catalog Items

Catalog Sources

Catalog Topics

Ordering

Carts

Customers

Orders

Packages

Restocks

Shipping

Stock

new queries

old queries

This was the first batch of queries I created, before I had decided to go with the qry prefix as in Access.

Caching

Caching should only be used for catalog display.