-
Notifications
You must be signed in to change notification settings - Fork 0
/
icdatabase.sdf
4228 lines (2958 loc) · 172 KB
/
icdatabase.sdf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!init OPT_LOOK="icdevgroup"; OPT_STYLE="manual"
# $Id: icdatabase.sdf,v 1.66 2004-05-05 15:22:30 jon Exp $
!define DOC_NAME "Interchange Databases"
!define DOC_TYPE ""
!define DOC_CODE "icdatabase"
!define DOC_VERSION substr('$Revision: 1.66 $',11, -2)
!define DOC_STATUS "Draft"
!define DOC_PROJECT "Interchange"
!define DOC_URL "http://www.icdevgroup.org/doc/icdatabase.html"
!build_title
H1: Databases and Interchange
Interchange is database-independent, perhaps more so than almost
any other powerful content management system.
Interchange can use GDBM, DB_File, SQL, LDAP, or in-memory databases. In
most cases, these different database formats should operate the same
when called by Interchange's access methods.
Also, most all of Interchange's core functions do not use hard-coded
field names; virtually every field can have a configurable name.
Interchange does not require an external SQL database. If you have
a small data set and do not want to integrate your own tool set, you
cound use Interchange's internal database. However, the order
management functions of Interchange will be slower and not as robust
without an SQL database. SQL is strongly recommended for at least the
C<state>, C<country>, C<orderline>, C<transactions>, and C<userdb> tables. Any other
tables that will have programmatic updates, such as C<inventory>, will
be best placed in SQL.
If you plan on using Interchange Admin UI, you should make the move
to SQL. It provides easy import routines for text files that should
replace text-file uploads.
Keeping a database in an SQL manager makes it easier to integrate
Interchange with other tools. Interchange can be used to maintain a
spreadsheet containing product information through modifying the
file C<products.txt> as needed. References to SQL, DBI, and DBD can
be ignored.
H2: Text Source Files
Interchange reads delimited text files to obtain its initial data.
However, the text files are not the database. They are the source
information for the database tables.
By default, all database source files are located in the C<products>
subdirectory of the catalog directory. The main products database is in
the C<products/products.txt> file in the supplied demo catalog.
Note:If you are using one of the internal database methods, any changes made to the ASCII source file will be reflected in the database in the next user session. If the product database contains less than a thousand records, updates will be instantaneous. If the product database is larger, updates will take longer. Use the C<NoImport> reference tag to stop auto updating.
In the following configuration directive:
!block example
Database products products.txt TAB
!endblock
the C<products> table will obtain its source information from the file C<products.txt>. What is done with it depends on the type of underlying database being used. The different types and their behavior are described below:
LI1: GDBM
.The database source file is checked to see if it is newer than the actual database file, C<products.gdbm>. If it is, the database table is re-imported from the file.
.This behavior can be changed in a few ways. If files should not be imported unless the C<.gdbm> file disappears, set the C<NoImport> directive:
!block example; listitem=2
NoImport products
!endblock
.If the database source file is only to be imported at catalog start-up time, use the IMPORT_ONCE modifier:
!block example; listitem=2
Database products IMPORT_ONCE 1
!endblock
.GDBM is the default database type if the GDBM_File Perl module is installed (as it is on LINUX).
LI1: DB_File
.The database source file is checked to see if it is newer than the actual database file, C<products.db>. If it is, the database table is re-imported from the file. You can change this behavior in the same way as GDBM_File, described above.
.DB_File is the default database type if the GDBM_File Perl module is not installed. This is common on FreeBSD. To specify DB_File as your database type, set it in C<catalog.cfg> with a Database directive:
!block example; listitem=2
Database products DB_FILE 1
!endblock
LI1: DBI/SQL
.If a file named C<products.sql> is in the same directory as C<products.txt>, the database table will not be imported from the ASCII source. If there is no C<products.sql>, the following will occur:
.DBI/SQL imports will only happen at catalog configuration time.
.^Interchange will connect to the SQL database using the specified DSN. (DBI parameter meaning "Database Source Name".)
.+The table will be dropped with "DROP TABLE products;". This will occur without warning. NOTE: This can be prevented in several ways. See C<NoImport External> or the SQL documentation for more information.
.+The table will be created. If there are COLUMN_DEF specifications in C<catalog.cfg>, they will be used. Otherwise, the key (first field in the text file by default) will be created with a C<char(16)> type and all other fields will be created as C<char(128)>. The table creation statement will be written to the C<error.log> file.
..The text source file will be imported into the SQL database. Interchange will place the data in the columns. Data typing must be user-configured. This means that if "none" is placed in a field, and it is defined as a numeric type, the database import will not succeed. And if it does not succeed, the catalog will not become active.
LI1: In-Memory
.Every time the catalog is configured, the C<products.txt> file is imported into memory and forms the database. Otherwise, the database is not changed. The in-memory database is the default database if there is no GDBM_File or DB_File Perl module installed; specify it with:
!block example; listitem=2
Database products MEMORY 1
!endblock
H2: Interchange Database Conventions
This section describes naming and file usage conventions used with Interchange.
Note: Throughout the documentation, the following terms and their definitions are used interchangeably:
LI1: key, code
.A reference to the database key. In Interchange, this is usually the product code or SKU, which is the part number for the product. Other key values may be used to generate relationships to other database tables.
.It is recommended that the key be the first column of the ASCII source file, since Interchange's import, export, and search facilities rely on this practice.
LI1: field, column
.The vertical row of a database. One of the columns is always the key and it is usually the first one.
LI1: table, database
.A table in the database. Because Interchange has evolved from a single-table database to an access method for an unlimited number of tables (and databases, for that matter), a table will occasionally be referred to as a database. The only time the term database refers to something different is when describing the concept as it relates to SQL, where a database contains a series of tables. While Interchange cannot create SQL databases, it can drop and create tables with that database if given the proper permissions.
If necessary, Interchange can read the data to be placed in tables from a standard
ASCII-delimited file. All of the ASCII source files are kept in the products directory, which is normally in the catalog directory (where catalog.cfg is located). The ASCII files can have ^M (carriage return) characters, but must have a new line character at the end of the line to work. NOTE: Mac users uploading files must use ASCII mode, not binary mode.
Interchange's default ASCII delimiter is TAB.
Note:The items must be separated by a single delimiter. The items in this document are lined up for reading convenience.
LI1: TAB
.Fields are separated by C<^I> characters. No whitespace is allowable at the beginning of the line.
!block example; listitem=2
code description price image
SH543 Men's fine cotton shirt 14.95 shirts.jpg
!endblock
LI1: PIPE
.Fields are separated by pipe C<|> characters. No whitespace is allowable at the beginning of the line.
!block example; listitem=2
code|description|price|image
SH543|Men's fine cotton shirt|14.95|shirts.jpg
!endblock
LI1: CSV
.Fields are enclosed in quotes, separated by commas. No whitespace should be at the beginning of the line.
!block example; listitem=2
"code","description","price","image"
"SH543","Men's fine cotton shirt","14.95","shirts.jpg"
!endblock
Note: Using the default TAB delimiter is recommended if you plan on searching the ASCII source file of the database. PIPE works fairly well, but CSV delimiter schemes might cause problems with searching.
Note[label='IMPORTANT NOTE: '] Field names are usually case-sensitive. Use consistency when naming or you might encounter problems. All lower or all upper case names are recommended.
.Interchange uses one mandatory database, which is referred to as the products database. In the supplied demo catalog, it is called products and the ASCII source is kept in the file C<products.txt> in the products directory. This is also the default file for searching with the THE SEARCH ENGINE.
.Interchange also has a two of standard, but optional, databases that are in fixed formats:
LI2: shipping.asc
..The database of shipping options that is accessed if the C<CustomShipping> directive is in use. This is a fixed-format database, and must be created as specified. For more information, see the Shipping ITL tag in the {{1:Interchange Tag Reference Guide}}.
LI2: salestax.asc
..The database of sales tax information if the C<[salestax]> tag is to be used. A default is supplied. NOTE: Caution, these things change! This is a fixed-format database, and must be created as specified. See Sales Tax.
.These are never stored in SQL or DBM.
H2: The Product Database
Each product being sold should be given a product code, usually referred to as SKU, a short code that identifies the product on the ordering page and in the catalog. The products.txt file is a ASCII-delimited list of all the product codes, along with an arbitrary number of fields which must contain at least the fields C<description> and C<price> (or however the C<PriceField> and C<DescriptionField> directives have been set). Any additional information needed in the catalog can be placed in any arbitrary field. See Interchange Database Capability for details on the format.
Field names can be case-sensitive depending on the underlying database type. Unless there are fields with the names "description" and "price" field, set the C<PriceField> and C<DescriptionField> directives to use the C<[item-price]> and C<[item-description]> tags.
The product code, or SKU, must be the first field in the line, and must be unique. Product codes can contain the characters B<A-Za-z0-9>, along with hyphen (C<->), underscore (C<_>), pound sign/hash mark (C<#>), slash (C</>), and period (C<.>). Note that slash (/) will interfere with on-the-fly page references. Avoid if at all possible.
The words should be separated by one of the approved delimiting schemes (TAB, PIPE, or CSV), and are case-sensitive in some cases. If the case of the "description" or "price" fields have been modified, the C<PriceField> and C<DescriptionField> directives must be appropriately set.
Note: CSV is not recommended as the scheme for the products database. It is much slower than TAB- or PIPE-delimited, and dramatically reduces search engine functionality. No field-specific searches are possible. Using CSV for any small database that will not be searched is fine.
Note[label='IMPORTANT NOTE: ']The field names must be on the first line of the C<products.txt> file. These field names must match exactly the field names of the C<[item-field]> tags in the catalog pages, or the Interchange server will not access them properly. Field names can contain the characters A-Za-z0-9 and underscore (C<_>).
More than one database may be used as a products database. If the catalog directive, ProductFiles, is set to a space-separated list of valid Interchange database identifiers, those databases will be searched (in the order specified) for any items that are ordered, or for product information (as in the C<[price code]> and C<[field code]> tags).
When the database table source file (i.e., products.txt) changes after import or edit, a DBM database is re-built upon the next user access. No restart of the server is necessary.
If changing the database on-the-fly, it is recommended that the file be locked while it is being modified. Interchange's supplied import routines do this.
H2: Multiple Database Tables
Interchange can manage an unlimited number of arbitrary database tables. They use the TAB delimiter by default, but several flexible delimiter schemes are available. These are defined by default:
!block example
Type 1 DEFAULT - uses default TAB delimiter
Type 2 LINE
Each field on its own line, a blank line
separates the record. Watch those carriage
returns! Also has a special format when CONTINUE
is set to be NOTES.
Type 3 %%
Fields separated by a \n%%\n combination, records by
\n%%%\n (where \n is a newline). Watch those carriage
returns!
Type 4 CSV
Type 5 PIPE
Type 6 TAB
Type 7 reserved
Type 8 SQL
Type 9 LDAP
!endblock
The databases are specified in C<Database> directives, as:
!block example
Database arbitrary arbitrary.csv CSV
!endblock
This specifies a Type 4 database, the ASCII version of which is located in the
file C<arbitrary.csv>, and the identifier it will be accessed under in Interchange is "arbitrary." The DBM file, if any, will be created in the same directory if the ASCII file is newer, or if the DBM file does not exist. The files will be created as C<arbitrary.db> or C<arbitrary.gdbm>, depending on DBM type.
The C<identifier> is case sensitive, and can only contain characters in the class [A-Za-z0-9_]. Fields are accessed with the [item_data C<identifier> field] or [data C<identifier> field key] elements. NOTE: Use of lower-case letters is strongly recommended.
If one of the first six types is specified, the database will automatically be built in the default Interchange DB style. The type can be specified with DB_FILE, GDBM, or MEMORY, if the type varies from that default. They will coexist with an unlimited number of DBI databases of different types.
In addition to the database, the session files will be kept in the default format, and are affected by the following actions.
The order of preference is:
LI1: GDBM
.This uses the Perl C<GDBM_File> module to build a GDBM database. The following command will indicate if GDBM is in Perl:
!block example; listitem=2
perl -e 'require GDBM_File and print "I have GDBM.\n"'
!endblock
.Installing GDBM_File requires rebuilding Perl after obtaining the GNU GDBM package, and is beyond the scope of this document. LINUX will typically have this by default; most other operating systems will need to specifically build in this capability.
LI1: DB_File (Berkeley DB)
.This uses the C<DB_File> module to build a Berkeley DB (hash) database. The following command will indicate if DB_File is in Perl:
!block example; listitem=2
perl -e 'require DB_File and print "I have Berkeley DB.\n"'
!endblock
.Installing C<DB_File> requires rebuilding Perl after obtaining the Berkeley DB package, and is beyond the scope of this document. BSDI, FreeBSD, and LINUX will typically have it by default; most other operating systems will need to specifically build this in.
.If using C<DB_File>, even though C<GDBM_File> is in Perl, set the environment variable MINIVEND_DBFILE to a true (non-zero, non-blank) value:
!block example; listitem=2
# csh or tcsh
setenv MINIVEND_DBFILE 1
# sh, bash, or ksh
MINIVEND_DBFILE=1 ; export MINIVEND_DBFILE
!endblock
.Then, re-start the server.
.Or, to set a particular table to use Berkeley DB, the DB_FILE class in C<catalog.cfg> can be specified:
!block example; listitem=2
Database arbitrary DB_FILE 1
!endblock
LI1: In-memory
.This uses Perl hashes to store the data directly in memory. Every time the Interchange server is restarted, it will re-import all in-memory databases for every catalog.
.If this is used, despite the presence of C<GDBM_File> or C<DB_File>, set the environment variable MINIVEND_NODBM as above or specify the memory type in the Database directive:
!block example; listitem=2
Database arbitrary MEMORY 1
!endblock
Note: The use of memory databases is not recommended.
H2: Character Usage Restrictions
To review, database identifiers, field names, and product codes (database keys) are restricted in the characters they may use. The following table shows the restrictions:
!block example
Legal characters
---------------------
Database identifiers A-Z a-z 0-9 _
Field names A-Z a-z 0-9 _
Database keys (product code/SKU) A-Z a-z 0-9 _ # - . /
Database values Any (subject to field/record delimiter)
!endblock
Some SQL databases have reserved words which cannot be used as field names; Interchange databases do not have this restriction.
For easy HTML compatibility, it is not recommended that a / be used in a part number if using the flypage capability. It can still be called [page href=flypage arg="S/KU"].
H2: Database Attributes
Especially in SQL databases, there are certain functions that can be set with additional database attributes. For text import, the CONTINUE extended database import attribute allows additional control over the format of imported text.
Note: CONTINUE applies to all types except CSV. (Do not use NOTES unless using type LINE.)
LI1: CONTINUE
.One of UNIX, DITTO, LINE, NONE, or NOTES. The default, NONE, is to simply split the line/record according to the delimiter, with no possible spanning of records. Setting CONTINUE to UNIX appends the next line to the current when it encounters a backslash (C<\>) at the end of a record, just like many UNIX commands and shells.
.DITTO is invoked when the key field is blank. It adds the contents of following fields to the one above, separated by a new line character. This allows additional text to be added to a field beyond the 255 characters available with most spreadsheets and flat-file databases.
.Example in catalog.cfg:
!block example; listitem=2
Database products products.txt TAB
Database products CONTINUE DITTO
!endblock
.Products.asc file:
!block example; listitem=2
code price description
00-0011 500000 The Mona Lisa, one of the worlds great masterpieces.
Now at a reduced price!
!endblock
.The description for product 00-0011 will contain the contents of the C<description> field on both lines, separated by a new line.
Note: Fields are separated by tabs, formatted for reading convenience.
.This will work for multiple fields in the same record. If the field contains any non-empty value, it will be appended.
.LINE is a special setting so a multi-line field can be used. Normally, when using the LINE type, there is only data on one line separated by one blank line. When using CONTINUE LINE, there may be some number of fields which are each on a line, while the last one spans multiple lines up until the first blank line.
.Example in catalog.cfg:
!block example; listitem=2
Database products products.txt LINE
Database products CONTINUE LINE
!endblock
.Products.asc file:
!block example; listitem=2
code
price
description
00-0011
500000
The Mona Lisa, one of the worlds great masterpieces.
Now at a reduced price!
00-0011a
1000
A special frame for the Mona Lisa.
!endblock
.NOTES reads a Lotus Notes "structured text" file. The format is any number of fields, all except one of which must have a field name followed by a colon and then the data. There is optional whitespace after the colon.
.Records are separated by a settable delimiting character which goes on a line by itself, much like a "here document." By default, it is a form feed (^L) character. The final field begins at the first blank line and continues to the end of the record. This final field is named C<notes_field>, unless set as mentioned below.
.Interchange reads the field names from the first paragraph of the file. The key field should be first, followed by other fields in any order. If one (and only one) field name has whitespace, then its name is used for the C<notes_field>. Any characters after a space or TAB are used as the record delimiter.
.If there are none, then the delimiter returns to the default form feed (^L) and the field name reverts to C<notes_field>. The field in question will be discarded, but a second field with whitespace will cause an import error. Following records are then read by name, and only fields with data in them need be set. Only the C<notes_field> may contain a new line. It is always the last field in the record, and begins at the B<first> blank line.
.The following example sets the delimiter to a tilde C<(~)> and renames the C<notes_field> to C<description>.
.Example in catalog.cfg:
!block example; listitem=2
Database products products.txt LINE
Database products CONTINUE NOTES
!endblock
.Products.asc file:
!block example; listitem=2
code
title
price
image
description ~
size
color
title: Mona Lisa
price: 500000
code: 00-0011
image: 00-0011.jpg
The Mona Lisa, one of the worlds great masterpieces.
Now at a reduced price!
~
title: The Art Store T-Shirt
code: 99-102
size: Medium, Large*, XL=Extra Large
color: Green, Blue, Red, White*, Black
price: 2000
Extra large 1.00 extra.
~
!endblock
LI1: EXCEL
.Microsoft Excel is a widely-used tool to maintain Interchange databases, but has several problems with its standard TAB-delimited export, like enclosing fields containing commas in quotes, generating extra carriage returns embedded in records, and not including trailing blank fields. To avoid problems, use a text-qualifier of none.
.Set the EXCEL attribute to 1 to fix these problems on import:
!block example; listitem=2
Database products EXCEL 1
!endblock
.This is normally used only with TAB-delimited files.
LI1: LARGE
.Interchange databases containing many records can result in a noticeable slowdown when displayed by the UI.
.Set the LARGE attribute to 1 to avoid this problem:
!block example
Database transactions LARGE 1
!endblock
.In this case the UI supplies only input boxes to search records in the
database instead of drawing all the records from the database, sorting
them and creating more lists.
H2: Dictionary Indexing With INDEX
Interchange will automatically build index files for a fast binary
search of an individual field. This type of search is useful for looking
up the author of a book based on the beginning of their last name, a
book title based on its beginning, or other similar situations.
Such a search requires a dictionary ordered index with the field to be
searched contained in the first field and the database key (product
code) in the second field. If the C<INDEX field> modifier is specified,
Interchange will build the index upon database import:
!block example
Database products products.txt TAB
Database products INDEX title
!endblock
If the C<title> field is the fourth column in the C<products> database table,
a file C<products.txt.4> will be built, containing two tab-separated fields
something like:
!block example
American Gothic 19-202
Mona Lisa 00-0011
Sunflowers 00-342
The Starry Night 00-343
!endblock
Options can be appended to the field name after a colon (:). The most
useful will be C<f>, which does a case-insensitive sort. The
C<mv_dict_fold> option must be added to the search in this case.
Another option is C<c>, which stands for "comma index." To index on
comma-separated sub-fields within a field, use the :c option:
!block example
Database products products.txt TAB
Database products INDEX category:c
!endblock
This can get slow for larger databases and fields. Interchange will
split the field on a comma (stripping surrounding whitespace) and make
index entries for each one. This allows multiple categories in one field
while retaining the fast category search mechanism. It might also be
useful for a C<keywords> field.
The fast binary search is described in greater detail in THE SEARCH ENGINE below.
H2: MEMORY for Memory-Only Databases
Interchange's memory-based databases are the fastest possible way to
organize and store frequently used data. To force a database to be built
in memory instead of DBM, use the MEMORY modifier:
!block example
Database country country.asc TAB
Database country MEMORY 1
!endblock
Obviously, large tables will use a great deal of memory, and the data
will need to be re-imported from the ASCII source file at every catalog
reconfiguration or Interchange restart. The big advantage of using
MEMORY is that the database remains open at all times and does not need
to be reinitialized at every connect. Use it for smaller tables that
will be frequently accessed.
Memory tables are read only -- the MEMORY modifier forces IMPORT_ONCE.
H2: IMPORT_ONCE
The IMPORT_ONCE modifier tells Interchange not to re-import the database
from the ASCII file every time it changes. Normally, Interchange does a
comparison of the database file modification time with the ASCII source
every time it is accessed, and if the ASCII source is newer it will
re-import the file.
IMPORT_ONCE tells it only to import on a server restart or catalog
reconfiguration:
!block example
Database products products.txt TAB
Database products IMPORT_ONCE 1
!endblock
SQL databases don't normally need this. They will only be imported once
in normal operation. Also see C<NoImport> for a way to guarantee that
the table will never be imported.
IMPORT_ONCE is always in effect for MEMORY databases. A catalog
reconfiguration is required to force a change.
H2: MIRROR
Additionally, you can have two tables, the regular table and the memory
table by adding to the definition files:
> Database country_memory country_memory.txt TAB
> Database country_memory MIRROR country
> Database country_memory MEMORY 1
H2: SQL/DBI parameters
H3: AUTO_SEQUENCE
Tells Interchange to use a SQL sequence to number new database items
inserted into the database.
If you have Interchange create the table, then you need to do:
> Database foo foo.txt dbi:mysql:test
> Database foo AUTO_SEQUENCE foo_seq
Then on MySQL, Pg, or Oracle, Interchange will create an integer
key type and a sequence (or AUTO_INCREMENT in MySQL) to maintain
the count.
H3: AUTO_SEQUENCE_MAXVAL
Sets the MAXVAL to have in an AUTO_SEQUENCE counter:
> Database foo AUTO_SEQUENCE_MAXVAL 1000000
H3: AUTO_SEQUENCE_MINVAL
Sets the MINVAL to have in an AUTO_SEQUENCE counter:
> Database foo AUTO_SEQUENCE_MINVAL 10
H3: AUTO_SEQUENCE_START
Sets the starting value for an AUTO_SEQUENCE counter:
> Database foo AUTO_SEQUENCE_START 1000
H3: COMPOSITE_KEY
If you are using a DBI table with composite keys, where two or more
fields combine to make the unique identifier for a record, you must
tell Interchange so it can request data in the right way. To do
this, set:
> Database product_spec product_spec.asc dbi:mysql:foobase
> Database product_spec COMPOSITE_KEY sku feature
> Database product_spec COLUMN_DEF "sku=varchar(32)"
> Database product_spec COLUMN_DEF "feature=varchar(128)"
If you want to create a custom index for the table, do so. If you
don't specify a POSTCREATE or INDEX parameter for the table, Interchange
will create a unique index with all composite key elements at table
creation time.
H3: DSN
The data source name (DSN) for the database. It is beyond the
scope of this document to describe this in detail.
Normally this is set as the type in the initial C<Database>
configuration line, i.e.
> Database foo foo.txt dbi:mysql:foobase
This has the same effect:
> Database foo foo.txt SQL
> Database foo DSN dbi:mysql:foobase
Some other examples of DSN specs:
> Database foo DSN dbi:mysql:host=db.you.com;database=foobase
> Database foo DSN dbi:Pg:dbname=foobase
> Database foo DSN dbi:Oracle:host=myhost.com;sid=ORCL
H3: HAS_TRANSACTIONS
Informs Interchange that the SQL database in use has commit() and
rollback() for transactions. For PostgreSQL and Oracle this should be
set properly to 1 -- for MySQL and other databases you have to set it.
H3: HAS_LIMIT
Informs Interchange that the SQL database in use has as the LIMIT
extension to SQL to limit return from queries. Should be set properly
by default for MySQL, PostgreSQL, and Oracle.
H3: POSTCREATE
One or more SQL statements that should be performed after
Interchange creates a table.
> Database foo POSTCREATE "create unique index foo_idx on foo(key1,key2)"
> Database foo POSTCREATE "create index mulkey_idx on foo(mulkey)"
H3: PRECREATE
One or more SQL statements that should be performed before
Interchange creates a table.
> Database foo POSTCREATE "drop table foobackup"
> Database foo POSTCREATE "alter table foo rename to foobackup"
H3: REAL_NAME
Sometimes it may be convenient to have a table named a consistent
value in Interchange despite its name in the underlying database.
For instance, two divisions of a company may share orders but
have different C<products> tables. You can tell Interchange to
name the table C<products> for its purposes, but use the C<products_a>
table for SQL statements:
> Database products REAL_NAME products_a
Of course if you have SQL queries that are passed verbatim to
Interchange (i.e. the [query ...] tag) you must use the REAL_NAME
in those.
H2: Importing in a Page
To add a data record to a database as a result of an order or other
operation, use Interchange's C<[import ...]> tag.
LI1: [import table type*] RECORD [/import]
.Named parameters:
!block example; listitem=2
[import table=table_name
file=filename*
type=(TAB|PIPE|CSV|%%|LINE)*
continue=(NOTES|UNIX|DITTO)*
separator=c*]
!endblock
Import one or more records into a database. The C<type> is any of the
valid Interchange delimiter types, with the default being TAB. The
table must already be a defined Interchange database table. It cannot
be created on-the-fly. If on-the-fly functionality is need, it is time
to use SQL.
The import type selected need not match the type the database was specified. Different delimiters may be used.
The C<type> of C<LINE> and C<continue> setting of C<NOTES> is particularly
useful, for it allows fields to be named and not have to be in any particular order of appearance in the database. The following two imports are identical in effect:
!block example
[import table=orders]
code: [value mv_order_number]
shipping_mode: [shipping-description]
status: pending
[/import]
[import table=orders]
shipping_mode: [shipping-description]
status: pending
code: [value mv_order_number]
[/import]
!endblock
The C<code> or key must always be present, and is always named C<code>. If C<NOTES> mode is not used, the fields must be imported in the same order as they appear in the ASCII source file.
The C<file> option overrides the container text and imports directly from a named file based in the catalog directory. To import from C<products.txt>, specify C<file="products/products.txt">. If the NoAbsolute directive is set to C<Yes> in interchange.cfg, only relative path names will be allowed.
The C<[import ....] TEXT [/import]> region may contain multiple records. If using C<NOTES> mode, a separator must be used, which, by default, is a form-feed character (^L). See Import Attributes for more information.
H2: Exporting from a Database
To export an existing database to a file to its text file, suitable for
full-text search by Interchange, use Interchange's UI create a page that contains a
C<[export table=TABLENAME]> ITL tag (ExportTag).
H2: Write Control
Interchange databases can be written in the normal course of events, either
using the C<[import ...]> tag or with a tag like C<[data table=table column=field key=code value=new-value]>. To control writing of a global database, or to a certain catalog within a series of subcatalogs, or make one read only, see the following:
To enable write control:
!block example
Database products WRITE_CONTROL 1
!endblock
Once this is done, to make a database read only, which won't allow writing even if C<[tag flag write]products[/tag]> is specified:
!block example
Database products READ_ONLY 1
!endblock
To have control with C<[tag flag write]products[/tag]>:
!block example
Database products WRITE_TAGGED 1
!endblock
To limit write to certain catalogs, set:
!block example
Database products WRITE_CATALOG simple=0, sample=1
!endblock
The "simple" catalog will not be able to write, while "sample" will if C<[tag flag write]products[/tag]> is enabled. If a database is to always be writable, without having to specify C<[tag flag write] ... [/tag]>, then define:
!block example
Database products WRITE_ALWAYS 1
!endblock
The default behavior of SQL databases is equivalent to WRITE_ALWAYS, while the default for GDBM_File, DB_File, and Memory databases is equivalent to:
!block example
Database products WRITE_CONTROL 1
Database products WRITE_TAGGED 1
!endblock
H2: Global Databases
If a database is to be available to all catalogs on the Interchange server, it may be defined in C<interchange.cfg>. Any catalog running under that server will be able to use it. It is writable by any catalog unless WRITE_CONTROL is used.
H1: SQL Support
Interchange can use any of a number of SQL databases through the powerful Perl DBI/DBD access methods. This allows transparent access to any database engine that is supported by a DBD module. The current list includes mSQL, MySQL, Solid, PostgreSQL, Oracle, Sybase, Informix, Ingres, Dbase, DB2, Fulcrum, and others. Any ODBC (with appropriate driver) should also be supported.
No SQL database is included with Interchange, but there are a number widely available on the Internet. Most commonly used with Interchange are PostgreSQL, MySQL, and Oracle. It is beyond the scope of this document to describe SQL or DBI/DBD. Sufficient familiarity is assumed.
In most cases, Interchange cannot perform administrative functions, like creating a database or setting access permissions. This must be done with the tools provided with a SQL distribution. But, if given a blank database and the permission to read and write it, Interchange can import ASCII files and bootstrap from there.
H2: SQL Support via DBI
The configuration of the DBI database is accomplished by setting attributes in additional Database directives after the initial defining line as described above. For example, the following defines the database B<arbitrary> as a DBI database, sets the data source (DSN) to an appropriate value for an mSQL database named C<minivend> on port 1114 of the local machine:
!block example
Database arbitrary arbitrary.asc SQL
Database arbitrary DSN dbi:mSQL:minivend:localhost:1114
!endblock
As a shorthand method, include the DSN as the type:
!block example
Database arbitrary arbitrary.asc dbi:mSQL:minivend:localhost:1114
!endblock
Supported configuration attributes include (but are not limited to):
LI1: DSN
.A specification of the DBI driver and its data source. To use the DBD::mSQL driver for DBI, use:
!block example; listitem=2
dbi:mSQL:minivend:othermachine.my.com:1112
!endblock
.where mSQL selects the driver (case IS important), C<minivend> selects the database, C<othermachine.my.com> selects the host, and 1112 is the port. On many systems, C<dbi:mSQL:minivend> will work fine. Of course, the C<minivend> database must already exist.
.This is the same as the DBI_DSN environment variable, if the DSN parameter is not set. Then, the value of DBI_DSN will be used to try and find the proper database to connect to.
LI1: USER
.The user name used to log into the database. It is the same as the environment variable B<DBI_USER>. If a user name is not needed, just don't set the USER directive.
LI1: PASS
.The password used to log into the database. It is the same as the environment variable B<DBI_PASS>. If a password is not needed, just don't set the PASS directive.
LI1: COLUMN_DEF
.A comma-separated set of lines in the form NAME=TYPE(N), where NAME is the name of the field/column, TYPE is the SQL data type reference, and N is the length (if needed). Most Interchange fields should be the fixed-length character type, something like char(128). In fact, this is the default if a type is not chosen for a column. There can be as many lines as needed. This is not a DBI parameter, it is specific to Interchange.
LI1: NAME
.A space-separated field of column names for a table. Normally not used. Interchange should resolve the column names properly upon query. Set this if a catalog errors out with "dbi: can't find field names" or the like. The first field should always be B<code>. This is not a DBI parameter, it is specific to Interchange. All columns must be listed, in order of their position in the table.
LI1: NUMERIC
.Tells Interchange not to quote values for this field. It allows numeric data types for SQL databases. It is placed as a comma-separated field of column names for a table, in no particular order. This should be defined if a numeric value is used because many DBD drivers do not yet support type queries.
LI1: UPPERCASE
.Tells Interchange to force field names to UPPER case for row accesses using the C<[item-data ...]>, C<[loop-data ...]>, C<[item-field ...>, etc. Typically used for Oracle and some other SQL implementations.
LI1: DELIMITER
.A Interchange delimiter type, either TAB,CSV,PIPE,%%,LINE or the corresponding numeric type. The default for SQL databases is TAB. Use DELIMITER if another type will be used to import. This is not a DBI parameter. It is specific to Interchange.
LI1: KEY
.The keying default of C<code> in the first column of the database can be changed with the KEY directive. Don't use this unless prepared to alter all searches, imports, and exports accordingly. It is best to just accept the default and make the first column the key for any Interchange database.
LI1: ChopBlanks, LongReadLen, LongTruncOK, RaiseError, etc.
.Sets the corresponding DBI attribute. Of particular interest is C<ChopBlanks>, which should be set on drivers which by default return space-padded fixed-length character fields (Solid is an example).
.The supported list as of this release of Interchange is:
!block example; listitem=2
ChopBlanks
CompatMode
LongReadLen
LongTruncOk
PrintError
RaiseError
Warn
!endblock
.Issue the shell command C<perldoc DBI> for more information.
Here is an example of a completely set up DBI database on MySQL, using a comma-separated value input, setting the DBI attribute C<LongReadLen> to retrieve an entire field, and changing some field definitions from the default char(128):
!block example
Database products products.csv dbi:mysql:minivend
Database products USER minivend
Database products PASS nevairbe
Database products DELIMITER CSV
# Set a DBI attribute
Database products LongReadLen 128
# change some fields from the default field type of char(128)
# Only applies if Interchange is importing from ASCII file
# If you set a field to a numeric type, you must set the
# NUMERIC attribute
Database products COLUMN_DEF "code=char(20) NOT NULL primary key"
Database products COLUMN_DEF price=float, discount=float
Database products COLUMN_DEF author=char(40), title=char(64)
Database products COLUMN_DEF nontaxable=char(3)
Database products NUMERIC price
Database products NUMERIC discount
!endblock
MySQL, DBI, and DBD::mysql must be completely installed and tested, and have created the database C<minivend>, for this to work. Permissions are difficult on MySQL. if having trouble, try starting the MySQL daemon with C<safe_mysqld --skip-grant-tables &> for testing purposes.
To change to ODBC, the only changes required might be:
!block example
Database products DSN dbi:ODBC:TCP/IP localhost 1313
Database products ChopBlanks 1
!endblock
The DSN setting is specific to a ODBC setup. The C<ChopBlanks> setting takes care of the space-padding in Solid and some other databases. It is not specific to ODBC. Once again, DBI, DBD::ODBC, and the appropriate ODBC driver must be installed and tested.
H2: SQL Access Methods
An Interchange SQL database can be accessed with the same tags as any of
the other databases can. Arbitrary SQL queries can be passed with the C<[query sql="SQL STATEMENT"]> ITL tag.
!block example
[query
ml=10
more=1
type=list
sp="@@MV_PAGE@@"
sql=|
SELECT sku, description
FROM products
WHERE somecol
BETWEEN '[filter sql][cgi from][/filter]'
AND '[filter sql][cgi to][/filter]'
AND someothercol = '[filter sql][cgi whatever][/filter]'
ORDER BY sku
|]
[list]
sku=[sql-code] - desc=[sql-param description]<br>
[/list]
[on-match]
Something was found<br>
[/on-match]
[no-match]
Nothing was found<br>
[/no-match]
[more-list]
<br>[matches]<br>
[/more-list]
[/query]
!endblock
Not the filter for E<lbracket>cgi foo] values, which prevent single
quotes (C<'>) from destroying the query.
H2: Importing from an ASCII File
When importing a file for SQL, Interchange by default uses the first column of the ASCII file as the primary key, with a C<char(16)> type, and assigns all other columns a C<char (128)> definition. These definitions can be changed by placing the proper definitions in COLUMN_DEF Database directive attribute:
!block example
Database products COLUMN_DEF price=char(20), nontaxable=char(3)
!endblock
This can be set as many times as desired, if it will not fit on the line.
!block example
Database products COLUMN_DEF price=char(20), nontaxable=char(3)
Database products COLUMN_DEF description=char(254)
!endblock
To create an index automatically, append the information when the value is in quotes:
!block example
Database products COLUMN_DEF "code=char(14) primary key"
!endblock
The field delimiter to use is TAB by default, but can be changed with the Database DELIMITER directive:
!block example
Database products products.csv dbi:mSQL:minivend:localhost:1114
Database products DELIMITER CSV
!endblock
To create other secondary keys to speed sorts and searches, do so in the COLUMN_DEF:
!block example
Database products COLUMN_DEF "author=char(64) secondary key"
!endblock
Or use external database tools. NOTE: Not all SQL databases use the same index commands.
To use an existing SQL database instead of importing, set the NoImport directive in catalog.cfg to include any database identifiers not to be imported:
!block example
NoImport products inventory
!endblock
Note[label='WARNING: '] If Interchange has write permission on the products database, be careful to set the NoImport directive or create the proper .sql file. If that is not done, and the database source file is changed, the SQL database could be overwritten. In any case, always back up the database before enabling it for use by Interchange.
H1: Managing DBM Databases
H2: Making the Database
The DBM databases can be built offline with the C<offline> command. The directory to be used for output is specified either on the command line with the C<-d> option, or is taken from the C<catalog.cfg> directive C<OfflineDir> -- C<offline> in the catalog directory by default. The directory must exist. The source ASCII files should be present in that directory, and the DBM files are created there. Existing files will be overwritten.
!block example
offline -c catalog [-d offline_dir]
!endblock
Do a C<perldoc VENDROOT/bin/offline> for full documentation.
H2: Updating Individual Records
If it takes a long time to build a very large DBM database, consider using the C<bin/update> script to change just one field in a record, or to add from a corrections list.
The database is specified with the C<-n> option, or is 'products' by default.
The following updates the products database C<price> field for item 19-202 with the new value 25.00:
!block example
update -c catalog -f price 25.00
!endblock
More than one field can be updated on a single command line.
!block example
update -c catalog -f price -f comment 25.00 "That pitchfork couple"
!endblock
The following takes input from C<file>, which must be formatted exactly like the original database, and adds/corrects any records contained therein.
!block example
update -c catalog -i file
!endblock
Invoke the command without any arguments for a usage message describing the options.
H1: Other Database Capabilities