1 -- you might want to limit the space here (or create the database with
6 -- filename='e:\msde\data\bse.mdf'
9 drop procedure bse_update_article
11 drop procedure bse_add_article
13 drop proc bse_get_articles
15 drop proc bse_get_an_article
17 drop proc bse_articles_by_level
19 drop proc bse_articles_by_parent
21 drop proc bse_delete_article
25 CREATE TABLE article (
26 id integer NOT NULL identity,
27 -- 0 for the entry page
28 -- -1 for top-level sections (shown in side menu)
29 parentid integer DEFAULT 0 NOT NULL,
31 -- the order to display articles in
32 -- used for ordering sibling articles
33 displayOrder integer not NULL default 0,
34 title varchar(64) DEFAULT '' NOT NULL,
35 titleImage varchar(64) not null,
39 thumbImage varchar(64) not null default '',
40 thumbWidth integer not null,
41 thumbHeight integer not null,
43 -- position of first image for this article
44 imagePos char(2) not null,
45 release datetime DEFAULT '2000-01-01 00:00:00' NOT NULL,
46 expire datetime DEFAULT '2099-12-31 00:00:00' NOT NULL,
49 -- the template in $TMPLDIR used to generate this as HTML
50 template varchar(127) DEFAULT '' NOT NULL,
52 -- a link to the page generated for this article
53 -- if this is blank then no page is generated
54 -- this is combined with the base of the site to get the file
55 -- written to during generation
56 link varchar(64) not null,
57 admin varchar(64) not null,
59 -- if there are more child articles than this, display links/summaries
60 -- if the same of fewer, embed the articles
61 -- the template can ignore this
62 threshold integer not null default 3,
64 -- the length of summary to display for this article
65 summaryLength integer DEFAULT '200' NOT NULL,
67 -- the class whose generate() method generates the page
68 generator varchar(20) not null default 'article',
70 -- the level of the article, 1 for top-level
71 artLevel integer not null,
75 -- 1 - list everywhere
76 -- 2 - list in sections, but not on the menu
77 listed smallint not null default 1,
80 lastModified datetime not null default getdate(),
84 create index article_date_index on article
87 create index article_displayOrder_index on article
90 create index article_parentId_index on article
93 create index article_level_index on article
96 drop proc bse_clear_search_index
98 drop proc bse_add_searchindex
102 drop proc bse_search_wc
104 DROP TABLE searchindex
106 CREATE TABLE searchindex (
107 id varbinary(200) NOT NULL,
108 -- a comma-separated lists of article and section ids
109 articleIds varchar(255) default '' not null,
110 sectionIds varchar(255) default '' not null,
111 scores varchar(255) default '' not null,
115 drop procedure bse_add_image
117 drop procedure bse_update_image
119 drop proc bse_get_images
121 drop proc bse_delete_image
123 drop proc bse_get_article_images
128 id integer NOT NULL identity,
129 articleId integer not null,
130 image varchar(64) DEFAULT '' NOT NULL,
131 alt varchar(255) DEFAULT '[Image]' NOT NULL,
140 CREATE TABLE sessions (
141 id char(32) not null primary key,
143 -- so we can age this table
145 whenChanged timestamp
148 drop procedure bse_update_product
150 drop procedure bse_add_product
152 drop proc bse_get_products
154 drop proc bse_get_a_product
158 create table product (
159 -- fkey to article id
160 articleId integer not null,
162 summary varchar(255) not null,
164 -- number of days it typically takes to supply this item
165 leadTime integer not null default 0,
167 -- prices are in cents
168 retailPrice integer not null,
169 wholesalePrice integer,
171 -- amount of GST on this item
172 gst integer not null,
174 options varchar(255) not null,
176 primary key(articleId)
179 drop procedure bse_add_order
181 drop procedure bse_update_order
183 drop procedure bse_get_orders
185 drop procedure bse_get_an_order
188 create table orders (
189 id integer not null identity,
192 delivFirstName varchar(127) not null default '',
193 delivLastName varchar(127) not null default '',
194 delivStreet varchar(127) not null default '',
195 delivSuburb varchar(127) not null default '',
196 delivState varchar(40) not null default '',
197 delivPostCode varchar(40) not null default '',
198 delivCountry varchar(127) not null default 'Australia',
201 billFirstName varchar(127) not null default '',
202 billLastName varchar(127) not null default '',
203 billStreet varchar(127) not null default '',
204 billSuburb varchar(127) not null default '',
205 billState varchar(40) not null default '',
206 billPostCode varchar(40) not null default '',
207 billCountry varchar(127) not null default 'Australia',
209 telephone varchar(80) not null default '',
210 facsimile varchar(80) not null default '',
211 emailAddress varchar(255) not null default '',
214 total integer not null,
215 wholesaleTotal integer not null default 0,
216 gst integer not null,
218 orderDate datetime not null,
220 -- credit card information
221 ccNumberHash varchar(127) not null default '',
222 ccName varchar(127) not null default '',
223 ccExpiryHash varchar(127) not null default '',
224 ccType varchar(30) not null,
226 -- non-zero if the order was filled
227 filled integer not null default 0,
229 whoFilled varchar(40) not null default '',
231 -- if the order has been paid for
232 paidFor integer not null default 0,
233 paymentReceipt varchar(40),
235 -- hard to guess identifier
236 randomId varchar(40),
238 -- order was cancelled
239 cancelled integer not null default 0,
244 create index order_cchash on orders
247 drop proc bse_add_order_item
249 drop proc bse_order_items_by_order
251 DROP TABLE order_item;
252 create table order_item (
253 id integer not null identity,
254 -- foreign key to product
255 productId integer not null,
257 -- foreign key to order
258 orderId integer not null,
261 units integer not null,
264 price integer not null,
265 wholesalePrice integer not null,
266 gst integer not null,
268 options varchar(255) not null,
273 create index order_item_order on order_item
276 create procedure bse_update_article
279 @displayOrder integer,
281 @titleImage varchar(64),
283 @thumbImage varchar(64),
285 @thumbHeight integer,
289 @keyword varchar(255),
290 @template varchar(127),
294 @summaryLength integer,
295 @generator varchar(20),
298 @lastModified datetime
300 update article set parentid = @parentid, displayOrder = @displayOrder,
301 title = @title, titleImage = @titleImage, body = @body,
302 thumbImage = @thumbImage, thumbWidth = @thumbWidth,
303 thumbHeight = @thumbHeight, imagePos = @imagePos,
304 release = @release, expire = @expire, keyword = @keyword,
305 template = @template, link = @link, admin = @admin,
306 threshold = @threshold, summaryLength = @summaryLength,
307 generator = @generator, artLevel = @artLevel, listed = @listed,
308 lastModified = @lastModified
311 create procedure bse_add_article
313 @displayOrder integer,
315 @titleImage varchar(64),
317 @thumbImage varchar(64),
319 @thumbHeight integer,
323 @keyword varchar(255),
324 @template varchar(127),
328 @summaryLength integer,
329 @generator varchar(20),
332 @lastModified datetime
334 insert into article(parentid, displayOrder, title, titleImage, body,
335 thumbImage, thumbWidth, thumbHeight, imagePos, release, expire,
336 keyword, template, link, admin, threshold, summaryLength,
337 generator, artLevel, listed, lastModified)
338 values (@parentid, @displayOrder, @title, @titleImage, @body, @thumbImage,
339 @thumbWidth, @thumbHeight, @imagePos, @release, @expire, @keyword,
340 @template, @link, @admin, @threshold, @summaryLength, @generator,
341 @artLevel, @listed, @lastModified)
343 create proc bse_get_articles
345 select * from article
347 create proc bse_get_an_article
350 select * from article where id = @id
352 create proc bse_articles_by_level
355 select * from article where artLevel = @artLevel
357 create proc bse_articles_by_parent
360 select * from article where parentid = @parentid
362 create proc bse_delete_article
365 delete from article where id = @id
367 create proc bse_get_images
371 create proc bse_delete_image
374 delete from image where id = @id
376 create procedure bse_update_image
385 set articleId = @articleId, image = @image, alt = @alt, width = @width,
389 create procedure bse_add_image
396 insert into image(articleId, image, alt, width, height)
397 values(@articleId, @image, @alt, @width, @height)
399 create proc bse_get_article_images
402 select * from image where articleId = @articleId
404 create procedure bse_update_product
406 @summary varchar(255),
408 @retailPrice integer,
409 @wholesalePrice integer,
411 @options varchar(255)
414 set summary = @summary, leadTime = @leadTime, retailPrice = @retailPrice,
415 wholesalePrice = @wholesalePrice, gst = @gst, options = @options
416 where articleId = @articleId
418 create procedure bse_add_product
420 @summary varchar(255),
422 @retailPrice integer,
423 @wholesalePrice integer,
425 @options varchar(255)
427 insert into product(articleId, summary, leadTime, retailPrice,
428 wholesalePrice, gst, options)
429 values(@articleId, @summary, @leadTime, @retailPrice,
430 @wholesalePrice, @gst, @options)
432 create proc bse_get_products
434 select article.*, product.* from article, product where id = articleId
436 create proc bse_get_a_product
439 select article.*, product.* from article, product
440 where id=@id and articleId = id
443 create proc bse_clear_search_index
445 delete from searchindex
447 create proc bse_add_searchindex
448 @phrase varchar(200),
449 @articleIds varchar(255),
450 @sectionIds varchar(255),
453 insert into searchindex values(cast(@phrase as varbinary(200)), @articleIds, @sectionIds, @scores)
455 create proc bse_search
458 select * from searchindex where id = cast(@phrase as varbinary)
460 create proc bse_search_wc
461 @phrase varbinary(200)
463 select * from searchindex where id like @phrase
465 create proc bse_add_order
466 @delivFirstName varchar(127),
467 @delivLastName varchar(127),
468 @delivStreet varchar(127),
469 @delivSuburb varchar(127),
470 @delivState varchar(40),
471 @delivPostCode varchar(40),
472 @delivCountry varchar(127),
473 @billFirstName varchar(127),
474 @billLastName varchar(127),
475 @billStreet varchar(127),
476 @billSuburb varchar(127),
477 @billState varchar(40),
478 @billPostCode varchar(40),
479 @billCountry varchar(127),
480 @telephone varchar(80),
481 @facsimile varchar(80),
482 @emailAddress varchar(255),
484 @wholesaleTotal integer,
487 @ccNumberHash varchar(127),
488 @ccName varchar(127),
489 @ccExpiryHash varchar(127),
492 @whenFilled datetime,
493 @whoFilled varchar(40),
495 @paymentReceipt varchar(40),
496 @randomId varchar(40),
499 insert into orders(delivFirstName, delivLastName, delivStreet, delivSuburb,
500 delivState, delivPostCode, delivCountry, billFirstName, billLastName,
501 billStreet, billSuburb, billState, billPostCode, billCountry,
502 telephone, facsimile, emailAddress, total, wholesaleTotal, gst,
503 orderDate, ccNumberHash, ccName, ccExpiryHash, ccType,
504 filled, whenFilled, whoFilled, paidFor, paymentReceipt, randomId,
506 values(@delivFirstName, @delivLastName, @delivStreet, @delivSuburb,
507 @delivState, @delivPostCode, @delivCountry, @billFirstName,
508 @billLastName, @billStreet, @billSuburb, @billState, @billPostCode,
509 @billCountry, @telephone, @facsimile, @emailAddress, @total,
510 @wholesaleTotal, @gst, @orderDate, @ccNumberHash, @ccName,
511 @ccExpiryHash, @ccType, @filled, @whenFilled, @whoFilled, @paidFor,
512 @paymentReceipt, @randomId, @cancelled)
516 create proc bse_update_order
518 @delivFirstName varchar(127),
519 @delivLastName varchar(127),
520 @delivStreet varchar(127),
521 @delivSuburb varchar(127),
522 @delivState varchar(40),
523 @delivPostCode varchar(40),
524 @delivCountry varchar(127),
525 @billFirstName varchar(127),
526 @billLastName varchar(127),
527 @billStreet varchar(127),
528 @billSuburb varchar(127),
529 @billState varchar(40),
530 @billPostCode varchar(40),
531 @billCountry varchar(127),
532 @telephone varchar(80),
533 @facsimile varchar(80),
534 @emailAddress varchar(255),
536 @wholesaleTotal integer,
539 @ccNumberHash varchar(127),
540 @ccName varchar(127),
541 @ccExpiryHash varchar(127),
544 @whenFilled datetime,
545 @whoFilled varchar(40),
547 @paymentReceipt varchar(40),
548 @randomId varchar(40),
552 set delivFirstName = @delivFirstName, delivLastName = @delivLastName,
553 delivStreet = @delivStreet, delivSuburb = @delivSuburb,
554 delivState = @delivState, delivPostCode = @delivPostCode,
555 delivCountry = @delivCountry, billFirstName = @billFirstName,
556 billLastName = @billLastName, billStreet = @billStreet,
557 billSuburb = @billSuburb, billState = @billState,
558 billPostCode = @billPostCode, billCountry = @billCountry,
559 telephone = @telephone, facsimile = @facsimile,
560 emailAddress = @emailAddress, total = @total,
561 wholesaleTotal = @wholesaleTotal, gst = @gst,
562 orderDate = @orderDate, ccNumberHash = @ccNumberHash,
563 ccName = @ccName, ccExpiryHash = @ccExpiryHash, ccType = @ccType,
564 filled = @filled, whenFilled = @whenFilled, whoFilled = @whoFilled,
565 paidFor = @paidFor, paymentReceipt = @paymentReceipt,
566 randomId = @randomId, cancelled = @cancelled
570 create proc bse_get_orders
574 create proc bse_get_an_order
577 select * from orders where id = @id
579 create proc bse_add_order_item
584 @wholesalePrice integer,
586 @options varchar(255)
588 insert into order_item(productId, orderId, units, price,
589 wholesalePrice, gst, options)
590 values(@productId, @orderId, @units, @price, @gst, @wholesalePrice,
593 create proc bse_order_items_by_order
596 select * from order_item where orderId = @orderId