V12-Dbe 3 Manual PDF
V12-Dbe 3 Manual PDF
V12-Dbe 3 Manual PDF
Regular Edition
Version 3.0
User Manual
(99/06/16)
INTRODUCTION......................................................................................................11
INSTALLING V12-DBE..................................................................................16
USING XTRAS...........................................................................................................20
WHAT IS AN XTRA?.......................................................................................20
The V12-DBE Xtra..........................................................................21
MAKING AN XTRA AVAILABLE TO DIRECTOR.............................................21
DATABASE BASICS.................................................................................................27
OVERVIEW.....................................................................................................27
What is a Database?.........................................................................27
Records, Fields and Tables...................................................27
Indexes ..................................................................................28
Compound Indexes................................................................28
Database ...............................................................................29
Full-text Indexing ............................................................................29
Flat and Relational Databases..........................................................30
Field Types ......................................................................................32
Typecasting ...........................................................................32
International Support .......................................................................33
Selection, Current Record, Search Criteria......................................33
USING V12-DBE........................................................................................................36
OVERVIEW.....................................................................................................36
Defining Identifiers..........................................................................38
PROPERTIES OF DATABASES.......................................................................112
Predefined Properties.....................................................................113
ProgressIndicator ...............................................................113
ProgressIndicator.Message ................................................113
VirtualCR ............................................................................114
CharacterSet .......................................................................114
Resources............................................................................114
CurrentDate ........................................................................115
Verbose ...............................................................................115
Months ................................................................................115
ShortMonths........................................................................115
Weekdays ............................................................................116
ShortWeekdays....................................................................116
ErrorLog .............................................................................116
MaxLoggedErrors...............................................................117
SharedRWcount ..................................................................117
DBversion ...........................................................................117
The String Property .......................................................................118
Initialization...................................................................................167
Retrieving Data..............................................................................167
Modifying Data..............................................................................167
Browsing through Data..................................................................167
Searching and Sorting....................................................................167
Importing Data...............................................................................167
Error Management .........................................................................167
Database Structures .......................................................................167
Database Utilities...........................................................................167
ERRORS .......................................................................................................185
WARNINGS...................................................................................................191
INDEX.......................................................................................................................192
V12 Database Engine enables you to provide advanced functionality to your end-users
while bringing down your development and maintenance costs.
V12-DBE is very flexible and scalable. It can be used in a wide range of applications;
from simple projects where Lingo Lists and FileIO have become difficult to manage, to
true database-driven applications.
V12-DBE for Director is available in Light and Regular editions. V12-DBE Light
Edition can be used with Director 6.x and later and supports Windows 95, 98, NT, and
PowerMac. V12-DBE Regular Edition runs with Director 5.x and later, and supports
Windows 3.x, 95, and 98, NT, Mac68K and PowerMac.
Lingo programmers can work through more complex projects by taking advantage of
V12-DBE Regular Edition’s rich and flexible Lingo interface to fully script both the
authoring and runtime tasks. If you are new to Lingo you may want to begin with V12-
DBE Light Edition to create more simple projects. Both Regular and Light Editions
are fully compatible with each other. You can start using V12-DBE Light Edition, and
later easily upgrade to V12-DBE Regular Edition.
If you are looking for a fast and easy way to integrate V12-DBE into your multimedia
projects, you may be interested in using the V12-DBE Tool and V12-DBE Behaviors
Library, both freely available at http://www.integration.qc.ca.
The V12-DBE Tool used with Authorware will help you quickly implement the most
common V12-DBE’s powerful functions such as database creation, viewing, editing,
importing, exporting, and more. The V12-DBE Tool is available FREE on our web
site at http://www.integration.qc.ca
This manual provides you with a brief overview on how to use V12-DBE, by
illustrating the main development stages involved through a practical example: the
Portfolio. You will be guided from step one, which consists in modeling your
database, up to the final results in a Director movie. The Portfolio example is also
extended in the Manual’s Appendix, where you will learn how to add a media field in
the project in order to display images in the Portfolio.
This manual is organized to help you get the information you need efficiently. The first
two sections deal with basics concerning Xtras (Using Xtras) and databases (Database
Basics). The third section leads you through explanations on how to use V12-DBE in
greater detail (Using V12-DBE). You will learn how to prepare data, create the
database and import data. The following sections will show you how to use the
methods available to you in V12-DBE.
The next sections cover the integration of V12-DBE with Macromedia Director —here
you can get a sense of how V12-DBE can be helpful to your projects. The Appendices
deal with very specific issues such as capacities and limitations, errors, end-user
delivery, portability, etc.
Please make sure you understand V12 Database Engine's license agreement before
proceeding. The full license agreement is at the end of this user manual, in Appendix
2: License Agreement. Answers to commonly asked questioned can be found in the
licensing FAQ section in Appendix 1: :Licensing FAQs.
Macintosh Version
Mac68K or PowerMac with System 7.1 or later and 1 Mb of free disk-space. On the
Macintosh, V12-DBE (and any other Xtra) will share the same memory partition as
Macromedia Director.
For simple database applications, you do not need to change the memory partition
allocated to Director or for projectors generated by Director. For more advanced
development, you may need to increase the memory partition. In either cases, try to
establish the minimum equipment requirements of your project as conservatively as
possible.
Windows Version
Any PC running Windows 3.1, 95, Windows 98 or Windows NT that is capable of
running Macromedia Director plus 1 Mb of free disk-space. The amount of memory
allocated to an application cannot be configured on Windows. This means that an
application can "borrow" as much memory as needed from the Operating System. It
also means that Windows shows unpredictable behaviors when it is short of memory.
Try to establish the minimum equipment requirements of your project as
conservatively as possible.
Macromedia Director
Macromedia Director version 5.0 or later is required.
Simple projects require no knowledge of Lingo at all. If your project uses a single
database and shows one record at a time on Director's stage, chances are that you can
implement it using the V12-DBE Behaviors Library only. No Lingo required.
For more advanced projects, V12 Database Engine's comprehensive Lingo interface
requires very little knowledge of Lingo and provides as much guidance as possible
when programming, such as checking the number of parameters, the types of the
parameters, etc.
In a nutshell, the Lingo basics you need to acquire before delving into V12-DBE are
- Local and global variables,
- Control structures (if statements, repeat loops, etc.),
- Handlers
- Object instances (this is covered in detail later in the Using Xtras section of this
manual)
FAQs
INM’s FAQs discusses many of the questions that are frequently asked by V12
developers. Please check http://www.integration.qc.ca/products/v12director/faqs/
Customer support is available from 9:00 am to 5:00 pm EST, Monday through Friday
by email to [email protected] or by phone at (514) 871-1333 (choose menu
selection6). Priority will be given to registered V12-DBE users. Customer suport
covers:
•√ Helping to understand V12-DBE, clarify specifications.
•√ Supplying sample scripts.
•√ Providing useful tips.
Where Customer Support stops, Developer Assistance begins. If you are familiar
enough with V12-DBE, but want to take your project to a more sophisticated level,
Developer Assistance is for you. Our team of programmers can help you discover
easier ways to take advantage of databases in your multimedia projects. Here are just
some of the services we offer:
•√ Project design, data structure analysis, planning
•√ Technical assistance (guidance/advice) throughout the various steps of your
project
•√ Troubleshooting and debugging your scripts
•√ Optimization (how to obtain superior performance)
•√ Assistance with other Xtras, custom development of Xtras
Typographic Conventions
Important terms, such as the names of methods, are in bold.
Sample code is indented and printed in a courier font.
Note: Special annotations and tips are enclosed in boxes like this
one.
Although the sample scripts throughout this manual contain both upper and lower case
characters, V12-DBE is not case sensitive. This applies to the methods names, the
parameters as well as to the actual data.
If you are familiar with other database management systems, you will find V12-DBE
very easy to use. If you are only vaguely familiar with database management systems,
the next few sections will give you an overview of what you need to know to help you
get started with V12-DBE.
Installing V12-DBE
The name of this Xtra is V12-DBE for Director.XTR on the Macintosh, V12-DBE for
Director.X32 on Windows 9x/NT and V12DBE-D.x16 on Window 3.x.
•√ Move the V12-DBE Xtra to the Xtras folder located in the same folder as
Director.
•√ Start Director.
To confirm that V12-DBE is properly installed, check the Xtras menu in Director. You
should see "V12-DBE for Director" in the Xtras menu.
V12-DBE comes with an on-line help to assist you in the development of your
projects. It is an unprotected Director movie that can be accessed by selecting the
Xtras>V12-DBE for Director >Help menu. To install it, Move V12Help.DIR and
V12Help.V12 to the Director folder.
•√ Multiple users can simultaneously access V12 databases over a Local-Area Network.
See Appendix 4: Multi-user Access (if you need to make a V12 database available to
multiples users through a TCP/IP network, check V12-DBE's Online Companion).
•√ Text files can be easily imported from FileMaker Pro, MS Access and MS Excel
thanks to the new mImport file method and its TextQualifier property.
mImportFile is still supported for the purpose of backward compatibility. However,
it will be progressively phased out. See Importing Data with mImport.
•√ Lingo lists and property lists can be easily imported to V12 databases with the
mImport method. One can easily convert a project that has become hard to manage
with Lingo lists to one that takes advantage of V12-DBE. Also, it makes it possible to
import XML documents to V12 databases (through Macromedia's XML parser). See
Importing Data with mImport.
•√ mFind allows the setting of the current record within the selection based on a value (as
opposed to mGo, which requires a record number). mFind in Step 5: Implementing the
User Interface.
•√ mGetUnique retrieves unique values of the field that determines selection's order. It is
convenient to populate a pop-up menu or a scrolling list with all the possible search
values on a given field. See Reading Unique Values of a Field in Step 5: Implementing
the User Interface.
•√ mBuild accepts an additional parameter, "online", and can create V12 databases that
are compatible to the V12-DBE Online Companion. See Step 3c: Building the
Database.
•√ mOrderBy can now properly sort on any field, whether indexed or not. See Sorting a
Selection (mOrderBy) in Step 5: Implementing the User Interface.
•√ Table, field and index identifiers must begin with an alphabetic character and must be
followed by up to 31 alphanumeric characters. Unlike former versions of V12-DBE
they cannot contain spaces or punctuation marks.
Version History
V12 Database Engine version 1.0 was released in 1996 as both an Xobject and Xtra for
Macromedia Director 4 and 5. It was essentially meant to serve as an advanced data
management system for Director titles with elaborate user interfaces delivered on CD-
ROM, such as games and virtual workshops.
V12 Database Engine Xtra version 2.0 was released in early 1998. It focused on
making database technology easier to learn an use by Director users. It added features
that better suit projects such as electronic catalogs, electronic books, template-based
movies, etc. Some of these features are: full-text indexing, simplified database creation
, data binding, styled text management, a behaviors library, etc.
The evaluation copy of V12-DBE is not limited in any way: it only displays a splash
screen upon startup. To get rid of the splash screen, you must purchase a V12-DBE
license (or as many as required by the V12-DBE license agreement). Such a license is
granted to you as a registration number that you enter in Director's Xtra > V12-DBE
for Director > Register… menu item.
Once your copy of V12-DBE is licensed, all new databases you create are
automatically stamped as legal and do not show a splash screen. Existing databases are
also stamped as legal as soon as they are opened by the registered V12-DBE.
The “Development” version requires an additional file – the license file - located in the
System:Preferences folder of your Macintosh, or the Windows\System folder of your
PC. This encoded file is generated by V12-DBE upon the registration of your license
number.
What is an Xtra?
Xtras are components (alternatively know as add-ons, or plug-ins) that add new
features to Macromedia Director. Many of Director's own functions are implemented
as Xtras.
•√ Lingo Xtras add new Lingo commands and functions to Director. They must be
delivered to the end-users along with your project. To list all available Lingo
Xtras, type "ShowXlib" in Director's Message Window. To find out what methods
are provided by a Lingo Xtra, type "put mMessageList(Xtra "<the Xtra's
name>")" in the message window.
•√ Tool Xtras extend Director's features at authoring time. They appear in Director's
Xtra menu.
•√ Transition Xtras add new transitions to Director's own transitions set. They only
appear in Director's Modify > Frame > Transition window.
•√ Asset Xtras enable you to create members of new types and place them on
Director's stage. They appear in Director's Insert menu.
•√ MIX Xtras are translation modules that enable you to import/export foreign media
such as WAV, MP3 files, etc.
Xtras for Windows 9x/NT must have a .X32 file extension, as in "V12-DBE for
Director.X32". Xtras for the Macintosh generally have the an .XTR extension. The file
extension *.X16 is reserved for Xtras for Windows 3.1.
The more accurate description is that it actually contains two Lingo Xtras and one Tool
Xtra:
•√ a Lingo Xtra named V12table, which represents the table within the database file
(see Database Basics for the definition of table )
•√ a Tool Xtra that enables you to access V12-DBE's on-line help and to register
your V12-DBE license.
Example:
set gDB = New(Xtra"V12dbe", the pathname&"myBase.V12", "Create",
"myPassword")
Example:
if NOT ObjectP(gDB) then alert "Could not create Xtra instance"
This example shows the structure of the database referred to by gDB in the message
window:
put mDumpStructure(gDB)
Closing an Xtra
When the Xtra instance has completed its function and is no longer required, close it
by setting the variable that refers to it to 0. Closing an Xtra performs mandatory
housekeeping tasks and closes unneeded files. It also frees the memory occupied by
the Xtra. All Xtra instances created with New must be ultimately set to 0 once they are
no longer needed.
Example:
set gDB = 0
If V12-DBE is installed, you should see V12dbe and V12table listed in ShowXlib's
output, as well as all other available Lingo Xtras. Note that this technique applies to
Lingo Xtras only.
Example
set gDB = New(Xtra"V12dbe", "myBase.V12", "Create", "myPassword")
assumes that "myBase.V12" is in the same folder as Director or the Projector. This is
strictly equivalent to:
set gDB = New(Xtra"V12dbe", the applicationPath & "myBase.V12",
"Create", "myPassword")
Most of the time, however, placing the database file in the same folder as the movie
that uses it is more convenient. Use the pathname Lingo function to get the current
movie's folder. Example:
set gDB = New(Xtra"V12dbe", the pathname & "myBase.V12", "Create",
"myPassword")
While the two aforementioned examples require exactly one and two parameters
respectively, some commands and functions offer more flexibility by accepting
optional parameters. For example, in Lingo, the Beep command requires one
parameter: the number of beeps. However, if that parameter is omitted, Lingo assumes
that one beep is required.
Xtras offer the same mechanism: some methods require an exact number of parameters
(fixed number of parameters), others assume default values if parameters are omitted
Basic Documentation
In Director, Xtras contain a built-in mechanism that provides documentation for Lingo
developers. In the Message Window, type:
put mMessageList(Xtra "V12dbe")
in the Message Window, where Xtra "V12dbe" is the name of the Xtra library, not of
an Xtra instance.
Methods that expect a fixed number of parameters are those for which each parameter
is listed. Methods that accept a variable number of parameters are those followed by a
*.
In this case, the Shockwave movies you deliver must playback on the end-user's
computer in a web browser (Microsoft Internet Explorer or a Netscape browser) using
a playback engine installed in the System folder.
Shockwave movies, like projectors, need to handle two files: the V12-DBE Xtra and
your V12 database. These files must be placed in a location on the end-user's computer
depending on which browser is used, as explained below.
The Xtra file must be placed into the Shockwave Plug-In folder located in Netscape's
Plug-Ins folder. This folder's name is:
The database file (filename.V12) must be placed in the same folder as Netscape. If the
Shocked movie is used locally (that is, not downloaded by the user from the Web), the
V12 database file can also be placed in the same folder as the Shockwave movie.
The Xtra file must be placed into the Shockwave Plug-In folder.
•√ \windows\shockwave\xtras\ on Microsoft Windows
•√ System Folder:Extensions:Macromedia:Shockwave:Xtras: on Macintosh
The V12 database file must be placed in the same folder as the shocked movie.
Overview
If your understanding of what a database is and does is unclear, we recommend that
you read this section. The following sections deal with database basics:
•√ what is a database,
•√ records, fields and tables,
•√ indexes and full-text indexes,
•√ flat and relational databases,
•√ field types,
•√ selection, current record, and search criteria.
What is a Database?
A database is a collection of information that can be structured and sorted. A
telephone book is an example of a hardcopy database, and government statistical
records are examples of electronic databases. Database management programs such as
V12-DBE provide many advantages over hardcopy databases. Unlike using a
telephone directory that sorts data in alphabetical order, database software allows you
to change the way you sort and view information. Moreover, you can find, modify and
update information quickly and easily.
For example, data entry in an address book typically consists of seven pieces of
information called fields: last name, first name, street address, city, state, zip code
and phone number. All the information relevant to one person makes up one record.
The collected records make up the table and are contained in a database file.
Entries below are typical of those found in an address book:
This is a table:
Last Name First Name Address City State Zip Phone --- These are fields
Jordan Ann 6772 Toyon Court San Mateo CA 94403 349-5353 --- This is the 1st record
Brown Charles 30 Saxony Ave. San Francisco CA 94115 421-9963 --- ...the 2nd record
Pintado Jack 22 Hoover Ave. Bowie MD 20712 731-5134 --- ...the 3rd record
Van Damme Lucie 87 Main St. Richmond VA 23233 315-3545 --- ... etc
Indexes
V12-DBE allows you to determine how you want to sort information by defining one
or more indexes in a table. When a field is indexed, V12-DBE creates an internal list
that can be used to sort and search quickly the data it contains. Non-indexed fields can
also be searched and sorted, but at a slower speed.
In this example, the address book entries are listed according to an index of the first
name field and sorted in ascending order (A to Z), thus appearing in alphabetical order
by first name.
Compound Indexes
In the following example, three records share the same last names (Cartman). Indexing
the field LastName alone would certainly force Last Names to be properly ordered.
But this would not determine the order in which the Cartmans are sorted.
If you want your records sorted by Last Name, and by First Name in case of identical
Last Names, you define a compound index on the fields LastName and FirstName.
The sorted result would then be:
If you want them sorted by Last Name, and then by State in case of identical Last
Names you define a compound index on the fields LastName and State. The sorted
result would then be:
Last Name First Name City State Zip
Brown Charles San Francisco CA 94115
Cartman Wendy San Mateo CA 94403
Cartman Eric Lebanon MO 92023
Cartman Lucy Richmond VA 23233
Pintado Jack Bowie MD 20712
Database
A table, its fields and the indexes defined are stored in a database. A database can
contain one or more such tables.
in
in Field FieldFieldField
in in
Field FieldFieldFiel d
Table
Table
Database
Full-text Indexing
Defining an index on a field allows for quick sorting and searching of the first few
characters of a field. In some applications – typically when fields contain extensive
information – you need to search for words that appear anywhere in a field efficiently.
In this example, looking for the word "Soup" in the Publication Title field requires a
full-index for optimal search performance. If no index is defined on the Publication
Title field, the same result can be achieved, but with a slower performance. If a regular
index is defined on the Publication Title field, publications that start with the word
"Soup" can be quickly located, but publications that contain that word require more
time. Full-indexes apply only to fields of type string, including those which contain
styled text (see Field Types, International Support and Managing Styled Text).
For optimal full-text search efficiency, some level of control is required on the way it is
performed. For example, indexing trivial words such as "and", "or", "the", etc. (or
equivalent words that appear frequently in your application's language) is useless as
most records would contain one or more occurrences of those words.
Last Name First Name Address City State Zip Phone Company Phone
Jordan Ann 6772 Toyon Court San Mateo CA 94403 349-5353 Rocco & Co. 526-2342
Brown Charles 30 Saxony Ave. San Francisco CA 94115 421-9963 National Laundry 982-9400
Pintado Jack 22 Hoover Ave. Bowie MD 20712 731-5134 Rocco & Co. 526-2342
Van Damme Lucie 87 Main St. Richmond VA 23233 315-3545 Presto Cleaning 751-5290
Peppermint Patty 127 Big St. Lebanon MO 92023 462-6267 Presto Cleaning 751-5290
However, adding this information might lead to the duplicate of information given that
some people might be working for the same company. To prevent duplication and to
save on disk space and time required to update, you could create a new table
containing only the business information. For example, the new table could be called:
Companies. Each record of that new table would have a unique ID number, Company
Ref, that would also be used in the first table.
The database now contains two related tables, each having a field containing the
common information, named “Company Ref”:
The relational database is smaller because it avoids useless data duplication. In order
to retrieve full information about any given individual in your address book, you would
perform a search in your first table, retrieve the company reference, and then perform a
search in the second table. The flat model may be easier to manage when retrieving
data given that only one search is required, however it tends to consume valuable disk
space.
Field Types
For optimal data sorting and searching, you can specify the kind of information to be
stored in each field. In V12-DBE, fields can be designated to contain strings, integers,
floating-point numbers, dates, pictures, sounds, palettes, etc. A field would then be of
type string, integer, float, date, or media. Fields of type Media can accommodate
any media that can be stored in a cast member except for Film Loops and QuickTime
movies. See Appendix 3: Capacities and Limits at the end of this manual for a formal
definition of each field type.
For example, if you wanted to organize a contest where each person listed in your
address book is collecting points, you would need to keep track of the number of
points accumulated by each person. Therefore, you would update your address book to
include a new field: number of points. Since you would want to search and sort this
new field quickly, you need to define an index. This new field could be one of two
types: string or integer.
If you define the new field as type string, you might end up with the following listing
when the table is sorted by ascending order of points:
Jordan Ann 1
Brown Charles 12
Peppermint Patty 127
Pintado Jack 6
Van Damme Lucie 64
This order occurs because the string "12" is alphabetically lower than the string "6"
given that the ASCII code for "1" is 49 which is smaller than the ASCII code for "6",
54. To sort the list in the expected ascending order, you must define the field number
of points to be of type integer to get the following result:
Jordan Ann 1
Pintado Jack 6
Brown Charles 12
Van Damme Lucie 64
Peppermint Patty 127
Typecasting
Typecasting (or casting, for short) is the process of converting a piece of data from one
type to another. This is a common mechanism to most programming languages,
including Lingo.
Typecasting can be performed explicitly in Lingo using the Integer, String and
Float functions (i.e., String(234) returns the string "234") or automatically (i.e.,
12&34 returns the string "1234").
V12-DBE has the same ability as Lingo to typecast data when it is required by the
context. However, some borderline conditions can lead to ambiguous results such as
trying to store the value " 123" in a field of type Integer (note the leading space).
You must always make sure that the data supplied to V12-DBE does not contain
spurious characters, otherwise typecasting will not be performed properly.
International Support
Although the 26 basic letters of the roman alphabet sort in the same order in all roman
languages, the position of accented characters (also called mutated characters) varies
from one language to another. For example, the letter ä sorts as a regular a in German
whereas it sorts after z in Swedish. Likewise, in Spanish, ch sorts after cz and ll sorts
after lz.
V12-DBE also offers the option of defining fields of type Swedish, Spanish,
Hebrew, etc. that index and sort data in a way that is compliant with these languages.
See Appendix 16: String and Custom String Types for an exhaustive list and
description of those behaviors called custom string types.
The Regular Edition of V12-DBE allows for the creation of custom string types having
each a sort/search description table defined by you. Therefore, you can define your
own string type for any language supported by single-byte characters, including
Klingon.
•√ If two or more records satisfy the search criteria, the selection is the set of
those records and the first record of the selection becomes the current record.
•√ If no record satisfies the search criteria, then the selection is empty and the
current record is undefined. Any attempt to read or write in a field will result
in an error.
The following figure illustrates the idea of searching a table for records satisfying a
certain criteria. The result is placed in a selection, the first record of which becomes
the current record.
All operations on any fields (such as reading and writing data) are done on the current
record. Therefore, before performing these operations, you must designate the record
on which you wish to work as the current record by selecting it, and by using methods
such as mGoFirst, mGoLast, mGoNext, mGoPrevious and mGo.
At any given time, with the possible exception of no record satisfying the criteria, there
is a current record. All record operations apply to the current record and do not apply
to any other record. You can read the content of a field in the current record, modify
its content or delete the entire record. The current record is changed when you move
from one record to the next in the selection.
Besides sorting a table through indexes, you can find information based on search
criteria. You can define simple search criteria, also called simple queries, such as:
•√ First name is Jack
•√ State is California
•√ Number of points is less than 30
•√ Last name begins with P
Or you can define complex search criteria, also called Boolean queries using and/or,
such as:
•√ First name is Jack or Last name begins with P
•√ State is California and Number of points is less than 30
•√ State is California and Number of points is less than 30 and Last name
contains "pe"
Overview
This section covers the main steps in using V12-DBE. If you have looked at the First
Steps manuals, you should already be familiar with these five steps.
V12-DBE Basics
V12-DBE is a powerful database management engine, composed of two Xtras
libraries: a database Xtra named "V12dbe" and a table Xtra named "V12table". The
database Xtra is used to create a new database or to open an existing database in a
given mode (read only, read/write or create). The table Xtra is used to manage the
content of the table in your database.
Step 1 Deciding on a data model: Before you create your database, decide which fields are
needed, the type of those fields, how they should be grouped in the tables and which
fields should be indexed. This is a design effort that does not require a special tool
(with the possible exception of a word processor to help you edit your ideas). If your
original data is managed in FileMaker Pro, MS Access, or a similar database
management product, that database's model is probably the best starting point for your
V12 database model.
Step 2 Preparing the data: If your original data is managed in FileMaker Pro, MS Access, or
a similar database management product, in step 2, you make sure that your data is
properly entered and that it is in a format readable by V12 Database Engine (Text file,
DBF file or one of V12-DBE's ODBC-compliant formats).
Step 3 Creating a V12-DBE database: Use the V12-DBE Tool to create the V12 database
you designed at Step 1. Alternatively, you can use the database Xtra's (i.e. Xtra
V12dbe's) methods to write an automated database creation script in Lingo.
Step 5 Implementing the user interface: This step consists of the development of data
search, retrieval and modification routines at runtime either as Behaviors attached to
the various Director sprites, or as Lingo handlers in Director script members. Sample
movies provided in the V12-DBE package or on Integration New Media's web site
(http://www.integration.qc.ca) can be used to inspire the development of your projects.
In the stationary catalog example below, only one table is needed. It is called
"Articles". The seven fields you need are :
•√ Field "ItemName" of type String
•√ Field "Category" of type String
•√ Field "Description" of type String
•√ Field "Price" of type Float
•√ Field "CatalogNumber" of type Integer
•√ Field "Photo" of type Media
•√ Field "Date" of type Date
Since only the fields "ItemName", "Price" and "CatalogNumber" will be searchable,
only them are indexed.
Defining Identifiers
Tables, field and indexes are given names called identifiers, and V12-DBE makes
reference to them by use of these identifiers. An identifier must start with a low-ASCII
alphabetic character (a..z, A..Z) and can be followed by any combination of
alphanumeric characters (0..9, a..z, A..Z, à, é, ö, …). The maximum length for an
identifier is 32 characters. No two fields or indexes of a table can have the same name.
V12-DBE is not case-sensitive. That is, upper-cases and lower-cases are identical. The
following identifiers are considered identical in V12-DBE: "articles", "ARTICLES",
"Articles", "aRtICleS".
If you plan to use an ODBC driver to import your data from MS Access, MS FoxPro,
MS Excel or MS SQL Server, or if the records must be keyed-in by the user, skip to
Step 3.
In brief, Step 2 consists in making sure that your original data is properly structured
and in exporting it as Text or DBF files. Those files are then imported to V12
databases at Step 4: Importing Data into a V12-DBE Database.
where Field_A1, Field_A2, etc. designate the actual data in those fields. TAB is
the ASCII character 9, indicating the end of a field.
On the Mac, CR is the ASCII character 13, indicating the end of a record. On
Windows, CR is the ASCII character 13 followed by the ASCII character 10 (Line
Feed). Since V12-DBE always ignores Line Feed characters, you need not worry about
exceptional cases between the Mac and Windows with respect to Record Delimiters.
Generally, using the V12-DBE Tool or the mImport method to import a text file into a
V12-DBE database is a straightforward process, unless your fields contain TAB or CR
characters. In such cases, V12-DBE confuses the real delimiter with the legitimate
content of your field. See Dealing with Delimiters Ambiguity below.
Field Descriptors
V12-DBE requires a special type of Delimited Text file format. The file's first line
must contain field descriptors, or the names of the fields into which the data that
follow must be imported. This file format is sometimes referred to as mail merge
format. Following is an example of such a file:
Name Price CatNumber
Ruler 1.99 1431
You can easily have FileMaker Pro and MS Access export those field names before
exporting the records data as follows:
•√ In FileMaker Pro, choose File > Import/Export > Export Records and select
"Merge (*.MER)" in the Save as Type menu. As a side effect, FileMaker Pro
exports your data with quotation marks surrounding each field and a comma as
field separator. Your file can easily be imported to the V12 database with
quotation marks as Text Qualifiers (Text Qualifiers below) and commas as field
delimiters (see Custom Delimiters below).
Some database management systems (e.g., FileMaker Pro) export a special character
other than ASCII #13 instead of the CRs that appear in your fields. For example,
FileMaker Pro exports ASCII #11 (Vertical Tab) instead of ASCII #13. Those
characters are called Virtual Carriage Returns or VirtualCR for short.
V12 Database Engine can recognize those characters and convert them to real Carriage
Returns (ASCII #13) once they are imported. See Step 4: Importing Data into a V12-
DBE Database / Importing Data with mImport and VirtualCR / Properties of
Databases.
Text Qualifiers
A text qualifier is special character used to begin and end each Text field. In most
database management systems, the quotation mark (") is the default text qualifier. Its
main purpose is to group a field's content between two identical marks so to enable the
occurrence of field and record delimiters without the risk of confusion.
Example:
"Name" , "Description" CR
"Hat" , "high-quality, excellent fabric, available in:CRRedCRGreenCRBlue"
"Shoe", "this, description, field, contains, commas, and, CarriageCRReturns"
Text files containing Text Qualifiers are easily imported to V12 databases by setting
the mImport method's TextQualifier property to the right character. See Step 4:
Importing Data into a V12-DBE Database / Importing Data with mImport.
Custom Delimiters
Another way to avoid delimiter ambiguity is to choose delimiters other than TAB and
CR. Some database management systems allow you to select appropriate delimiters
before exporting a TEXT file (e.g., 4th Dimension). Some others allow only the
selection of a custom field delimiter and always use CRs as records delimiters (e.g., MS
Access). FileMaker Pro and MS Excel do not allow for any customization.
V12-DBE's mImport method assumes, by default, that the field and record delimiters
are TAB and CR. However, other delimiters can be specified. See Step 4: Importing
Data into a V12-DBE Database / Importing Data with mImport.
Calculated Fields
If your database management system does not support alternative delimiters you can
nonetheless force it to export your own delimiters by creating an additional field and
setting it as the result of the concatenation of all the other fields with the desired
delimiter in between each two fields. Then, export only the new field in a text file.
Although all three operating systems use the ASCII characters set, only low-ASCII
characters (i.e., those below #127) are common to the many variants of the ASCII set.
Therefore, the rest of this topic is of interest to you only if your deal with high-ASCII
characters (such as å, æ, ß, ê, ï, ø, ž, ‰, §, ¥, etc.)
MS Word documents, V12 databases as well as many other proprietary file formats are
cross-platform compatible. You should not worry about this portability issue if your
data contains only low-ASCII characters (e.g. English alphabet).
The separator between the three chunks of values can be any non-numeric character,
although slash (/), hyphen (-) and period (.) are most commonly used.
Any date that needs to be imported in a V12-DBE fields of type date needs to be in
this raw format. This rules applies to the V12-DBE Tool as well as to V12-DBE's
Lingo methods that accept dates as input parameters (e.g., mImportFile, mSetField
and mSetCriteria).
•√ on Windows 9x/NT only, DBF files can be exported through the FoxPro ODBC
driver.
You may want to export your data as DBF files, if that format is supported by your
database management system.
DBF is an old file format. It was enhanced over the years but most common
applications still use the popular Dbase III format whose features are common to all
other DBF file variants. Limitations include:
•√ Records are of fixed length, determined upon the creation of the DBF file,
•√ There is more than one way to deal with high-ASCII characters (accented
characters) with DBF files. This depends on the operating system and
application used to manage the DBF file,
•√ Indexes are saved in separate files with extensions such as IDX, MDX, NDX
or CDX (depends on the managing application),
•√ Media (either Binary or Text) are stored in external DBT files pointed to by
Memo fields in the DBF file. Media fields are limited to 32K of size.
Various flavors of the DBF file format were introduced over the years, such as DBase
IV, DBase V, FoxPro 2.0, FoxPro 2.5, FoxPro 2.6, FoxPro 3.0 and FoxPro 5.0. They
all include DBase III's features as core specifications and add new data types or extend
certain limits. See mReadDBstructure from a DBF File for more details.
Note Years ago, DBF files were convenient given that they
contained less variants than TEXT files. However, since the
introduction of Windows and the popularization of DBF to
other Operating Systems, DBF files contain many categories
and have become difficult to manage. V12-DBE's preferred
file importing format is Text.
In summary, the exact structure and limitations of your DBF files largely depend on
how your database management system deals with them.
If you are confident that your strings will not exceed 256 bytes, or your media 64K,
you do not need to worry about the buffer size. Default buffers are set to 256 bytes for
strings and to 64K for media.
If you use the V12-DBE Tool, just read through the next two sections (Database
Descriptors and Using the V12-DBE Tool) and skip to Step 4: Importing Data into a
V12-DBE Database. If you wish to script the database creation process, read through
Scripting the Database Creation as well.
Database Descriptors
Following is the format of text (and literal) database descriptors required by both the
V12-DBE Tool and the mReadDBstructure method. It is used to build a database
structure from scratch.
If you build your V12 databases from other databases (e.g., MS Access, MS Excel,
etc.), you can directly skip to Scripting the Database Creation.
The desired V12-DBE database structure is stored in a text file (or Director member)
called the database descriptor in the following format.
[TABLE]
NameOfTable
[FIELDS]
FieldName1 FieldType1 IndexType1
FieldName2 FieldType2 IndexType2
FieldName3 FieldType3 BufferSize3 IndexType3
etc.
[END]
The [TABLE] tag is be followed by one parameter: the name of the table. This is an
identifier (see Defining Identifiers).
The [FIELDS] tag is followed by as many lines as you need to define fields in the
above defined table. The syntax of each line is as follows (see Database Basics for a
thorough explanation of these concepts):
•√ IndexType: the word "indexed" if the field must be indexed, or the word
"full-indexed" if the field must be full-indexed, or nothing if no indexing is
required. If you need to both index and full-index a field, see Defining Both
an Index and a Full-index on a Field.
Note: If you try to store a text longer than the size of the buffer
allocated for a field type string, V12-DBE signals a
warning and stores the truncated text into the field. Media
that are larger than the maximum buffer size of a fields are
not stored at all.
In each line of the descriptor file, tokens (i.e. field name, index name, value, etc.) must
be separated by one or multiple Tabs and/or space characters.
Example:
[TABLE]
Recipes
[FIELDS]
NameOfRecipe string indexed
Calories integer indexed
CookingTime integer
TextOfRecipe string 5000 full-indexed
Photo media 300000
[END]
Note: A valid database needs exactly one table, at least one field
and at least one index.
The [FULL-INDEXES] tag must follow the [FIELDS] section and must be followed
by a list of fields to be full-indexed, one per line.
Example:
[TABLE]
Recipes
[FIELDS]
NameOfRecipe string indexed
Calories integer indexed
CookingTime integer
TextOfRecipe string 5000 indexed
Photo media 300000
[FULL-INDEXES]
TextOfRecipe
[END]
This alternate syntax is used by mDumpStructure for clarity (see Viewing the
Structure of a Database ).
where:
Example:
(*
description of the Mega-Cookbook recipes table version 1.1
by Bill Gatezky, 14-Feb-97
This is a valid comment despite the fact that it contains
Carriage Returns
*)
[TABLE]
Recipes
(* this is also a valid comment *)
[FIELDS]
NameOfRecipe string indexed
...
[END]
The comment opening tag for database descriptors must be followed by a blank
character such as a space, tab or CARRIAGE_RETURN. Likewise, a comment closing tag
must be preceded by a blank character. Thus,
(*invalid comment: will generate an error*)
is valid.
2. Fill out the Database Descriptor field according to the syntax described in
Database Descriptors,
3. Provide a name, and optionally a password, for your new V12 database,
Instead of filling out the Database Descriptor field manually in the V12-DBE Tool,
you can edit it in a text file and load that text file to the Tool's Database Descriptor
field. You can also directly read the structure of a DBF file, or of another V12
database into the Tool's Database Descriptor field.
where
Syntax:
set gDB = New(Xtra "V12dbe", Name, "create", Password)
•√ Name: the name of the new database file, including its path if needed (see
Dealing with Pathnames in Using Xtras).
•√ "Create" or the Mode: the mode in which the Xtra instance is defined. In
this case, the mode is Create (create a new database file). Other possible
modes are ReadOnly, ReadWrite and Shared ReadWrite. See Opening
an Existing Database.
Example:
set gDB = New(Xtra "V12dbe", "Catalog.V12", "Create", "top secret")
Database structure translation rules from the above ODBC-compliant databases to V12
Databases vary according to the specific ODBC driver installed on your computer.
To read a database descriptor into V12-DBE, use the following Lingo statement:
mReadDBStructure(gDB, "TEXT", File_Pathname)
Assuming that the name of the database descriptor's filename is "Def.txt", the
following Lingo code creates a new V12-DBE database file named "Catalog.V12" and
structures it as described in "Def.txt".
on CreateDatabase
set gDB = New(Xtra "V12dbe", the pathname&"Catalog.V12",
"create", "top secret")
CheckV12Error()
mReadDBStructure(gDB, "TEXT", the pathname & "Def.txt")
CheckV12Error()
mBuild(gDB)
CheckV12Error()
set gDB=0
end CreateDatabase
A literal is either a Director member of type Field or a Lingo variable that actually
contains the database descriptor (as opposed to containing the pathname of the
descriptor Text file). Building a database from a literal description is very similar to
the building it from a text file. The literal must contain the database descriptor as
defined in Database Descriptors. The Lingo script to build the database is:
mReadDBStructure(gDB, "LITERAL", Variable_or_Field_Name)
A DBF file alone represents a flat file, thus a single V12-DBE table. A DBF file can be
used as a template for a V12-DBE table in much the same way as a text file or literal
can. The name of the created V12-DBE table is identical to the DBF filename without
the ".DBF" extension. The syntax is:
mReadDBStructure(gDB, "DBF", File_Pathname)
For a DBF file to be used as a complete and valid V12-DBE table descriptor, at least
one index must be defined. If that index is defined by an IDX or NDX file located in
the same folder as the DBF file, mReadDBstructure detects its presence and
automatically defines an index for that field in the current table.
DBF Translated to
field type V12 field type Notes
Buffer size = size of field in
Character String
DBF file
Integer Integer
Numeric with no
digit after fixed Integer
point
Numeric with one
or more digits Float
after fixed point
Float Float
Double Float
On Windows 3.1 and Mac68K,
Currency Float acceptable values are in the
range -2k to 2k-1, where k = 31
Memo fields are those typically used to store text longer than 255 characters.
Memo fields can also store binary data of arbitrary formats: those cannot be
imported in V12-DBE databases. When importing data from a DBF file that
contains Memo fields, the corresponding DBT files are automatically processed
by V12-DBE.
The following example uses the file VIDEO.DBF as a template to build a table named
"video" in the V12-DBE database named "VideoStore.V12". The structure of the file
VIDEO.DBF is as follows:
Field Type Width
TITLE Character 30
DESCRIPT Memo 10
RATING Character 4
TYPE Character 10
DATE_ARRIV Date 8
AVAILABLE Logical 1
TIMES_RENT Numeric 5
NUM_SOLD Numeric 5
Two index files named TITLE.IDX and TYPE.IDX are available in the same folder as
VIDEO.DBF.
mReadDBStructure reads the structure of a DBF file, not its content. To import the
content of a DBF file, see Importing from a DBF File.
Any V12-DBE database can be used as a template for the creation of a new V12-DBE
database, provided you know the password to unlock it. The syntax is as follows:
mReadDBStructure(gDB, "V12", FileName, Password)
The following example uses the database "Catalog.V12" as a template for a new
database named "Specials.V12".
on CreateDatabase
set gDB = New(Xtra "V12dbe", the pathname&"Specials.V12",
"create", "MyNewPassword")
CheckV12Error()
mReadDBStructure(gDB, "V12", the pathname&"Catalog.V12", "top
secret")
CheckV12Error()
mBuild(gDB)
CheckV12Error()
set gDB=0
end CreateDatabase
mReadDBStructure reads the structure of a V12-DBE file, not its content. To import
the content of a V12-DBE file, see Importing from V12-DBE and Adding Records to a
Database.
A FoxPro database is a directory containing a collection of DBF files along with their
index files. A directory containing one or more MS FoxPro files can be collectively
used as a database template to a V12 database. The FoxPro ODBC driver is required to
perform this operation. The names of your FoxPro files and their field names must be
valid V2-DBE identifiers (see Defining Identifiers in Step 1: Deciding on a Data
Model).
Syntax:
mReadDBStructure(gDB, "FoxPro", DirectoryPath)
The following rules apply to the translation of FoxPro databases to V12 databases:
FoxPro Translated to
Notes
field type V12 field type
Buffer size is the size of the field
Character String
in the DBF file
Integer Float
Numeric Float
Float Float
Double Float
Currency Float
Date Date
Data cannot be converted from
fields of type DateTime. Only
DateTime Date
the default date (1900/01/01) is
imported.
Logical Integer
Memo String Buffer size = 32K
Buffer size is the size of the field
General String
in the DBF file
Character-Binary String Buffer size is 32K
Memo-Binary String Buffer size is 32K
Example:
on CreateDatabase
set gDB = New(Xtra "V12dbe", the pathname&"myDB.V12", "create",
"secret")
CheckV12Error()
mReadDBStructure(gDB, "FoxPro", the pathname&"FoxDB\")
CheckV12Error()
mBuild(gDB)
CheckV12Error()
set gDB=0
end CreateDatabase
The names of the tables and fields of your MS Access file must be valid V2-DBE
identifiers (see Defining Identifiers in Step 1: Deciding on a Data Model).
Syntax:
mReadDBStructure(gDB, "Access", FileName, Username, Password)
where
•√ Username is a valid user name to access the MDB file, or EMPTY if the
MDB file is not protected,
The following rules apply to the translation of MS Access file structures to V12
databases:
MS Access Translated to
Notes
field type V12 field type
Buffer size is same as Access
Text String
field size
Number (byte) Integer
Number (integer) Integer
Number
Integer
(long integer)
Number (single) Float
Number (double) Float
Number
Ignored
(replication ID)
Currency Integer
Date / Time Ignored
Autonumber Integer
Yes/No Integer
OLE Object Ignored
HyperLink String URL imported as text
MS Access unique and duplicate indexes are properly converted to unique and
duplicate V12-DBE indexes with ascending field values.
The names of the worksheets and columns of your MS Excel file must be valid V2-
DBE identifiers (see Defining Identifiers in Step 1: Deciding on a Data Model).
The types of the field defined in the new V12 database depend on the format of the
corresponding MS Excel columns. To change the format of a entire column in MS
Excel, select it by clicking in its heading, choose Format > Cells… and select the
Number tab. It may be necessary to Save As… your workbook with a new name to
force MS Excel to commit to the new column's format (depends on version of Excel).
The following rules apply to the translation of MS Excel file structures to V12
databases:
MS Excel Translated to
Notes
field type V12 field type
General Float
Number Float
Currency Integer
Accounting Integer
Convert to text first if importing
Date Ignored
to V12-DBE is needed
Convert to text first if importing
Time Ignored
to V12-DBE is needed
Percentage Float
Fraction Float
Scientific Float
Text String Buffer size = 255 bytes
Special Float
MS Excel cannot define indexes on its fields, when reading an Excel workbook, V12-
DBE automatically indexes the leftmost field of each worksheet.
Syntax:
mReadDBStructure(gDB, "Excel", FileName)
The following rules apply to the translation of MS SQL Server data sources to V12
databases:
Syntax:
mReadDBStructure(gDB, "SQLserver", DSN, Username, Password)
•√ where DSN is the name of a valid User DSN, System DSN or File DSN (see
Window's Control Panel)
mReadDBStructure reads the structure of a MS SQL Server data source, not its
content. To import the content of the data source, see Importing from MS SQL (Win-
32 only).
Syntax:
mBuild(gDB)
mBuild optionally accepts a second parameter, "online", that makes the created file
compatible to the V12-DBE Online companion. In this case, two additional fields,
named _uID and _timeStamp are created for V12-DBE Online to manage
internally. Both fields are hidden and do not appear in mDumpStructure's result.
Syntax:
mBuild(gDB, "online")
Note: A valid database needs exactly one table, at least one field
and at least one index.
Example:
mBuild(gDB)
-- since mBuild does a lot of validations, checking for
errors/warnings is HIGHLY recommended
if V12Status() then Alert "mBuild failed with error code" &
V12Error()
Note: For mBuild to create a licensed database (that is, one that
does not display a Demo dialog when opened), a V12-DBE
license file must be present on your Mac or PC. Since the
V12-DBE license file cannot be delivered to the end-user,
mBuild cannot be used to create new databases at runtime.
If your application requires to create new databases at
runtime, usee mCloneDatabase (see Cloning a
Database).
Syntax:
mDumpStructure(gDB)
Example:
put mDumpStructure(gDB) into field "myDBstructure"
The above example places the structure of the database referred by gDB in the member
named "myDBstructure".
(*
Structure of file 'HardDisk:myDatabase.V12'
created on Thu Apr 29 15:55:07 1999,
last modified on Tue May 11 15:31:53 1999,
file format version = V12,3.0.0,Multi-User
*)
[TABLE]
Articles
[FIELDS]
name string 256
category string 256
price Float
catalognumber Integer
description string 600
[INDEXES]
nameNdx duplicate name ascending (* Default index *)
categoryNdx duplicate category ascending
priceNdx duplicate price ascending
cat#Ndx unique catalognumber ascending
catNameNdx duplicate category ascending name descending
[FULL-INDEXES]
description
[END]"
This output is fully compatible with the database descriptors discussed in Database
Descriptors and thus, can be used as is with mReadDBstructure.
You can import data into a V12 database through one of the two following methods:
1. Choose File > Open… to open the V12 database you want to import data to. A
newly created V12 database automatically opens and data can be immediately
imported to it.
2. Choose File > Import Text File… or File > Import DBF File…
3. Browse through your disk to locate the Text or DBF file to import. Click OK.
If the source data is in more than one file, you can successively import them by
repeating the above steps.
Data type translation rules from the above ODBC-compliant databases to V12
Databases vary according to the specific ODBC driver installed on your computer.
As for any V12table method, valid instances of V12dbe and V12table must exist
before the method is invoked. This is explained in details in Creating Instances.
mImport's syntax varies significantly according to the selected input source. This is
explained in details in Importing Data with mImport below.
Setting Xtra instances to 0 when they are no longer needed is mandatory, as explained
in Closing an Xtra, so to make sure that the imported data is secured on hard disk.
where:
•√ other params are parameters that depend upon the selected InputType.
For example, if InputType is "text", other params is an optional property
list that specifies the source text file's field delimiter, record delimiter, etc. If
InputType is "Access", other params are the user name, password and
table to import. The details are explained below.
Syntax:
mImport(gTable, "TEXT", FileName [, Options])
where FileName is the pathname of the text file to import, and Options is an
optional Lingo Property list containing the following properties:
For example, the following instruction imports the Text file "myTextData.txt" located
in the same folder as the current movie into gTable with all the default options (field
delimiter = TAB, records delimiter = RETURN, Character set = the current operating
system's, virtual CR = ASCII #11, Text Qualifier = QUOTE).
mImport(gTable, "TEXT", the pathname & "myTextData.txt")
This second example imports the Text file "myFile.txt" which uses "%" as field
delimiter and "\" as record delimiter.
mImport(gTable, "TEXT", the pathname & "myTextData.txt",
[#field_delimiter:"%", #record_delimiter:"\"] )
Sometimes, you need to process data with Lingo before importing it in a V12-DBE
table. A convenient place to store such data is a Director member of type Field.
mImport allows to import the content of such a field through the following syntax:
mImport(gTable, "LITERAL", DirMemberName_or_variable, [, Options])
and Options is a property list identical to the one used for importing Text files (see
Importing from a TEXT File above).
Level-1,Level-2,Level-3
12,14,16
45,58,72
33,56,68
224,301,451
Importing a DBF file is similar to importing text files, except that you cannot specify a
subset of fields to import: all the fields in the DBF file must be imported. The field
names of the DBF file must match those in the destination V12-DBE table. Non-
matching field names are ignored during the importing process and a warning is
reported by V12Error (see Errors and Defensive Programming).
Syntax:
mImport(gTable, "DBF", FileName [, Options])
Example:
mImport(gTable, "DBF", the pathname&"Pier1-Import.DBF",
[#character_set:"MS-DOS"])
If a field in the destination table has the same name as a field in the source DBF file,
but is of a different type, mImport tries to typecast the data to match the destination
field type. When importing data from a DBF file that contains Memo fields, the
corresponding DBT files are automatically processed and imported by V12-DBE. See
Dealing with Dates and mReadDBstructure from a DBF File for more details on DBF
files and data importing rules.
Data can be imported from one V12 table into another. The name of the source table
need not necessarily match the name of the destination table. However, field names
must match. Non-matching field names are ignored. If the source and destination tables
have different indexes, the destination table's indexes are used.
Syntax:
mImportFile(gTable, "V12", FileName, password, TableName)
where FileName is the pathname of the V12 database to import from, password is
the password to unlock it and TableName is the name of the table to import.
Example:
mImportFile(gTable, "V12", the pathname&"Catalog.V12", "top secret",
"articles")
If two fields have the same name but are of different types when importing data from a
V12-DBE database, mImport tries to typecast the data fields.
Lingo list, or a Lingo Property List can easily be imported to V12 tables through
mImport. This is very convenient for the conversion of projects that use Lingo lists to
manage data and that have become difficult to debug and maintain.
It is also convenient to import XML documents into V12 tables, through Macromedia's
XML Xtra.
Syntax:
mImport(gTable, "List", theList)
mImport(gTable, "PropertyList", thePropertyList)
where:
•√ theList is a Lingo list of lists. The first element is a list containing the names of
the V12 fields to which subsequent items must be imported, in the right order. If
the first item of the list contains field names that are not present in the current V12
table, the corresponding data is ignored.
[ [#CatalogNumber:8724], [#CatalogNumber:9825],
[#CatalogNumber:1745] ]
You can import an XML document to a V12 table using Macromedia's XML parser
Xtra (delivered with Director 7). This is a two-step process:
1 Convert the XML document to a Lingo property list using the XML parser.
Example (the XML string xmlString below is convert to xmlPropList)
parserObj = new (xtra "xmlparser")
node = parseString(parserObj, xmlString)
error = getError(parserObj)
if voidP(error) then
xmlPropList = makeList(parserObj)
else
alert "Sorry, there was an error"&&error
end if
MS Access (*.MDB) files can be imported to V12 databases, one table at a time. A
MS Access ODBC driver must be present but no DSN (Data Source Name) is
required.
Syntax:
mImport(gTable, "Access", FileName, UserName, Password, TableName)
where
•√ Username is a valid user name to access the MDB file, or EMPTY if the
MDB file is not protected,
Generally, MS Access databases are encoded in the Windows ANSI character set.
Thus, you must make sure that the CharacterSet Property is properly set to
"Windows-ANSI" before importing the data. ("Windows-ANSI" is the default setting
for the CharacterSet property. See CharacterSet in Properties of Databases).
Fox Pro (*.DBF) files can be imported to V12 tables provided a MS FoxPro ODBC
driver is present on your PC. No DSN (Data Source Name) is required.
Syntax:
mImport(gTable, "FoxPro", FileName)
where FileName is the path to the source *.DBF file. Always make sure to set V12-
DBE's CharacterSet property to the encoding that matches your DBF file's (see
CharacterSet in Properties of Databases).
Example:
mImport(gTable, "Excel", the pahtname&"Results.XLS", TableName)
MS Excel workbooks (*.XLS) can be imported to V12 databases, one table at a time,
through a PC's ODBC driver. No DSN (Data Source Name) is required.
Syntax:
mImport(gTable, "Excel", FileName, TableName)
where:
Example:
mImport(gTable, "Excel", the pahtname&"Results.XLS")
MS SQL Server data sources can be imported to V12 databases, one table at a time,
through a PC's ODBC driver and a valid DSN (Data Source Name). Data sources can
be created through Window's ODBC Data Sources Control Panel which is accessible
from Start > Settings > Control Panel menu.
Syntax:
mImport(gTable, "SQLserver", DSN, Username, Password, TableName)
where:
Example:
mImport(gTable, "SQLserver", "InventoryDSN", "Admin", "XBF48",
"Products")
Instead of storing media in V12-DBE files, they can be stored in a Director member. In
addition, these members' names or numbers can be stored in V12-DBE tables. This
may be convenient if your original media is already located in Director members - it
yields faster access times given that it avoids useless memory allocations/re-allocations
in transferring data between Director and V12-DBE.
However, storing media directly in V12-DBE databases has its advantages. Your data
becomes completely independent of your Director projector and it may be easier to
update.
You can import media to V12-DBE fields of type media, one at a time, using the V12-
DBE Tool (see the V12-DBE Tool's User Manual).
You can also automate and customize the media importing process through Lingo
scripting. Assume your database contains one table and five fields:
•√ Field ItemName of type String,
•√ Field Description of type String,
•√ Field Price of type Float,
•√ Field CatalogNumber of type Integer,
•√ Field Photo of type Media.
In addition, assume that the first four fields are in a TAB-delimited format named
"Data.txt", and that all photos (5th field) are in PICT format. Each photo is located in
the same folder as "Data.txt" with each image file bearing the catalog number of the
item with which it corresponds.
The following example illustrates how to import the text file in a V12-DBE database,
and then how to review each imported record in order to import the corresponding
image file.
Example:
-- some database creation preliminaries here
-- this is a purely academic example: no error trapping is performed
set gDB = New(Xtra "V12dbe", the pathname&"Catalog.V12",
"ReadWrite", "top secret")
set gTable = New(Xtra "V12table", mGetRef(gDB), "Articles")
This section discusses the elements needed to manage your V12-DBE database at
runtime.
However, the V12-DBE Behaviors Library enables you to implement a subset of V12-
DBE's functionality. If the V12-DBE Behaviors Library cannot satisfy the
requirements of your project, you probably need to use V12-DBE's Lingo interface.
Using Lingo
As for any V12-DBE method, a valid V12dbe or V12table Xtra instance (depending
on which Xtra the method belongs to) must exist before the method is invoked.
Generally, you create instances of V12dbe and V12table on StartMovie, store their
references in global variables and use those instances throughout your project.
Likewise, on StopMovie, you set those global variables to 0 thus disposing of the
Xtra instances and closing the V12 database file.
The creation of such Xtra instances is often referred to as Opening a Database and
Opening a Table. Disposing the Xtra instances is often referred to as Closing the
Database and Closing the Table instances.
Syntax:
set gDB = New(Xtra"V12dbe", database_filename, mode, password)
Opening a database means creating a V12dbe Xtra instance with the following
parameters:
•√ mode: the mode in which the Xtra instance is opened. To allow for
modifications to the database, open it in "Shared ReadWrite" or "ReadWrite"
mode. If you open your database in "Shared ReadWrite" mode, up to 128
users can access your database simultaneously (see Appendix 4: Multi-user
Access). If you open it in "ReadWrite" mode, only one user at a time can
access your database. If you do not allow modifications to your database,
open it in "ReadOnly" mode.
•√ password: the password. If you do not use the correct password, the database
cannot be opened.
Example:
set gDB = New(Xtra "V12dbe", the pathname & "Catalog.V12",
"ReadWrite", "top secret")
Always make sure that the New method succeeded by checking the validity of the
returned reference with ObjectP. Example:
set gDB = New(Xtra"V12dbe", the pathname & "Catalog.V12",
"ReadWrite", "top secret")
if NOT (ObjectP(gDB)) then alert "New V12dbe failed"
Opening a Table
Records belong to tables. Creating new records, reading the contents of records, and
searching and sorting records are operations that are performed on tables. Prior to
performing any of these operations, you must create a table Xtra instance
Syntax:
set gTable = New(Xtra "V12table", mGetRef(gDB), TableName)
To create a table Xtra instance, use the New method with the following parameters:
Example:
set gTable = New(Xtra "V12table", mGetRef(gDB), "Articles")
mGetRef is a standard Xtra method that returns the exact reference of an Xtra
instance.
Always make sure that the New method succeeded by checking the validity of the
returned reference with ObjectP. Example:
set gTable = New(Xtra "V12table", mGetRef(gDB), "Articles")
if NOT (ObjectP(gTable)) then alert "New V12table failed"
Closing a Table
Closing a Database
Always make sure to dispose of all V12table instances before you dispose of the
V12dbe instance that contains them.
At any time, the selection is sorted according to one of its fields. You can enforce that
sorting order with mOrderBy (see Sorting a Selection (mOrderBy)). Otherwise, the
Selection at startup
When a table is first opened, its selection is the entire content of that table sorted by
the field that is indexed by the default index. The first record of that selection – which
is also the first record of the table – is the current record. The default index is the first
index that was defined for the table in the database descriptor. You can use
mDumpStructure to verify which of the table's index is the default index (see
Viewing the Structure of a Database).
You never need to explicitly manage indexes in V12-DBE. The best index is always
chosen by V12-DBE to perform a search. See Appendix 12: Optimization Using
Indexes for advanced index management.
Syntax:
mSelectAll(gTable)
Example:
mOrderBy(gTable, "price", "ascending")
mSelectAll(gTable)
This example sets the selection to the whole table as referred by gTable, in ascending
order of prices (least to most expensive). The field "price" must be indexed for
mSelectAll to work efficiently. Otherwise, it would be very slow.
Browsing a Selection
Browsing a selection means changing the position of the current record. The following
methods enable you to change the current record in a selection (to set the current
record to various values related to a given selection).
mGetPosition
mGetPosition checks the position of the current record in a table and returns an
integer between one and the total number of records in the selection.
Example:
set currRec = mGetPosition(gTable) -- returns the current record's
position in the Message Window
put "the current record is:" & currRec
mGoNext sets the current record to the record following the current record.
Example:
mGoNext(gTable)
Suppose that the current record is the tenth item in the selection. After calling
mGoNext, the current record becomes the eleventh. If the selection contains only ten
records, the current record does not change and a warning is reported by V12-DBE
(see Errors and Defensive Programming).
mGoPrevious
mGoPrevious sets the current record to the record preceding the current record.
Example:
mGoPrevious(gTable)
Suppose that the current record is the tenth item in the selection. Upon calling
mGoPrevious, the current record becomes the ninth. If the current record is the first
record of the selection, upon calling mGoPrevious the current record does not change
and a warning is reported by V12-DBE (see Errors and Defensive Programming).
mGoFirst
mGoFirst sets the current record to the first record of the selection.
Example:
mGoFirst(gTable)
mGoLast sets the current record to the last record of the selection.
Example:
mGoLast(gTable)
mGo
th
mGo takes one integer parameter (call it n) and sets the current record to the n item of
the selection.
Example:
mGo(gTable, 11)
This example sets the current record to the eleventh record of the selection. If no such
record exists, mGo signals a warning.
mFind sets the current record to one, in the selection, whose Master Field equals or
starts with the keyword provided in parameter (see definition of Mater Field in
Selection and Current Record).
mFind is a great complement to mGo which can set the current record only based on its
position in the selection.
where Keyword is the value to look for in the Master Field. If the Master Field is of
type String, the matching record's content must start with Keyword. If it is of type
Integer, Float or Date, it must equal Keyword
Use the first form (with the "First" parameter), if you want the new current record to be
the first one of the selection that matches Keyword
Use the second form (with the "Next" parameter) if you want it to be the next record in
the selection according to the present current record. Use the third form ("Previous") if
you want it to be the previous record in the selection according to the present current
record.
The selection's Master Field is "LastName". Thus, a call to mFind would automatically
look for values in this field. For example:
mFind(gT, "First", "Kar") -- current rec becomes Mona Karp's
mFind(gT, "Next") -- current rec becomes Joe Karp's
mFind(gT, "Next") -- current rec becomes Richard Karp's
mFind(gT, "Next") -- current rec becomes Eric Kartman's
mFind(gT, "Next") -- current rec remains Eric Kartman's
mFind(gT, "Previous") -- current rec becomes Richard Karp's
mFind can be used to quickly locate one occurrence of a keyword in a selection where
many duplicate values exist, as opposed to mSetCriteria and mSelect which find
all occurrences but need more time.
Once the current record is properly set, mGetField retrieves the data from a specific
field. mGetField retrieves data from all field types except Media.
Syntax:
set var = mGetField(gTable, fieldName[, dataFormat])
Example:
set cost = mGetField(gTable, "price")
This example stores the content of the price field from the current record in the
variable cost. You do not need to specify the type of field you are reading. The
Lingo variable is automatically set to the appropriate type after a successful call to
mGetField (see Typecasting in Database Basics).
Example:
set cost = mGetField(gTable, "price", "9,999.99")
This example retrieves the formatted content of the price field to the cost variable.
The formatting is according to the pattern "9,999.99". That is, if the field price
contains the value 1245.5, the string "1,245.50" is returned by mGetField. Note that
the result of a formatted value is always a string.
Data formatting applies to mGetField the same way it does to mDataFormat. If two
distinct formatting patterns are applied to a field with the mGetField option and
mDataFormat, the mGetField option overrides mDataFormat. See Data Formatting
for a complete explanation on formatting patterns.
mGetSelection allows for the retrieval of one or more fields in one or more records
of the selection. The result is one of the followings:
•√ a Lingo list of lists, where each sub-list represents a record and each item of each
sub-list is the data contained in the corresponding field
•√ a Lingo list of property lists, where each sub-list represents a record and each item
is a property/value pair: the property is the name of the field and the value is the
data contained in it.
mGetSelection is powerful and flexible. It's behavior depends on the syntax used to
call it. The syntax for mGetSelection to return a result of type String is:
mGetSelection(gTable ["Literal" [, From [, #recs [, FieldDelimiter
[, RecordDelimiter [, FieldNames ]* ]]]]])
where:
•√ gTable is the instance of the table from which records must be retrieved
(mandatory parameter),
•√ From is the number of the first record to retrieve data from. It is optional. The
default value is 1.
•√ #recs is the number of records to retrieve starting from record number From.
It is optional. The default value is the number of records between From and
the end of the selection plus 1 (convenient to retrieve all the records of a
selection starting from record number From).
•√ FieldNames are the names of the fields to retrieve, in the specified order. If
the field names are omitted, mGetSelection returns the contents of all the
fields of gTable, in their order of creation. Fields of type Media are ignored
by mGetSelection.
mGetField requires that you set the current record to the record you need to retrieve
data from. mGetSelection does not.
The examples below show various ways of using mGetSelection. All examples
assume that the table gTable contains 3 fields ("name", "price" and "number",
declared in that order when creating the table), and that the selection contains 6
records.
This example retrieves the entire content of each record of the selection with TABs as
field delimiters and CARRIAGE_RETURNs (CRs) as record delimiters. Fields are sorted
in their order of creation. The records' sort order is the one defined by the selection.
set x = mGetSelection(gTable)
This example retrieves the content of 3 successive records in the selection starting
with record #2, with TABs as field delimiters and CARRIAGE_RETURNs (CRs) as record
delimiters..
set x = mGetSelection(gTable, "LITERAL", 2, 3)
This is identical to the previous example, except that the result is returned in a Lingo
list:
set x = mGetSelection(gTable, "LIST", 2, 3)
Same as the two previous examples, except that the result is returned in a Lingo
property list:
set x = mGetSelection(gTable, "PropertyList", 2, 3)
This example retrieves the entire content of the current record in a single call to V12-
DBE.
set x = mGetSelection(gTable, "LITERAL", mGetPosition(gTable), 1)
This example retrieves the content of record #4 without setting it as the current record.
set x = mGetSelection(gTable, "LITERAL", 4, 1)
This example retrieves the entire content of each record of the selection with commas
(",") as field delimiters and slashes ("/") as record delimiters.
set x = mGetSelection(gTable, "LITERAL", 1, mSelectCount(gTable),
"," , "/" )
This example retrieves the content of a single field ("name") for all the records of the
selection. Note that the TAB parameter is unused in the result, but it should nonetheless
be present.
set x = mGetSelection(gTable, "LITERAL", 1, mSelectCount(gTable),
TAB , RETURN, "name" )
This example retrieves the content of all the records of the selection with TABs as field
delimiters and CARRIAGE_RETURNs (CRs) as record delimiters, with fields ordered in
the sequence "number", "name", "price".
set x = mGetSelection(gTable, "LITERAL", 1, mSelectCount(gTable),
TAB, RETURN, "number", "name", "price")
Although, this latter request would not be of much interest because property lists
are parsed by property names, not item positions.
mGetUnique returns unique values of the Master Field in a string or a Lingo list (See
Selection and Current Record above for a definition of Master Field).
Syntax:
set a = mGetUnique(gTable, "literal")
set b = mGetUnique(gTable, "list")
Example: In a clothing catalog, you want to display only the available colors for a
specific category and size of product (e.g., T-shirt and XXL). You run the following
script:
mSetCriteria(gTable, "category", "=", "T-shirt")
mSetCriteria(gTable, "and", "size", "=", "XXL")
mOrderBy(gTable, "color")
mSelect(gTable)
put mGetUnique(gTable, "literal") into field "ScrollList"
This script retrieves unique values of the "color" field (which is the Master Field) to
the field "ScrollList". Assuming that your selection contains 30 records (10 with Color
= "Red", 10 with Color = "Green" and 10 with Color = "Blue"), the above script puts
the string
Blue
Green
Red
in field "ScrollList".
Data Formatting
mDataFormat assigns a display pattern to a field so that all data read from that field
are formatted according to that pattern. All V12-DBE methods that read data from a
formatted field are affected. These include mGetField and mGetSelection.
Syntax:
mDataFormat(gTable, FieldName, Pattern)
The following example forces all data retrieved from the field price to be formatted
with 3 integral digits and 2 decimal places.
Example:
mDataFormat(gTable, "price", "999.99")
mDataFormat can be applied to fields of type float, integer and date. Media and
string fields cannot be formatted.
To reset the formatting of a pattern to its original value, call mDataFormat with an
empty string.
Example:
mDataFormat(gTable, "price", "")
Valid patterns for fields of type integer and float contain the following:
The following example forces the output of the field ratio to 2 integral digits, 2
decimal places and a trailing "%" sign:
The pattern "###9999" forces the output of an integer field to be formatted within no
less than four digits and with three leading spaces if necessary. Thus:
4 is formatted as " 0004"
123 is formatted as " 0123"
314159 is formatted as " 314159"
3141592 is formatted as "3141592"
31415926 is formatted as "#######"
The last formatting in the above example fails because an eight-digit integer does not
fit in a seven-digit pattern.
The pattern "(999) 999-9999" is convenient for formatting phone numbers stored as
integers. For example:
mDataFormat(gTable, "phone", "(999) 999-9999")
put mGetField(gTable, "phone")
-- returns something formatted as "(514) 871-1333"
Formatting Dates
•√ D for days,
•√ M for months,
•√ Y for years,
The following example formats the date in the "Year-Month-Day" numerical format:
mDataFormat(gTable, "TheDate", "YY-MM-DD")
put mGetField(gTable, "TheDate")
Assume the content of field TheDate for the current record is Jan 5th, 95 - the
returned string is "95-01-05".
In this last example, apostrophes around 'Weekday' and 'Month' are mandatory,
otherwise the "d" in Weekday and the "m" in Month would interfere with the pattern
itself. To specify real apostrophes within date patterns, use two consecutive
apostrophes.
When a table is first opened, the default format of all its Date fields is set to
"YYYY/MM/DD".
All of these names can be replaced by custom names through the properties of the
database (see Properties of Databases).
Syntax:
mGetMedia(gTable, fieldName, DirMember)
Example:
mGetMedia(gTable, "photo", member "PhotoMember")
This example stores the content of the field "photo" from the current record into the
member named "PhotoMember" in Director's internal castlib. If more than one castlib
is used in a project, mGetMedia can also retrieve media to any castlib through the
following syntax:
In the following example, a new record is created for the item "goggles" and its price is
set to $158.99:
mAddRecord(gTable)
mSetField(gTable, "ItemName", "Goggles")
mSetField(gTable, "Price", 158.99)
mUpdateRecord(gTable)
If mUpdateRecord is not called, the record created with mAddRecord is not saved to
the database. After calling mUpdateRecord, the record is created and kept in a cache:
it is not immediately written to disk. Thus, if the computer crashes or a power failure
occurs, the database file on disk may become corrupt. To secure the newly added
records onto the hard disk, close the database and open it again (see Opening and
Closing Databases and Tables).
New records are always added to the end of the selection regardless of the criteria used
to form the selection.
In the following example, the name of the current record is changed to "funnel" and its
price to $2.95:
mEditRecord(gTable)
mSetField(gTable, "name", "funnel")
mSetField(gTable, "price", 2.95)
mSetField(gTable, "CatalogNumber", 1234)
mUpdateRecord(gTable)
If an error occurs when updating a record (e.g. Duplicate Key error in a given field),
none of the preceding calls to mSetField are taken into consideration.
When writing to a field whose type is not the same as the supplied parameter, V12-
DBE tries to cast the parameter to the appropriate type and to interpret it as accurately
as possible (see Typecasting).
Example
mSetField(gTable, "price", "3.14") -– stores the value 3.14
mSetField(gTable, "price", "xyz") -– stores the value 0.00
mSetField(gTable, "name", 1234) -– stores the string "1234"
Note: Updating the content of a field that has a full-index may take
more time than equivalent fields without full-indexes.
Writing to a field of type Date is similar to writing to field of type Integer, Float or
String, except that V12-DBE requires the date to be supplied in Raw format
(YYYY/MM/DD).
Example
mSetField(gTable, "BirthDate", "1993/02/22") –- is valid
mSetField(gTable, "BirthDate", "02/22/1993") –- is not valid
Storing the current date in Raw format may be difficult as Lingo's the Date function
returns the current date in the Control Panel settings of the computer it is running on.
In this case, use mGetProperty(gDB, "CurrentDate") to retrieve the current date
in Raw format (see CurrentDate in Properties of Databases).
The following example copies the content of member "Yeti" of castlib "photo_album"
to the field photo:
mEditRecord(gTable)
mSetMedia(gTable, "photo", member "Yeti" of Castlib "photo_album")
Deleting a Record
Call mDeleteRecord to delete the current record.
Syntax:
mDeleteRecord(gTable_instance)
Example:
mDeleteRecord(gTable)
After calling mDeleteRecord, the record which follows the record being deleted
becomes the new current record. If no record follows the deleted record, the preceding
record becomes the new current record. If no record precedes the deleted record, the
selection is then empty and the current record is not defined.
Syntax:
mSelDelete(gTable)
After mSelDelete has been completed, the selection is empty and the current record
is undefined.
Data Binding
Throughout this section, the term field is used to designate a V12-DBE field, and
member to designate a Director member.
Syntax:
mBindField(table_instance, V12FieldName, DirMember)
Example:
mBindField(gTable, "price", member "thePrice")
mBindField(gTable, "age", member "AgeOfStudent" of Castlib
"External-two")
mUnBindField performs the opposite function - it breaks the link between a member
and whatever field with which the link is bound.
Syntax:
mUnBindField(gTable, DirMember)
Example:
mUnBindField(gTable, member "thePrice")
mBindField spares you multiple calls to mGetField and mSetField every time the
current record changes. It performs a complete read/write binding between the member
and its associated field. Every time the current record changes, V12-DBE updates the
field with the Director member content, goes to the new current record and then
refreshes the Director member with the new field's content.
Data displayed in the bound members comply to the formatting pattern supplied to
mDataFormat, if such a pattern is specified.
At any given time, a maximum of one field can be bound to a Director member.
However, a single field can be bound to several members and they can all display the
bound field's content from the current record. This may lead to ambiguous results if
two or more of these members are edited and need to be saved in the associated field.
When updating such data, V12-DBE always gives precedence to the last bound
member.
If a V12-DBE field of type string is bound to a Director member of another type, the
type of the Director field is forced to the type imposed by the binding (that is,
string): its contents will be replaced.
Fields of all types can be bound to Director members, including fields of type Media.
If a V12-DBE field is bound to a member such as a check box or radio button, the
member is checked if the field contains a non-zero value.
It is not necessary to call mUnBindField before you free a table (setting its instance to
zero). Once free, all bindings pertaining to the fields of a table are automatically
revoked.
Full Binding
For projects that usually require simple browsing and viewing of information, the
binding is a “Full” binding. This means that information is displayed and updated
automatically to and from the V12 database.
mBindField(gTable, V12FieldName, DirMember, "FullBinding")
For large projects (i.e. a large number of bound members, many of which can be used
without being on the stage), or in cases where increased control over content updates
or screen refreshment is required, note the following syntax variation in which you
specify a "safe" binding.
mBindField(gTable, V12FieldName, DirMember, "SafeBinding")
which forces the retrieval of content from V12-DBE and refreshes the display for the
bound member, and for all bound members simultaneously.
which refreshes the members associated with fields f1, f2 and f3 only, as long as they
are already bound by mBindField.
mGenerateMembers
Syntax:
mGenerateMembers(table_instance, fromMember)
For example, assume gTable refers to a table named articles containing the fields:
ItemName of type String, Description of type String, Price of type Float,
Catalog number of type Integer and Photo of type Media:
mGenerateMembers(gTable, member 22)
creates five members in the internal castlib starting from member 22. If all members 22
- 26 are empty upon calling mGenerateMembers, members 22, 23, 24, 25 and 26 are
created.
If any of the members 22 - 26 are not empty upon calling mGenerateMembers, the
members are skipped. In the above example, suppose that members 24 and 26 already
existed, mGenerateMembers would have then created members 22, 23, 25, 27 and 28.
mGenerateMembers can also generate members in any castlib other than the default
Director "internal" castlib as follows:
mGenerateMembers(gTable, member "bird" of castlib "album")
The newly created members are named after the table from which they were generated,
followed by the V12-DBE field name they represent, with a comma in-between. In the
above example, the newly created members are named "Articles,ItemName",
"Articles,Description", "Articles,Price", "Articles,Catalog number" and
"Articles,Photo".
This naming scheme enables you to get each piece of information as follows: for a
given auto-generated member (say member 25), item 1 of the name of member
25 returns the name of the table from which it is generated and item 2 of the
name of member 25 returns the name of the field from which it is generated.
Syntax:
mAutoBinding(table_instance, castLib)
For example, if gTable refers to a table named articles containing the fields:
ItemName, Description, Price, Catalog number and Photo, and if the Director
movie's internal cast contains members named "Articles,ItemName",
"Articles,Description", "Articles,Price", "Articles,ItemName" and "Articles,Photo"
(possibly obtained by calling mGenerateMembers):
mAutoBinding(gTable, "internal")
Syntax:
mAutoBinding(gTable, "Cast", "SafeBinding")
Syntax:
mSetCriteria(gTable, FieldName, operator, Value)
mSelect(gTable)
•√ operator: this is a comparison keyword. Valid operators are =, <, <=, >,
>=, <>, starts, contains, wordStarts and wordEquals.
•√ value: this is the value to which the field contents must be compared to, in
order to be selected.
The following example selects all items that are cheaper that $12.
mSetCriteria(gTable, "price", "<", 12)
mSelect(gTable)
Upon completion of mSelect, the resulting selection contains the set of records that
satisfy the defined criteria. In the above example, all records that contain a price
field with a value that is strictly smaller than 12 are selected. In addition, the selection
is sorted with an increasing order of prices given that a search with a defined ascending
index was performed on that field.
The current record is the first record of that selection. In our example, it is the least
expensive item.
If you want the selection sorted in an order other than the one proposed by mSelect,
you can do so by calling mOrderBy right before calling mSelect. However, keep in
mind that this may cost some additional processing time.
Example:
mSetCriteria(gTable, "price", "<", "100")
is strictly equivalent to
mSetCriteria(gTable, "price", "<", 100.00)
Operations on fields of type Date require that Value be supplied in Raw format (see
Step 2: Preparing the Data / Dealing with Dates). The following example locates all
records where field theDate contains a date occurring before May 21st, 1997.
mSetCriteria(gTable, "theDate", "<", "1997/05/21")
Example:
mSetCriteria(gTable, "ItemName", "contains", "hat")
mOrderBy(gTable, "price", "descending")
mSelect(gTable)
The above example selects all hats in gTable and returns a selection sorted by a
descending order of prices (most expensive to least expensive).
If mOrderBy is not called before calling mSelect, the sort order of the selection
depends on the index used to perform the search. That index is automatically chosen
by V12-DBE to optimize the search time. See Appendix 12: Optimization Using
Indexes.
Operators
The following is a list of valid operators and their meanings. Although comparisons of
integers, floats and dates are straightforward, comparing strings and custom
string types depends on how those comparison rules are defined (see Appendix 16:
String and Custom String Types). Media fields cannot be compared.
Equal (=)
The "=" operator is used to locate data that exactly match the specified value.
Example:
mSetCriteria(gTable, "price", "=", 3.14)
Example:
mSetCriteria(gTable, "ItemName", "=", "hat")
specifies a search for items named "hat". Items named "hats" or "hatchet" will not be
selected. Since V12-DBE does not differentiate upper case and lower case characters,
items named "HAT" or "Hat" will be selected.
The "<>" operator has the opposite effect of the "=" operator. It is used to locate data
that are different than the specified value.
Example:
mSetCriteria(gTable, "price", "<>", 9.99)
The "<" operator is used to locate data that are strictly smaller that the specified value.
Example:
mSetCriteria(gTable, "price", "<", 10)
specifies a search for items that cost less than $10. Items that cost exactly $10 are not
selected.
Example:
mSetCriteria(gTable, "ItemName", "<", "hat")
specifies an alphabetical search for items with names that precede the letter “h” in
"hat". This includes "cap", "bonnet" but excludes "hat".
The "<=" operator is used to locate data that are smaller or equal to the specified value.
Example:
mSetCriteria(gTable, "price", "<=", 10)
Example:
mSetCriteria(gTable, "ItemName", "<=", "hat")
specifies an alphabetical search for items with names that precede equal “h” in "hat".
This includes "cap", "bonnet" and "hat".
Example:
mSetCriteria(gTable, "CatalogNumber", ">", 1000)
specifies a search for items with catalog numbers larger than 1000. Catalog number
1000 will not be selected.
Example:
mSetCriteria(gTable, "birth date", ">", "1961/12/31")
specifies a search for records with a "birth date" field occurring after Dec 31st, 1961,
(excluding that date). The earliest birth date in the selection should be Jan 1st, 1962 or
later.
The ">=" operator is used to locate data that are larger or equal to the specified value.
Example:
mSetCriteria(gTable, "CatalogNumber", ">=", 1000)
specifies a search for items with catalog numbers larger or equal to 1000. Catalog
number 1000 will be selected.
Example:
mSetCriteria(gTable, "birth date", ">=", "1961/12/31")
specifies a search for records with a "birth date" field occurring on or after Dec 31st,
1961. Therefore, the earliest birth date in the selection may be Dec 31st, 1961.
Starts
The "starts" operator can be used with fields of type string only (including custom
string types). It locates records that start with a given sub-string in the specified field.
Example:
mSetCriteria(gTable, "description", "starts", "hat")
sets items for selection with descriptions such as "Hat with two propellers" and
"Hatchet for heavy-duty applications".
If an index is defined on the field description, the search process is very fast. If not,
the search takes more time but can be performed nonetheless.
Contains
The "contains" operator can be used with fields of type string only (including
custom string types). It locates records that contain a given sub-string in the specified
field.
Example:
mSetCriteria(gTable, "description", "contains", "hammer")
sets records for selection containing descriptions such as "the greatest hammer in the
world" and "casing for hammers of all sizes".
Searches using the "contains" operator are inherently sequential. They cannot take
advantage of any index definition and can be very slow.
WordStarts
The "wordStarts" operator can be used only with fields of type string (including
custom string types) with defined full-indexes. It locates records that contain words
that fully or partially match the value specified to mSetCriteria.
sets records for selection containing descriptions such as "Gigantic hamburger with
fries" and "The greatest hammer in the world". It does not find records containing
descriptions such as "Champion" or "Gotham City" because the words in these records
don't start with the sub-string "ham".
WordEquals
The "wordEquals" operator can be used only with fields of type string with defined
full-indexes. It locates records that contain words that fully match the value specified
to mSetCriteria.
Example:
mSetCriteria(gTable, "description", "wordEquals", "form")
sets records for selection containing descriptions such as "claim form". Records
containing words such as "forms" or "formalism" would not be selected.
Note Words shorter than the minimum word length set for full-
indexing cannot be looked for with the "WordEquals"
operator. In such cases, you must use the "WordStarts"
operator instead.
Why should you bother using the slow "Contains" operator if "wordStarts" does the
job faster?
Another reason is that "wordStarts" can only search for words that match or begin with
a given string. For example, if the description field of a certain record contains the text
"Dark chocolate with hazelnuts":
mSetCriteria(gTable, "description", "contains", "cola")
would locate that record ("chocolate" contains the sub-string "cola"), whereas
mSetCriteria(gTable, "description", "wordStarts", "cola")
Example:
mSetCriteria(gTable, "name", "contains", "hat")
mSetCriteria(gTable, "and", "price", "<=", 50)
mSelect(gTable)
The above example selects all hats up to $50.00 in the table referred to by gTable.
The first call to mSetCriteria should use three parameters, and it can be chained
with as many four-parameter calls as needed to specify your query. Using
mSetCriteria with three parameters will reset and ignore the preceding search
criteria.
It selects all records whose "name" fields contain either "hat" or "helmet" or "cap".
Complex criteria are very powerful but can be tricky to use. The following example
illustrates complex criteria.
mSetCriteria(gTable, "name", "=", "hat")
mSetCriteria(gTable, "or", "name", "=", "helmet")
mSetCriteria(gTable, "and", "price", "<=", 50)
mSelect(gTable)
This section of script selects all hats priced under $50.00 and all helmets under $50.00.
This is very different from:
mSetCriteria(gTable, "name", "=", "hat")
mSetCriteria(gTable, "and", "price", "<=", 50)
mSetCriteria(gTable, "or", "name", "=", "helmet")
mSelect(gTable)
where the selection consists of all hats under $50.00 and all helmets listed at any price.
To illustrate the semantic difference between the two requests, we could express the
first as:
(name = "hat" or name = "helmet") and price <= 50
Note The current version of V12-DBE does not have the ability to
perform searches such as
name = "hat" or (name="helmet" and price<=50)
(note the parentheses).
The first two criteria are always grouped first and the third
criteria is added to the result. See Appendix 9: Advanced
Boolean Searches for possible workarounds.
Partial Selections
The selection process can be time-consuming if a large number of records match the
criteria you specify. The worst case scenario is when all the records of a table match
the specified criteria. This can handicap your project if you have no control over that
the queries the end-user can express.
To speed up the selection process, you can limit the number of records V12-DBE
places in the selection with the following syntax of mSelect.
mSelect(gTable, from, #recs)
Example:
mSetCriteria(gT, "LastName", "=", "Smith")
mSelect(gT, 1, 100)
To retrieve the next 100 records that contain "Smith" in the "LastName" field, call:
mSelect(gT, 101, 100)
Note Partial selections also work with complex searches, but not
all of them. They are only accepted for complex searches
that do not use full-text indexes (i.e., WordStarts or
WordEquals).
Example:
mSetCriteria(gTable, "name", "=", "hat")
mSelect(gTable)
set selSize = mSelectCount(gTable)
In this example, the number of records in the selection (the number of items named
"hat") is stored in selSize.
Director 7 introduced a new member of type Text (or #text) that can by styled and
edited both at authoring time and runtime.
V12 Database Engine manages both Director 5/6 and Director 7 Text members
through fields of type String, Integer, Float and Date. Both types of Text members are
split in two parts: the text of the member is stored in the V12 field itself. The media
component — whether bitmap or binary representation of styled text — is stored in a
hidden field of type Media. The text component is used to searching and sorting,
whereas the media component is used for storage and retrieval.
Any V12-DBE field of type integer, float, date or string can be used to store a
text member through the following syntax:
mSetField(gTable, fieldName, member)
For example, assume that gTable contains a field of type string named "Banner"
and that member 28 is a Text member containing the anti-aliased text "The Tiger in
your Engine",
mSetField(gTable, "banner", member 28)
stores the styled Text member 28 in the field "Banner". Technically, the string "The
Tiger in your Engine" is stored in the field "Banner" and the media component of the
Text member is stored in an hidden Media field.
This instruction retrieves the banner image from the V12-DBE database and places it
in the member named "myBanner". Note that the V12-DBE field "Banner" mentioned
above is of type string and not media.
Alternatively, you can retrieve the content (the individual characters) of the data
contained in the field "Banner" as follows:
set aText = mGetfield(gTable, "Banner")
-- assigns "The Tiger in your Engine" to aText
the second call to mSetField would replace the content of the field "Banner" with the
unformatted text contained in member 28. This would replace any image associated
As a result of this technique, it is possible to search and sort fields that contain styled
text based on the content component of the fields. Since the fields used to store styled
text are of type string, integer, float or date, operations such as indexing,
sorting, searching, etc. all remain valid.
V12-DBE's Lingo interface provides methods that allow you to keep a close check on
your programming. Use the global functions V12Status() and V12Error(), to
confirm each step of database creation and handling.
As well, Director has two interesting tools to help you detect your Lingo scripting
errors: the Watcher and the Debugger, both available in the Windows menu. V12-
DBE's error detecting functions, the Watcher and the Debugger can be used together to
efficiently debug your scripts.
Example:
set aPrice = mGetField(gTable, "price")
set errCode = V12Status()
if errCode <> 0 then
Alert("Mayday! Mayday! mGetField returned error code" && errCode)
end if
If V12Status() returns a non-zero result, you can call V12Error() to get the details
of the error. When called with no parameters, as in V12Error() this global function
returns a plain-English explanation of the outcome of the last called method. If an error
occurred in that last call to V12-DBE, V12Error() provides a detailed contextual
report on it.
Example:
set aPrice = mGetField(gTable, "price")
set errCode = V12Status()
if errCode <> 0 then
Alert ( V12Error() )
end if
Example:
put V12Error(-600)
returns:
As shown in this last example, V12Error() sometimes returns strings which contain
placeholders for context specific information, such as %s or %ld. This is because the
returned message is a generic explanation of the error code -600. When called without
parameter, V12Error() returns a contextual explanation with the actual non-existing
table name instead of %s.
CheckV12Error
The CheckV12Error() Lingo handler is often used throughout this manual and in
sample projects. It is a generic error handling routine that centralizes all the error
management logic is a single handler. That way, it can more easily be adapted from
one project to the other, or from a debugging mode to a delivery mode (e.g. the
debugging mode would display alerts, whereas the delivery mode would write an error
log to an external file with the FileIO Xtra).
on CheckV12Error
if V12Status() then
alert V12Error()
return TRUE
end if
return FALSE
end CheckV12Error
•√ Errors which lead to major problems that require that you stop the execution
of your script.
An example of an error is File not found, when trying to import data. When a file is not
found, it does not make sense to continue the importing operation until the problem is
solved.
V12Status() returns negative codes for errors and positive codes for warnings.
Often, the term error is used to designate faults of both types (i.e. errors and
warnings).
Example
on doSomethingCritical
set gDB = New(Xtra "V12dbe", the pathname&"catalog.V12",
"ReadWrite", "top top top")
set gTable = New(Xtra "V12table", mGetRef(gDB), "Articles")
-- other Lingo statements
-- with a syntax error somewhere which
-- causes the handler to abort
set gTable = 0
set gDB = 0
end doSomethingCritical
In this example, a Lingo error is detected and the database remains open. If the
database was opened in ReadWrite mode and changes were made, the database file
might become corrupted.
You can prevent this problem by declaring the instance variables as global variables.
Example:
on doSomethingCritical
global gDB, gTable
set gDB = New(Xtra "V12dbe", the pathname&"catalog.V12",
"ReadWrite", "top top top")
set gTable = New(Xtra "V12table", mGetRef(gDB), "Articles")
-- other Lingo statements
-- with a syntax error somewhere which causes the handler to
abort
set gTable = 0
set gDB = 0
end doSomethingCritical
When a Lingo syntax error is detected and the handler aborts, you can still type
set gTable = 0
set gDB = 0
Exporting Data
mExportSelection allows exporting of data from a V12-DBE table to TEXT or
DBF files (DBase III). Only the selected records are exported (i.e. those in the
selection). To export a complete table, make sure it is entirely selected first (see
Selection and Selecting All the Records of a Table).
The above instruction exports all the fields of the selection to the file named
FileName. The field and record delimiters are TAB and CARRIAGE_RETURN
respectively.
Example:
mExportSelection(gTable, "TEXT", "Output.txt", "~", "%")
This example exports the selection in a text file named "Output.txt" with the field
delimiter "~" and the record delimiter "%".
mExportSelection can also export only selected fields in the following way:
mExportSelection(table_instance, "TEXT", FileName, FldDelimiter,
RecDelimiter, Field1, Field2, ...)
Example:
mExportSelection(gTable, "TEXT", "Data.TXT", TAB, RETURN,
"ItemName", "catalog number", "price")
This example exports the selection in a text file named "Data.TXT" with TAB and
RETURN delimiters. The only exported fields are ItemName, catalog number and
price, in that order.
The first line in the exported file contains the names of the exported fields separated by
the selected field delimiter. The resulting text file is in the character set of the current
Operating System (this is relevant only if accented characters are present in the
exported data).
Example:
mExportSelection(gTable, "DBF", "Goliath.DBF")
-- exports all fields of gTable
Or:
mExportSelection(gTable, "DBF", "Goliath.DBF", "ItemName", "catalog
number", "price")
-- exports only fields ItemName, catalog number and price.
•√ String fields are exported to fields of type Character, if the buffer size of the
string field is declared to be no larger than 255 characters. Otherwise, they are
exported to field of type Memo.
•√ Float fields are exported to fields of type Numeric with 10 digits after the
fixed point.
Note Although V12-DBE can read all kinds of DBF file variants,
it exports data only in the popular DBase III format. This is
mainly because DBase III is universally read by all DBF-
compliant systems whereas other more recent formats are
not.
Cloning a Database
Cloning a database makes a copy of an existing database file, with all the table, field
and index definitions but with none of the data. This is similar to creating a database
file from a template rather than starting a new project. Contrary to creating a database
with mReadDBstructure (which requires a V12-DBE license to create legal V12-
DBE databases) this method can be used at runtime.
Syntax:
Example
mCloneDatabase(gDB, the pathname & "myClonedFile.V12")
In this example, a new database file named "Cloned.V12" is created using the same
tables, fields and index definitions, as well as the same password as the database file
designated by the global variable gDB. This implies that the original database file,
designated by the variable gDB, must have been opened with the appropriate password
prior to proceeding with the cloning.
An alternate syntax for cloning databases is also supported for the purpose of
backward compatibility. It is similar to creating a new instance of an existing database,
and it uses the New method.
Syntax:
cloned_db_instance = New(Xtra "V12dbe", new_pathname, "clone",
mGetRef(main_db_instance))
Example:
set gClone= New(Xtra "V12dbe", "myClone.V12", "clone", mGetRef(gDB))
In this example, the new Xtra instance gClone refers to the file "myClone.V12".
Syntax:
mPackDatabase(database_instance, NewFilePathName)
Example:
mPackDatabase(gDB, the pathname & "Packed_DB.V12")
mPackDatabase(gDB, "LAN/Shared/Projects/Barney/KidsStuff.V12")
The first example compresses gDB into a new file named Packed_DB.V12 located in
the same folder as the current Director movie. The second example compresses gDB
into a new file named KidsStuff.V12 located on a different volume (removable
media, LAN, etc.)
At the end of the operation, database_instance stays valid (referring to the non-
packed database) and NewFilePathName is a new file that can be opened with V12-
DBE.
Some of these corrupt databases can be fixed with mFixDatabase. The syntax for
mFixDatabase is:
mFixDatabase(Xtra "V12dbe", pathname, new_pathname)
pathname is the name of the database to fix and new_pathname is the name of the
fixed database, which may reside on a different volume.
mFixDatabase is a static method (its first parameter is the Xtra library itself, not on
an instance of V12dbe). In the following example:
mFixDatabase(Xtra "V12dbe", "Crash.V12", "Recovered.V12")
mFixDatabase tries to read data from "Crash.V12" and saves the data to
"Recovered.V12".
Progress Indicators
V12 Database Engine can display a progress indicator to the user when performing
time-consuming tasks such as mImportFile, mExportFile, mGetSelection,
mSelect, mSelDelete, mFixDatabase and mPackDatabase. Such a progress
indicator can optionally feature a Cancel button to enable users to interrupt the current
With_Cancel
V12-DBE displays its own progress bar when performing one of the above mentioned
tasks. The user can click on the Cancel button to abort it. You can set the
ProgressIndicator.Message property to whatever message you wish to display in
the upper part of the progress window. If you set the ProgressIndicator.Message
property to an empty string, V12-DBE displays its own context-dependant message.
Without_Cancel
Without_Cancel: V12-DBE displays its own progress bar when performing one of
the above mentioned tasks. No "Cancel" button is shown and the current task cannot be
interrupted. You can set the ProgressIndicator.Message property to whatever
message you wish to display in the upper part of the progress window. If you set the
ProgressIndicator.Message property to an empty string, V12-DBE displays its
own context-dependant message.
UserDefined
V12-DBE does not display a progress bar of its own. Instead, it calls three Lingo
handlers that must be defined in your movie: V12BeginProgress, V12Progress and
V12EndProgress. See
None
•√ The V12BeginProgress handler is called when the task starts, to allow you to
initialize or open whatever progress indicator you want to show. One parameter is
supplied to V12BeginProgress: it is either 100 (which is the upper bound that is
eventually reached by the first parameter at the end of the operation), or -1 if no
such upper bound is known up front.
•√ The V12EndProgress handler is called at the end of the task, to allow you to
cleanup or close your progress indicator.
on V12BeginProgress
-- this is an empty handler. Spinning a cursor does not
-- require intialization.
end V12BeginProgress
on V12EndProgress
cursor -1 -- restore pointer cursor
end V12EndProgress
Both at authoring time and runtime, you can call mXtraVersion to retrieve the
version of the Xtra. Example:
set v = mXtraVersion(xtra "v12dbe")
put v -- puts "V12,3.0.0,Multi-User" in message window
if (char 1 of item 2 of v) <> 3 then Alert "not version 3"
Changing a Password
You can change the password assigned to a database by using the mSetPassword
method. The new password can be an empty string. The syntax is as follows:
mSetPassword(gDB, oldPassword, newPassword)
Example:
mSetPassword(gDB, "houdini", "ali baba")
Properties of Databases
V12-DBE databases contain generic properties that provide for technical information
on the current V12-DBE environment (such as the number of available indexes and the
state of the active debugger) and allow for the control of the V12-DBE environment
(such as custom string types and custom weekday names).
mSetProperty and mGetProperty are used to assign and read these generic
database properties. Certain properties can only be read, not written (i.e. the number of
available indexes) while others can be read and written (i.e. custom string types)
Certain properties are persistent (i.e. saved to the database and recovered when the
database is reopened), others are not.
PropertyName is a valid identifier (see Appendix 3: Capacities and Limits for the
definition of a valid identifier).
Value is always a string, even if PropertyName refers to a number. For example, the
MaxLoggedErrors property accepts a number (e.g. 35) but the parameter supplied to
mSetProperty must be a string (e.g. "35").
Valid PropertyNames and Values are listed below. Both parameters must be of type
String. Both are case insensitive (hence "resources", "Resources" and "RESOURCES"
are all three equivalent).
You can retrieve the list of all the properties of a database by calling
mGetPropertyNames, as in
set props = mGetPropertyNames(gDB)
Predefined Properties
ProgressIndicator
ProgressIndicator.Message
Read-Write, persistent.
set msg = mGetProperty(gDB, "ProgressIndicator.Message")
This property sets the text that must be displayed in the upper part of V12-DBE's
progress window. If you set it to an empty string, V12-DBE displays a message that
depends on the current operation. See Progress Indicators.
VirtualCR
When importing or exporting data, convert Carriage Returns (ASCII #13) to this
ASCII character. This is convenient to avoid the confusion of real Carriage Returns
with Record Delimiters. This property can be overridden by a specific VirtualCR
character passed as parameter to mImport.
set c = mGetProperty(gDB, "VirtualCR")
put CharToNum(c) – show ASCII number in message window
--
mSetProperty(gDB, "VirtualCR", NumToChar(10)) -- define ASCII
character #10 as virtual CR
CharacterSet
Translates imported and exported files (whether Text or DBF) with the "Windows-
ANSI", "Mac-Standard" or "MS-DOS" character set tables.
mSetProperty(gDB, "CharacterSet", "Mac-Standard")
Resources
Read-only, non-persistent.
put mGetProperty(gDB, "resources")
Returns information on the number of available indexes and the index used by the last
call to mSelect.
Example:
-- Number of indexes used: 6
-- Current index in table 'articles': 'nameNdx', using field 'name'
V12-DBE resources should not be confused with the MacOS resources (those normally
edited with ResEdit) - they are completely unrelated.
Read-only, non-persistent.
Example
set aDate = mGetProperty (gDB, "CurrentDate")
put aDate
-- "1999/12/31"
Verbose
When Verbose is set to "on", V12-DBE constantly displays a detailed feedback on the
tasks it is performing in Director's Message Window,
Example:
mSetProperty(gDB, "verbose", "on")
mGetProperty(gDB, "verbose")
Avoid setting both the Verbose and the ErrorLog properties to "on" at the same time,
otherwise Director's Message Window will be quickly loaded with lengthy error logs at
every call to V12-DBE.
Months
The Month property contains the names of the months used by mDataFormat to
format dates (the MMMM pattern in mDataFormat). The Value parameter is any 12-
word string. Words must be separated by spaces. Names of months that contain spaces
themselves must be enclosed between apostrophes.
Example:
mSetProperty (gDB, "Months", "Gennaio Febbraio Marzo Aprile Maggio
Giugno Luglio Agosto Settembre Ottobre Novembre Dicembre")
ShortMonths
The ShortMonth property contains the short names of the months used by
mDataFormat to format dates (the MMM pattern in mDataFormat). The Value
parameter is any 12-word string. Words must be separated by spaces. Short names of
months that contain spaces themselves must be enclosed between apostrophes.
Example:
Weekdays
The Weekdays property contains the names of the weekdays used by mDataFormat to
format dates (the DDDD pattern in mDataFormat). The Value parameter is any 12-
word string. Words must be separated by spaces. Names of weekdays that contain
spaces themselves must be enclosed between apostrophes.
Example
mSetProperty (gDB, "Weekdays", "Montag Dienstag Mittwoch Donnerstag
Freitag Samstag Sonntag")
ShortWeekdays
The ShortWeekdays property contains the short names of the weekdays used by
mDataFormat to format dates (the DDD pattern in mDataFormat). The Value
parameter is any 12-word string. Words must be separated by spaces. Short names of
weekdays that contain spaces themselves must be enclosed between apostrophes.
Example
mSetProperty (gDB, "ShortWeekdays", "Lun Mar Mie Jue Vie Sab Dom")
ErrorLog
Read/write, persistent. Valid values: "on" and "off". Default value: "off".
When the ErrorLog property is set to "off", V12-DBE's error log and status code are
reset before each call to a V12-DBE method.
When ErrorLog is set to "on", error messages are cumulated in an error log as V12-
DBE methods are called. Likewise, the status code is set to reflect the most recent
error/warning code according to the following rule:
Syntax:
mSetProperty(database_instance, "ErrorLog", on_or_off)
Example:
mSetProperty(gDB, "ErrorLog", "on")
When ErrorLog is "on", the maximum number of messages allowed for logging can
be adjusted with the MaxLoggedErrors property.
Avoid setting both the Verbose and the ErrorLog properties to "on" at the same time,
otherwise Director's Message Window will be quickly loaded with lengthy error logs at
every call to V12-DBE.
MaxLoggedErrors
Read/write, persistent. Valid values: any integer between 1 and 1000. Default value:
32.
When the ErrorLog property is set to "on", the maximum number of messages that
can be cumulated can be set with the MaxLoggedErrors property.
Syntax:
mSetProperty(database_instance, "MaxLoggedErrors", Max)
As V12-DBE's methods are called, error messages cumulate in an error log and can be
retrieved at any time with the V12Error() function.
The V12-DBE error log and status code can be explicitly cleared by calling the global
function V12ErrorReset.
Example:
mSetProperty(gDB, "MaxLoggedErrors", "100")
The above example sets the maximum number of messages allowed for
cumulation to 100. Note that the last parameter is "100" (a
string), not 100 (an integer).
SharedRWcount
Read only, non-persistent. Returns the number of users currently using the database in
Shared ReadWrite mode.
Example:
set nbUsers = mGetProperty(gDB, "SharedRWcount")
DBversion
Read only, non-persistent. Returns the version of the V12-DBE Xtra used to create the
database.
Example:
set v = mGetProperty(gDB, "DBversion")
put v
String.Language
Read/write, persistent. Valid values: any valid search/sort table (see Appendix 16:
String and Custom String Types)
The String property defines or modifies custom string types (i.e. string fields that obey
to particular searching and sorting rules). To define a new string type, or modify an
existing one, you append its name to "String.". The chosen name must be a valid
identifier and cannot contain periods (".").
Example:
mSetProperty (gDB, "String.Klingon", field "CompTable")
In this example, field "CompTable" contains the search/sort descriptor for Klingon as
defined in Appendix 16: String and Custom String Types. Once this property is
defined, you can use the type "Klingon" to define new fields with mCreateField or
mReadDBstructure. You also need to define this property first before modifying
other string properties such as Delimiters, StopWords and MinWordLength.
To modify the sort order of the default string, just omit the Language identifier:
mSetProperty (gDB, "String", field "NewCompTable")
String.Language.Delimiters
Delimiters defines, for an existing string type, the list of characters that are acceptable
as word delimiters for full-text indexing. By default, word delimiters for the predefined
types are all non-alphanumeric characters (everything except 0-9, A-Z, a-z and
accented characters).
Example:
mSetProperty (gDB, "String.Spanish.Delimiters",
"!?@$%?&*()[]^®{}£¢§¨¶≤≥º=+-,./\|")
In the above example, the punctuation characters indicated as the Value parameter
are considered as delimiters.
If you need to specify the double-quote as part of the delimiters, either use the Lingo
constant QUOTE, or place the delimiters in a Director member of type Field and use
that field as a Value parameter as follows :
All non-printing characters such as TAB, Space, CTRL+J, etc. (i.e. characters lower
than ASCII 32) are always considered as delimiters.
To modify the delimiters of the default string, just omit the Language identifier:
mSetProperty(gDB, "String.Delimiters", field "newDelimiters")
String.Language.MinWordLength
Read/write, persistent. Valid values: an integer in the range 1..100 passed as a String
parameter.
MinWordLength determines the size of the shortest word that must be considered for
full-indexing. All words shorter than MinWordLength are ignored and hence refused
by the mSetCriteria method when used with the operator "WordEquals".
Example:
mSetProperty (gDB, "String.Spanish.MinWordLength", "3")
Note that the Value parameter is "3" (with quotation marks). This is because
mSetProperty expects a Value parameter of type String only. The following is also a
valid formulation:
mSetProperty(gDB, "String.Spanish.MinWordLength", String(3) )
To modify the MinWordLength of the default string, just omit the Language
identifier:
mSetProperty(gDB, "String.MinWordLength", "2")
String.Language.StopWords
StopWords allows for the definition of a list of words that must be ignored in the full-
indexing process. The Value parameter is a string containing the stop words in any
order separated by spaces, TAB or Carriage Returns).
Example:
mSetProperty (gDB, "String.Spanish.StopWords", "in on the a")
To modify the stop words list of the default string, just omit the Language identifier:
mSetProperty(gDB, "String.StopWords","a the on for in by as")
By default, the StopWords property is empty. A typical list of stop words in English
is:
a by in the an for is this and from it to are had not was as have
of with at he on which be her or you but his that
For example, if you need to save the frame last visited by the user prior to leaving your
application (possibly to bring him/her back to that same frame next time):
on StopMovie
global gDB
mSetProperty(gDB, "LastVisited", string(the frame))
-- Typcasting to string is mandatory here.
-- Some other housekeeping tasks...
end StopMovie
Q: Do I have to pay royalties, or a per-project fee, for using V12 Database Engine?
A: No. Integration New Media’s one-time licensing fee enables you to use V12-DBE royalty-
free Once you own a V12-DBE license, you can use it for as many projects as you wish.
A: You use V12-DBE at authoring time if the V12-DBE Xtra is present in Director’s or
Authorware’s Xtras folder when developing a project that requires it. Writing scripts that
call the V12-DBE Xtra and creating/modifying database structures (a.k.a. database
schema) are authoring time tasks. You use V12-DBE at runtime if the V12-DBE Xtra is
present in a playback executable’s Xtras folder (a Director projector or Authorware
runtime).
A: You can give away the V12-DBE Xtra, its manuals and other related files in as many
copies as you wish, except for the license file (*.LIC) and the V12-DBE registration
number. Better yet, refer your business associate to http://www.integration.qc.ca for free
downloads of V12-DBE and related files.
A: No. The V12-DBE Xtra works as a development tool and enables you to create new
database structures only if it detects a license file in your System folder. Otherwise, it
works as a playback (a.k.a runtime) tool for reading, writing and searching data. Your
license number is encrypted in the V12 database you deliver. Thus, no one can hijack it.
Q: Can I deliver a project that uses V12-DBE and that would be used by two or more
users simultaneously?
A: You can distribute any product or program containing V12-DBE Xtra to be used at
runtime.
Q: I am working as a consultant for a client who will distribute (or sell, or give away)
the project I am developing. Who needs a V12-DBE license?
Q: We are two employees of the same company working on a project involving V12-
DBE. Both of us need to create database structures and/or write scripts to call V12-
DBE methods. Do we both need V12-DBE licenses?
A: Yes. You need two separate V12-DBE licenses, unless you share the same computer. A
V12-DBE license file can be installed on only one computer at a time.
A: No. If you only need to view or modify the content (add/delete records) of a V12-DBE
database, no license is required. If your project requires you to create or modify a V12-
DBE database structure (a.k.a adding/deleting tables), or if you need to write V12-DBE-
related scripts, then you must have a V12-DBE license.
Q: I developed a software tool that uses V12-DBE and I want to make it available to
colleagues and associates for use at authoring time. Must they also have V12-DBE
licenses?
A: Yes. Users of software that use V12-DBE in an authoring environment must have V12-
DBE licenses.
A: Yes, but you must conform to specific conditions. To obtain an educational license of
V12-DBE, you agree to use V12-DBE only for educational purposes. Educational means
that V12-DBE is intended for use by students and faculty of educational institutions only
for non-commercial projects.
A: In your project, you must mention "Portions of code are Copyright (c)1995-99 Integration
New Media, Inc." next to your own copyright notice. You must also place the "Powered
by V12" logo on the packaging of your product or within your product (in the Credits
section, About box or equivalent location). The "Powered by V12" logo is available on
the V12-DBE CD-ROM and on Integration New Media's web site
(http://www.integration.qc.ca).
The enclosed computer program(s), license file and data (collectively, "Software") are
licensed, not sold, to you by Integration New Media, Inc. ("Integration") for the
purpose of using it for the development of your own products ("Products") only under
the terms of this Agreement, and Integration reserves any rights not expressly granted
to you. Integration grants you no right, title or interest in or to the Software. The
Software is owned by Integration and is protected by International copyright laws and
international treaties.
1. License.
(a) You may install one copy of the Software on a single computer. To "install" the
Software means that the Software is either loaded or installed on the permanent
memory of a computer (i.e., hard disk). This installed copy of the Software may be
accessible by multiple computers, however, the Software cannot be installed on more
than one computer at any time. You may only install the Software on another computer
if you first remove the Software from the computer on which it was previously
installed. You may not sublease, rent, loan or lease the Software.
(b) You may make one copy of the Software in Machine readable form solely for
backup purposes. As an express condition of this Agreement, you must reproduce on
each copy any copyright notice or other proprietary notice that is on the original copy
supplied by Integration.
(c) You may permanently transfer all your rights under this Agreement to another party
by providing to such party all copies of the Software licensed under this Agreement
together with a copy of this Agreement and the accompanying written materials,
provided that the other party reads and agrees to accept the terms and conditions of this
Agreement and that you keep no copy of the Software. If the Software is an update,
any transfer must include the update and all prior versions.
(d) Your license is limited to the particular version (collectively "Version") of the
Software you have purchased. Therefore, use of a Version other than the one
encompassed by this License Agreement requires a separate license.
(e) The Software contains a license file (.LIC) which is subject to the restrictions set
forth above and may not be distributed by you in any way. However, Integration grants
you a royalty-free right to reproduce and distribute the files named "V12-DBE for
Director.XTR", "V12-DBE for Director.X32" and "V12DBE-D.X16" (collectively,
"Runtime Kit") provided that (i) you distribute the Runtime Kit only in conjunction
with and as part of your own Products; (ii) own a license for the specific Version of the
Software that contains the Runtime Kit; (iii) agree to indemnify, hold harmless and
defend Integration from and against any claims or lawsuits, including attorney's fees,
that arise or result from the use or distribution of your Products with the Runtime Kit.
(g) Any third party who will use the V12-DBE Runtime Kit in an authoring
environment must purchase his own V12-DBE license.
2. Restrictions. The Software contains trade secrets in its human perceivable form and,
to protect them, you may not MODIFY, TRANSLATE, REVERSE ENGINEER,
REVERSE ASSEMBLE, DECOMPILE, DISASSEMBLE OR OTHERWISE
REDUCE THE SOFTWARE TO ANY HUMAN PERCEIVABLE FORM. YOU
MAY NOT MODIFY, ADAPT, TRANSLATE, RENT, LEASE, LOAN OR CREATE
DERIVATIVE WORKS BASED UPON THE SOFTWARE OR ANY PART
THEREOF.
3. Copyright notices. You may not alter or change Integration's copyright notices as
contained in V12-DBE. You must include (a) a copyright notice, in direct proximity to
your own copyright notice, in substantially the following form "Portions of code are
Copyright (c)1995-99 Integration New Media, Inc."; and (b) place the "Powered by
V12" logo on the packaging of your Products; or (c) place the "Powered by V12" logo
within your Products in the credits section.
4. Acceptance. V12-DBE shall be deemed accepted by you upon delivery unless you
provide Integration, within two (2) weeks therein, with a written description of any
bona fide defects in material or workmanship.
6. Limited Warranty. Integration warrants for a period of ninety (90) days from your
date of purchase (as evidenced by a copy of your receipt) that the media on which the
Software is recorded will be free from defects in materials and workmanship under
normal use and the Software will perform substantially in accordance with the manual.
Integration's entire liability and your sole and exclusive remedy for any breach of the
foregoing limited warranty will be, at Integration's option, replacement of the disk,
refund of the purchase price or repair or replacement of the Software.
8. General. This Agreement will be construed under the laws of the Province of
Quebec, except for that body of law dealing with conflicts of law. If any provision of
this Agreement shall be held by a court of competent jurisdiction to be contrary to law,
that provision will be enforced to the maximum extent permissible, and the remaining
provisions of this Agreement will remain in full force and effect.
9. The parties acknowledge having requested and being satisfied that this Agreement
and its accessories be drawn in English. Les parties reconnaissent avoir demandé que
cette entente et ses documents connexes soient rédigés en anglais et s'en déclarent
satisfaits.
The following trademarks are used throughout this manual: Director and Xtra are
trademarks of Macromedia, Inc., FileMaker Pro is a trademark of Claris corp.,
Windows, Access and MS Excel are trademarks of Microsoft corp., Macintosh is a
trademark of Apple corp., 4th Dimension is a trademark of ACI, Photoshop is a
trademark of Adobe Systems Inc.
•√ Databases that contain media fields are not compatible between version 6 and
version 7 of Director. They must be used with the version of Director they
were created with.
•√ Since each table requires at least one index, the maximum number of tables in
a V12-DBE database is also 128.
•√ A valid V12-DBE database contains at least one field and one index.
•√ All records are of variable length. Fields of type media are limited to 1Mb.
Fields of type string are limited to 64K (Note: Director Field members are
limited to 32K).
•√ Any date later than January 1st, 1600 can be compared, retrieved and stored to
fields of type Date. However, date formatting is limited to the range Jan 1st
1904 through Dec 31st 2037.
•√ No two fields or indexes can have the same name in the same table. However,
two fields or two indexes might have the same name in different tables.
•√ Fields of type media can hold any type of media that can be stored in a
Director member, except Film Loops and QuickTime movies.
•√ When indexing fields of type String, up to the 200 first characters of each
string are actually entered in the index. The remaining characters are ignored.
•√ Full-indexes are built with words not exceeding 31 characters. Words longer
than 31 characters are truncated to 31 characters for the purpose of indexing
(this does not affect the actual data).
An icon on the desktop represents a mounted volume on the Macintosh computer. You
can mount such a volume by selecting it in the Chooser, in the Apple menu.
MacOS example:
new(Xtra "V12dbe", "MyNetworkDrive:Data:Catalog.V12", "Shared
ReadWrite", "password")
At most 128 users can open a V12-DBE file in Shared ReadWrite mode.
•√ V12-DBE uses a record locking technique which means that if a user is editing the
current record after a mEditRecord, then no other user can call mUpdateRecord
until that user is finished. Any other call to mEditRecord would fail because the
record would be locked. Both V12Error() and V12Status() would report such
failures.
Syntax:
mGetProperty(gDB, "sharedRWcount")
Scenario 1: Scenario 2:
User 1 and User 2 access the same V12 User 2 accesses the same V12 database file
database on a Remote Server. This is the as User 1, on User 1’s computer. User 1 and
typical multi-user access configuration. User 2 use separate instances of the
projector and V12-DBE Xtra.
Scenario 3: Scenario 4:
User 1 with two distinct Projectors, each User 1 and User 2 share the same projector,
with its own copy of the V12-DBE Xtra V12-DBE Xtra, and V12-DBE database file
share a single V12 database. NOTE: for the
Mac version to properly run in this scenario, (this scenario requires a locked projector
File Sharing must be set and the V12 file on a Windows computer).
database must be in a shared folder.
Example
set gTable1 = New(Xtra "V12table", mGetRef(gDB), "articles")
set gTable2 = New(Xtra "V12table", mGetRef(gDB), "articles")
mOrdreBy(gTable1, "price")
mOrdreBy(gTable2, "name")
mSelectAll(gTable1)
mSelectAll(gTable2)
This example defines two table instances (gTable1 and gTable2) for the table
articles. The selection in gTable1 is sorted by order of price, whereas in gTable2
it is sorted by order of name.
You deliver the Xtra file V12-DBE for Director.XTR and/or V12-DBE for
Director.X32 and/or V12-DBE for Director.X16. For an Xtra to be available to a
Director projector, you must to place it in a folder named "Xtras" located in the same
folder as the projector itself. Alternately, with Director 7, you can package the required
Xtras into your Director projector by including them in the Modify > Movie > Xtras
window.
As stated in the licensing agreement, you DO NOT deliver the license file
"V12-30.LIC", which is in the System:Preferences folder of your Macintosh, or the
Windows\System folder of your PC.
•√ Macromedia Director
•√ Projectors generated by Macromedia Director
•√ the V12-DBE Xtras
The following figure identifies which files are specific to Macintosh or Windows, and
which files are compatible to both Macintosh and Windows.
Macintosh
Windows only Macintosh only
and Windows
V12-DBE databases
Preference Thing
27 Raindrop on roses
35 Whiskers on kittens
50 Bright copper kettles
54 Warm woolen mittens
60 Round paper packages tied up with strings
75 Cream-colored ponies
87 Crisp apple strudels
92 Door bells and sleigh bells
95 Schnitzels with noodles
100 Wild geese that fly with the moon on their wings
The table is currently sorted by order of Preference, using that field's index and the
current record is the first record (27-Raindrop on roses).
Any modification to the Thing field does not affect the order of the selection.
However, modifying the Preference field would automatically cause the table to be
resorted with respect to the current index's sort order.
For example, modifying the value 27 above for 90 would instantly update the
selection to the following order, with the current record pointing to the 7th record.
Preference Thing
35 Whiskers on kittens
50 Bright copper kettles
54 Warm woolen mittens
60 Round paper packages tied up with strings
75 Cream-colored ponies
80 Crisp apple strudels
90 Raindrop on roses
92 Door bells and sleigh bells
95 Schnitzels with noodles
100 Wild geese that fly with the moon on their wings
To avoid this behavior, you must prohibit the modification of fields used in the current
index. Or better yet, create an additional indexed field that can be used as an internal
ID. This is how many database engines work internally.
The above query finds all soups and appetizers that require less than 30 minutes of
preparation time. This is not equivalent to:
mSetCriteria(gT, "TimeToPrepare", "<=", 30)
mSetCriteria(gT, "AND", "DishType", "=", "soup")
mSetCriteria(gT, "OR", "DishType", "=", "appetizer")
mSelect(gT)
which finds all soups that require less than 30 minutes of preparation time and all
appetizers regardless of the time required to prepare them. Thus, the order in which
criteria are expressed to V12-DBE is important.
However, V12-DBE cannot handle four criteria or more with alternating ANDs and
ORs. For example, the query "(Dish is soup or appetizer) and (Main Ingredient is
celery or eggplant)" cannot be directly expressed to V12-DBE.
Following are three techniques to workaround this limitation. Many others can be
easily derived from those techniques, but they all require some Lingo programming.
This technique requires to act on two V12table instances of the same table and to
merge the resulting selections.
Define a separate table instance of the same V12 table for each set of query your are
performing. For example:
set gT1 = new (Xtra "v12Table, mgetRef(gBD), "Recipes")
set gT2 = new (Xtra "v12Table, mgetRef(gBD), "Recipes")
You end up with gT1 and gT2 referencing two separate selections, both ordered by
RecipeID. You can run a small Lingo loop to intersect them:
set field "result" = EMPTY -- Dir member. Can also be a Lingo list
repeat while not V12Error() -- by "Next" on last rec of gT1 or gT2
set s1 = (mGetField(gT1, "RecipeID")
set s2 = (mGetField(gT2, "RecipeID")
if (s1 = s2) then
put mGetField(gT1, "RecipeName")&RETURN after field "result"
mGoNext(gT1)
mGoNext(gT2)
else if (s1 < s2) then
mGoNext(gT1)
else
mGoNext(gT2)
end if
end repeat
This Lingo loop performs an AND (intersection) between two selections. It can easily
be modified to perform an OR (union).
If you need to run your query with 3, 4, 5,... sets of criteria, just modify the above
Lingo loop to operate on 3, 4, 5,... V12table instances.
This technique may be faster if the number of records satisfying the search criteria is
large, but it works only if your database is on a writeable volume (ie, not on CD-
ROM).
In this case, you work with a single gTable instance. In your database structure, for
that table, define an additional indexed field of type Integer named "Marker". Initially,
this field contains 0s for all records.
Then, run the "(Dish is soup or appetizer) and (Main Ingredient is celery or eggplant)"
query in two rounds:
mSetCriteria(gTable, "DishType", "=", "soup")
mSetCriteria(gTable, "OR", "DishType", "=", "appetizer")
mSelect(gtable)
At the end, restore the marked fields to 0 so to prepare them for another query.
The field concatenation technique works for queries that use ANDs at the lowest level,
and ORs a the higher level, such as:
(Origin is Italian AND Dish is appetizer) or (Origin is French AND Dish is soup)
Furthermore, all of your search criteria — with the possible exception of the last one
— must use the "=" operators. The last operator can be either "=" or "starts".
This technique requires some preparation at the database design step. Such a
preparation is sometimes called data preconditioning.
When designing your database, you plan for additional fields that would hold the
concatenated result of the lowest level queries. For example, in the above example you
would create an additional field named OriginType that would hold the
concatenation of DishOrigin and DishType. That field would contain values such as
"Italian Asparagus al dente"
"Italian Prociutto e melone"
"French Soupe à l'oignon"
"Italian Melanzane del re"
"French Bouillon de merguez au miel"
Double-byte strings can be successfully stored and retrieved from V12 fields of type
String. The calls to V12-DBE are identical to those used for single-byte strings (see
Step 5: Implementing the User Interface).
You can also store and retrieve styled double-byte strings with calls to
mSetField(gTable, "name", member 5 of castlib "V12stuff")
mGetField(gTable, "name", member 5 of castlib "V12stuff")
See Managing Styled Text for details on the storage and retrieval of styled text.
The indexes of V12 Database Engine version 3.0 are not designed to handle double-
byte strings. This implies the following limitations on the queries that can be expressed
for searching (see Searching Data with mSetCriteria).
•√ the Equal and <> operators works properly, as with single-byte languages.
•√ the Starts operator can fail in certain circumstances, such as when an odd
number of bytes is searched with mSetCriteria.
•√ the Contains operator finds all records that match the specified criteria, but
can also find additional records that don't (Remember: the contains
operator does not take advantage of indexes. It is therefore slow).
•√ the >, <, >=, <= operators will fail most of the time. They would work
properly only in exceptional cases where the sort order of each stored double-
byte string happens to match the numeric (i.e. single-byte) ordering of that
string.
Work Around
A convenient and easy way to work around the above limitations is to manage double-
byte strings as if they were media. That is, only use them for the purpose of storage and
retrieval, and use additional fields of type Integer or single-byte String to store codes
that would determine the searching behavior and sorting order of the corresponding
double-byte strings. Either fields of type String or Media can be used to store such
double-byte strings.
•√ Directly print Director's stage with the PrintFrom Lingo command. This is very
easy to implement and does not require an additional Xtra. However, it simply
prints Director's stage and thus prints at 75 or so dots-per-inch.
•√ Use the mPrint Xtra (see http://www.mediashoppe.com). mPrint is easy to use and
features an advanced page design tool. However, it only runs on Windows 9x/NT.
3. Choose Code > Generate > Director Lingo (F7) to have mPrint Designer generate
the Lingo script needed for printing.
At step 6, you can optionally preview your report instead of printing it by replacing the
call to tMsPrintReport() by tMsPreviewReport()
For example, to print the content of selected fields of a record first design as report
similar to this:
In mPrint Designer, choose Code > Generate > Director Lingo. You get the following
script:
tMsRegisterMPrint("mp-xxxxxxxxxx")
tMsCreateReport(the pathname&"myReport.mpf")
tMsBeginRegion("MainRegion")
tMsSetVariable("FirstName","--value--")
tMsEndRegion()
tMsPrintReport()
tMsFreeReport()
This example shows how to print the first ten records of a V12-DBE selection with
mPrint. Printing any other number of records, or the entire selection, is similar.
"Top Ten Performers" is a mPrint Text object named TEXT1. "FirstName" is a mPrint
variable. The rectangle enclosing "FirstName" is a Repeat Region named
"NameListRegion".
This example shows how to print two columns on a mPrint report: the left column is a
list of products. The right column in a list of prices matching each product of the left
column. The right column is right-aligned.
This example also shows how to print a sum at the bottom of a column. This technique
can be easily extended to print a product, mean, standard deviation, etc.
In mPrint Designer, draw two Regions. In each region, create a Repeat Region: one for
each column. In the left region Repeat Region, create a variable named ProductName.
In the right region Repeat Region, create a variable named Price. Open the Properties
of the Price variable, and choose Alignment: Right. Finally, in the PriceColumn
Region but outside of the PriceList Repeat Region, create a variable named Total.
Note that the statement that prints "Total" was moved to after the repeat loop.
First, initialize PrintOMatic as you normally would, and print the required titles, texts,
tables, etc. A typical PrintOMatic initialization script is:
global doc
set doc = new(xtra "PrintOMatic")
newPage doc -- add a new page
Then, if you want to print the content of a specific V12-DBE field at the current
coordinates location of PrintOMatic, call V12-DBE's mGetField method followed by
PrintOMatic's append method. Example:
set x = mGetField(gT, "FirstName")
append doc, x, FALSE
If you want to compute a function (e.g., number of items, sum, average, product, mean,
standard deviation, etc.), initialize a Lingo variable and keep updating it in your loop.
Example: to compute the average price of all the products in a selection:
set n = mSelectCount(gT)
set total = 0
repeat with i = 1 to n
set prc = mGetField(gT, "price")
append doc, prc & RETURN, FALSE
set total = total + prc
end repeat
append doc, "Total=" & total & REUTRN, FALSE
append doc, "Average=" & total/n & REUTRN, FALSE
To print multiple columns with PrintOMatic, you must first create frames in your
document. For example, to print a list of products along with their corresponding
prices (prices must obviously right-adjust), you would write a script similar to the
following:
on PrintProdAndPrice
set doc = new(xtra "PrintOMatic")
newPage doc -- add a new page
It is very convenient, with PrintOMatic, to first preview your page before printing it.
To preview a page, call
printPreview doc
mSelect chooses the index that delivers the fastest search time based on the database
structure. It does an excellent job most of the time. However, it can be fooled in some
extreme cases where the actual data in the database is not uniform. In such cases, you
can optimize your queries to further improve searching time.
mOrderBy indifferently uses any one index defined for the field it sorts (if more than
one such index is defined). There is no performance handicap in using one index or
another. However, at any time, only one index can be used by V12-DBE. Thus, if you
call mOrderBy and mSelect in a single query, V12-DBE uses the best index it can to
build the selection, and then sorts the selection without relying on indexes1.
mSelect chooses its best index based on the following algorithm. Assume that your
query is :
(Field1 = A) AND (Field2 starts B) AND (Field3 < C)
V12-DBE first checks if Field1 is the first segment of an index (i.e., a simple index is
defined for it, or it is the first field of a compound index). If such an index exists, it is
automatically considered to be the best index for the query. Otherwise, V12-DBE
checks if Field2 is the first segment of an index. If so, that index is the best index for
the query. Otherwise, V12-DBE attempts to apply the same logic to Field3. If none of
Field1, Field2 and Field3 is indexed, or appears in the first segment of a
compound index, the table's default index is used.
The index chosen by mSelect determines the selection's default sorting. Thus, if
Field1 is not indexed and Field2's index is chosen, the following script yields a
selection sorted by Field2:
mSetCriteria(gT, "Field1", "=", A)
mSetCriteria(gT, "AND", "Field2", "starts", B)
mSetCriteria(gT, "AND", "Field3", "<", C)
mSelect(gT)
1
Actually, V12-DBE can use two or more indexes for a single search. However, for
the purpose of combined search and sort operations, using an index for sorting would
require more CPU effort than actually sorting the selection with Quicksort. Quicksort
is the most efficient sorting algorithm known to date.
As a result, you can control the sorting order of your selection without calling
mOrderBy.
The following query uses the index LastNameNdx. It delivers a selection sorted by
LastName and then by order of input. Since all the last names in the selection would
be identical ("Smith"), the selection's sorting order would be the order in which records
were added to the database.
mSetCriteria(gT, "LastName", "=", "Smith")
mSelect(gT)
If you need to sort all the Smiths in your table by order of First Name, run the
following script:
mSetCriteria(gT, "LastName", "=", "Smith")
mOrderBy(gT, "FirstName")
mSelect(gT)
You can optimize this script by slightly modifying your database structure as follows:
[TABLE]
Addresses
[FIELDS]
LastName string
FirstName string
YearOfBirth integer
[INDEXES]
LastNameNdx duplicate LastName ascending FirstName ascending
FirstNameNdx duplicate FirstName ascending
You can further optimize your queries by imposing a specific index for your search, if
more than one index fits the best index criteria.
Assume, for example, that your table contains two compound indexes: one for
LastName/FirstName and one for LastName/YearOfBirth:
[TABLE]
Addresses
[FIELDS]
LastName string
FirstName string
YearOfBirth integer
[INDEXES]
The query:
mSetCriteria(gT, "LastName", "=", "Smith")
mSelect(gT)
The criterion (YearOfBirth > 0) does not affect your selection in any way (since
any data stored in this field is always greater than 0). However, its presence forces
V12-DBE to use the LastBirthNdx index thus resulting in a selection sorted by
YearOfBirth.
For example, if you are tracking students scores, you would have two tables: one to
identify students, and one to log tests results. Following is a typical relational database
structure for student tracking:
[TABLE]
Students
[FIELDS]
ID integer indexed
LastName string indexed
FirstName string
Email string
Faculty string
[TABLE]
Scores
[FIELDS]
StudentID integer indexed
TestID integer indexed
Score integer indexed
TimeSpent integer
Table Students and Scores are related to each other through their respective ID and
StudentID fields. A shorthand notation to express this is:
1− N
Students :: ID → Scores :: StudentID
1-N means that many records in the Scores table can be related to a single record in
the Students table, and that to each record in the Scores table is related to exactly
one record in the Students table. This is called a One-To-Many relation.
Example:
SCORES
TestID StudentID Score …
STUDENTS 1081 127 90 …
ID LastName FirstName … 1284 127 45 …
127 Cartman Eric … 2015 127 98 …
128 Broslowsky Kyle … 1081 128 75 …
129 McCormick Kenny … 2015 128 65 …
1081 129 66 …
If you look at the relation the other way around, that is starting from the Scores table,
you get a N-1, or Many-to-One relation noted:
N −1
Scores :: StudentID → Students :: ID
2
In exceptional cases, relations can be established from a table's records onto records
of the same table.
[FIELDS]
ID integer indexed
Title string indexed
Topic string indexed
Author string
CreationDate date
LastUpdateDate date
Field TestID of table Scores refers to field ID of table Tests. This is another Many-
to-One relation:
N −1
Scores :: TestID → Tests :: ID
Example:
SCORES
StudentID TestID …
STUDENTS TESTS
127 1081 …
ID LastName … ID Title …
127 1284 …
127 Cartman … 1081 Trigonometry …
127 2015 …
128 Broslowsky … 1284 Genetics …
128 1081 …
129 McCormick … 2015 Rocket Science …
128 2015 …
129 1081 …
The structure of the overall database now contains three tables and can be represented
by the following Entity-Relation Diagram.
ST UDENT S T EST S
ID inte ger ID inte ger
La stName string Title string
Fi rstName strin g Topic string
Email strin g Autho r string
Fa cul ty strin g Creati onDate date
La stUpda teDate date
SCORES
TestID inte ger
StudentID inte ger
Score inte ger
Time Spent i nteg er
In this example, we were lucky enough to have a Scores tables that naturally links
Students and Tests, but in many cases, creating a Many-to-Many relation is not
obvious: you often need to create a fake table that only contains the IDs of both sides'
entities. Such a table is called an Associative Table: It's sole purpose is to put other
tables in relation with each other.
V12 Database Engine does not contain a language that automatically resolve relations
between tables. Instead, it relies on Lingo to do so.
In the above example, resolving a One-to-Many relation from the Students table is
something like "given a Student's last name, select all the records in table Scores that
a related to it". The following script performs this operation:
-- first locate record of student who's last name is LName
mSetCriteria(gTStudents, "LastName", "=", LName)
mSelect(gTStudents)
-- get student's ID
sID = mGetField(gTStudents, "ID")
-- look for score records where StudentID is sID
mSetCriteria(gTScores, "StudentID", "=", sID)
mOrderBy(gTScores, "Score") -- sorting is optional
mSelect(gTScores)
At the end of this script, gTScores'selection contains LName's scores sorted lowest
to highest.
Example: if LName was assigned the string "Cartman" in the above example, after the
execution of the above script, table gTScores' selection would contain:
SCORES
TestID StudentID Score …
1284 127 45 …
1081 127 90 …
2015 127 98 …
At the end of this script, gTStudents' current record is the one gTScores's current
record is related to.
1081 128 75 …
the corresponding record in table gStudents would be
Another more complex Many-to-One relation resolving question would be "list the last
names of all the students who scored 75 or higher at test number 1081". It can be
answered by the following script:
-- first locate all Scores records that match criteria
mSetCriteria(gTScores, "TestID", "=", 1081)
mSetCriteria(gTScores, "AND", "Score", ">=", 75)
mSelect(gTScores)
-- loop through all Student Ids and append them to member "result"
put EMPTY into field "result"
repeat with i = 1 to mSelectCount(gTScores)
mGo(gTScores, i)
sID = mGetField(gTScores, "StudentID")
This script lists the last names of all the students that match the specified criteria in a
Director member, in contrast to the previous script which leaves them in a V12-DBE
selection. Although a V12-DBE selection can be easily dumped to a Director field, the
opposite is not true.
Thus, if you need to further manage the list of last names created above, you must set
the current record to the one that matches a specific last name's and then perform the
required operation. This is sometimes called the lazy approach, whereby a piece of
data is accessed only when it is needed (as opposed to processing data before it is
actually needed, which may yield faster results, but at a higher pre-processing
overhead). V12-DBE's high-speed data search and retrieval routines enable you to
implement the lazy approach without handicap of performance.
Resolving Many-to-Many relations is much more complex than resolving other types
of relations. Even powerful query languages such as SQL cannot perform this
operation in a simple way.
For example, assuming that Mrs. Crabtree is the author of both the Trigonometry and
the Rocket Science courses, running this script on the above example would yield the
following result:
Cartman
Broslowsky
A shortcoming of this script is it's inability to sort the results, or to remove duplicates
from the results. A possible work around this limitation consists in creating an
additional field named Marker in table Students and, instead of immediately listing
all last names in field "result", setting the Marker field of found records to 1. At the
end, just find all marked records in table Students. Of course, this requires the
database to be on a writeable volume.
-- find all students who took one of Mrs.Crabtree's tests
-- and list their last names in alphabetic order, without duplicates
-- first locate all Tests authored by Mrs Crabtree
mSetCriteria(gTests, "Author", "=", "Crabtree")
mSelect(gTests)
put EMPTY into field "result"
-- loop through each test created by Mrs.Crabtree
repeat with i = 1 to mSelectCount(gTests)
mGo(gTests, i)
set tID = mGetField(gTests, "ID")
mSetCriteria(gTScores, "testID", "=", tID)
mSelect(gTScores)
-- loop through student IDs and retrieve name
repeat with j = 1 to mSelectCount(gTScores)
mGo(gTScores, j)
set sID = mGetField(gTScores, "StudentID")
mSetCriteria(gTstudents, "ID", "=", )
mSelect(gTstudents)
-- mark the found record
mEditRecord(gTstudents)
mSetField(gTstudents, "Marker", 1)
mUpdateRecord(gTstudents)
end repeat
end repeat
-- once all records are marked, select them all
mSetCriteria(gTstudents, "Marker", "=", 1)
mOrderBy(gTstudents, "LastName")
mSelect(gTstudents)
put mGetField(gTstudents, "literal") into field "results"
-- DO NOT forget to restore Markers to 0 to prepare
-- for next search
In the above example, this modified script would yield the result:
Broslowsky
Cartman
McCormick
The methods used to modify an existing V12 database are (see details in Methods
References):
mEditDBStructure
mUpdateDBStructure
mCreateField
mCreateFullIndex
mCreateIndex
mCreateTable
mDeleteTable
mRenameField
Modifying an existing database's structure is a tedious task and can be easily worked
around as follows:
1. Dump the structure of your initial database (see Viewing the Structure of a
Database).
4. Import the content of each table to the new V12 database (see Importing from
V12-DBE).
The above steps can be executed either through Lingo handlers, or using the V12-DBE
Tool.
This applies to V12-DBE as well as FileMaker Pro, MS Access and many other
database management systems.
To protect you V12 database from illegal viewing and/or tampering, you can use
simple techniques such as giving it a system file's name or making it invisible to the
Mac Finder or Windows Explorer.
If you really need to encrypt your data, you can use a third party Xtras (see
http://www.macromedia.com/software/xtras/director) or use your own Lingo
encryption handler. In either case, you will not be able to index encrypted strings.
Searching and sorting encrypted indexed strings would not work properly. Encrypted
fields must rely on other non-encrypted fields for searching and sorting.
The following Lingo handlers enable the encryption and decryption of strings based on
a variation of the One-Time Pad algorithm. One-Time Pad is very easy to program,
however it is only moderately secure, especially if a hacker is entitled to generate large
amounts of original/encrypted message pairs.
global gEncryptKey
on initCrypt
-- change this encryption key to the string of your choice.
-- The longer the string, the stronger your encryption algorithm.
set gEncryptKey = "thisisthesecretkey."
end initCrypt
on encrypt str
set res = ""
-- avoid redundant calls: compute lengths in advance
set keyLength = length (gEncryptKey)
set strLength = length (str)
repeat with i = 1 to strLength
set keyIdx = i mod keyLength
set tmp = numToChar ((charToNum (char i of str) + charToNum ¬
(char keyIdx of gEncryptKey)) mod 256)
-- check if resulting string contains 0.
-- if so, Director would trucate the string.
if (tmp = numToChar (0)) then
-- the escape code for a 00 char is 0102
set tmp = numToChar (1) & numToChar (2)
-- encode 01 as well to differentiate from encoded "0"s
else if (tmp = numToChar (1)) then
set tmp = tmp & tmp -- the escape code for a 01 char is 0101
end if
on cleanEscape str
-- just replace every instance of 0101 by 01, and 0102 by 00
set res = ""
set strLength = length (str)
repeat with i = 1 to strLength
if (charToNum (char i of str) = 1) then
if (charToNum (char i + 1 of str) = 2) then
set res = res & numToChar (0)
else if (charToNum (char i + 1 of str) = 1) then
set res = res & numToChar (1)
end if
set i = i + 1
else
set res = res & char i of str
end if
end repeat
return res
end cleanEscape
To use the above handlers, first assign the encryption key of your choice to the global
variable gEncryptKey. Then, at startup, call initCrypt (e.g., on StartMovie). To
store an encrypted string to a V12 table, call:
mSetField(gT, "Account", encrypt(secretData) )
You can further enhance the strength of your encryption by creating an additional field
in your table for the encryption key — as opposed to using the same global
gEncryptKey for all fields and records. Thus, each record would be encrypted with a
different key, making it harder to hackers to crack your algorithm.
If you want to encrypt dates, floats or integers, convert them to strings first.
V12-DBE's default and custom String types' sorting and searching rules are defined by
the following tables where equivalent characters are listed on the same line separated
by one or more spaces and strict precedence is indicated by characters on successive
lines. For example:
j J
k K
l L
means that:
•√ K sorts after J and before L,
•√ j and J are equivalent (likewise, k and K are equivalent, and l and L are
equivalent too)
Characters omitted from a sorting and searching rules table are considered to sort after
those listed in the table, except for Control characters (such as Carriage Return,
Horizontal Tab, Vertical Tab, etc.) which are considered to sort before those listed in
the table.
(If the tables below are not properly formatted in the HTML version of this manual,
please refer to the PDF version)
1. '‘’ 77. 2
2. "«» “” 78. 3
3. !¡ 79. 4
4. ?¿ 80. 5
5. . 81. 6
6. , 82. 7
7. : 83. 8
8. ; 40. 9
9. … 41. aàáâãAÀÁÂÃ
10. # 42. b B
11. $ 43. cçCÇ
12. ¢ 44. d D
13. £ 45. eèéêëEÈÉÊË
14. ¥ 46. f F
15. % ‰ 47. g G
16. ° 48. h H
17. | 49. iìíîïIÌÍÎÏ
18. †‡ 50. j J
19. [] 51. k K
20. {} 52. l L
21. () 53. mM
22. <> 54. nñNÑ
23. * 55. oòóôõœ OÒÓÔÕ Œ
24. + 56. p P
25. - 57. q Q
26. / 58. r R
27. \ 59. sßS
28. = 60. t T
29. ~ 61. uùúûüUÙÚÛÜ
30. ¬-– — 62. vV
31. § 63. w W
32. µ 64. x X
33. & 65. yÿYŸ
34. @ 66. z Z
35. © 67. æ Æ
36. ƒ 68. ø Ø
37. ® 69. å Å
38. 0 70. äÄ
39. 1 71. öÖ
1. '‘’ 40. 2
2. "«» “” 41. 3
3. !¡ 42. 4
4. ?¿ 43. 5
5. . 44. 6
6. , 45. 7
7. : 46. 8
8. ; 47. 9
9. … 48. aàáâãäAÀÁÂÃÄ
10. # 49. b B
11. $ 50. cçCÇ
12. ¢ 51. d D
13. £ 52. eèéêëEÈÉÊË
14. ¥ 53. f F
15. % ‰ 54. g G
16. ° 55. h H
17. | 56. iìíîïIÌÍÎÏ
18. †‡ 57. j J
19. [] 58. k K
20. {} 59. l L
21. () 60. mM
22. <> 61. nN
23. * 62. ñÑ
24. + 63. oòóôõöœ OÒÓÔÕÖŒ
25. - 64. p P
26. / 65. q Q
27. \ 66. r R
28. = 67. sßS
29. ~ 68. t T
30. ¬-– — 69. uùúûüUÙÚÛÜ
31. § 70. vV
32. µ 71. w W
33. & 72. x X
34. @ 73. yÿYŸ
35. © 74. z Z
36. ƒ 75. æ Æ
37. ® 76. ø Ø
38. 0 77. å Å
39. 1
To define your own sorting and searching rules, build a table similar to the ones listed
above in a Director member of type Field. Equivalent characters are listed on a single
line, whereas precedence is indicated by successive lines.
Then, call mSetProperty with the keyword "String." (note the period after String)
followed by the name of the custom string type.
For example, if your sorting and searching rules are defined in a Director field named
"Klingon-Sort-Order" and if the new custom string type is "Klingon", the following
statement defines the new custom type:
mSetProperty(gDB, "String.Klingon", field "Klingon-Sort-Order")
From then on, the type String.Klingon can be used in mCreateField and
mReadDBstructure to define new fields.
Syntax
mAddRecord(gTable)
Parameters
(none)
Description
Adds a new record to the table and sets it as the current record. Calls to mAddRecord are
generally followed by calls to mSetField and must end with a call to mUpdateRecord.
Example
-- add a record to gTable, put data in fields "name" and "price" and updates the
record:
mAddRecord(gTable)
mSetField(gTable, "field1_string", "funnel")
mSetField(gTable, "field2_float", 2.95)
mUpdateRecord(gTable)
See Also
mEditRecord, mSetField, mUpdateRecord
mBuild (V12dbe)
Syntax
mBuild (gDB)
Parameters
(none)
Description
Create the database structure defined by mReadDBstructure and writes it to a disk file. After
successfully calling mBuild, the database remains open in ReadWrite mode. Data can be
immediately imported to it.
Example
-- Reads the database definition contained in a text file:
set gDB = New(Xtra "V12dbe", "myBase", "Create", "very secret password")
mReadDBStructure(gDB, the pathname & "DatabaseDef.txt")
set mBuild(gDB)
See Also
new, mReadDBstructure.
Syntax
mCustom(gDB)
Parameters
(none)
Description
Undocumented generic method for project-specific implementations.
Contact Integration New Media, Inc. for specific implementations.
mCustom (V12Table)
Syntax
mCustom(gTable)
Parameters
(none)
Description
Undocumented generic method for project-specific implementations.
Contact Integration New Media, Inc.for specific implementations.
mDataFormat (V12Table)
Syntax
mDataFormat(gTable, fieldName, format)
Parameters
fielName = name of field to which format must be applied.
format = format applied to the content of fieldName.
Description
Associate a formatting pattern to the data retrieved from fieldName. Data formats can be
applied to fields of type Float, Integer and Date. If the retrieved data is longer then the
formatting pattern, V12 returns the corresponding number of "#": 56.78 would be returned as
"#.##" if the format was set to "9.99".
Example
mDataFormat(gTable,"date","dd/mm/yy")
-- characters can be added before the data such as:
-- 56.78 is formated to "00056.78":
mDataFormat(gTable, "price", "99999.99")
-- 56.78 is formated to "56.78$":
mDataFormat(gTable, "price", "99.99$")
-- 56.78 is formated to " 56.87":
mDataFormat(gTable, "price", "###.99")
mDeleteRecord (V12Table)
Syntax
mDeleteRecord(gTable)
Parameters
(none)
Description
Delete the current record. After calling mDeleteRecord, the record following the current record
becomes the new current record. If no record follows the deleted record, the preceding record
becomes the new current record. If no record precedes the deleted record, the current record is
not defined.
Example
mDeleteRecord(gTable)
See Also
mAddRecord, mEditRecord
mDumpStructure (V12dbe)
Syntax
mDumpStructure(gDB)
Parameters
(none)
Description
Retrieve information on a database structure. Very convenient for debugging.
Example
put mDumpStructure(gDB)
put mDumpStructure(gDB) into field "dummy"
mEditRecord (V12Table)
Syntax
mEditRecord(gTable)
Parameters
(none)
Example
mEditRecord(gTable)
mSetField(gTable, "name", "funnel")
mSetField(gTable, "price", 2.95)
mUpdateRecord(gTable)
See Also
mAddRecord, mSetField, mUpdateRecord
mFind (V12Table)
-- alternative to mGo
mGetField (V12Table)
Syntax
mGetField(gTable, fieldName [, dataFormat])
Parameters
fieldName = name of the field to read.
dataFormat = patten for Integer, Float and Date formatting.
Description
Retrieve the content of field FieldName for the current record. If dataFormat is specified, the
retrieved data is formatted accordingly. Otherwise, if a formatting pattern is assigned to
FieldName with mDataFormat, that format is taken into account. mGetField’s dataFormat
parameter overrides mDataFormat’s setting.
Example
set name = mGetField(gTable, "theName")
set date = mGetField(gTable, "theDate", "YY-MM-DD")
See Also
mDataFormat, mGetSelection, mGetMedia, mSetField
mGetMedia (V12Table)
Syntax
mGetMedia(gTable, fieldName, Member)
Parameters
fieldName = name of the field from which media is retrieved.
member = cast member in which media is stored.
Example
-- get the media from field "photo" and
-- store in the cast named "thePhotoCast" in castlib 1:
mGetMedia(gTable, "photo", Member "thePhotoCast")
-- or:
mGetMedia(gTable, "photo", member "thePhotoCast" of castlib 1)
See Also
mDataFormat, mGetSelection, mGetField, mSetMedia
mGetPosition (V12Table)
Syntax
mGetPosition(gTable)
Parameters
(none)
Description
Return the position of the current record in the selection.
Example
put mGetPosition(gTable)
See Also
mGo, mGoPrevious, mGoNext, mGoFirst, mGoLast, mSelectCount
mGetPropertyNames
-- introduced with V12 3.0. Return names of properties.
mGetProperty (V12dbe)
Syntax
mGetProperty(gDB, Prop)
Parameters
Prop = "virtualCR" | "characterSet" | "resources" | "currentDate" | "weekDays" |
"shortWeekDays" | "months" | "shortMonths".
Description
Retrieve the value of the property Prop.
Example
put mGetProperty(gDB, "characterSet")
-- return: "Windows-ANSI"
See Also
mSetProperty
mGetSelection (V12Table)
Syntax
mGetSelection(gTable, [outputType [, From [, #recs [, FieldDelimiter] [,
RecordDelimiter] [, FieldNames ]* ]]]]])
Parameters
outputType = “LITERAL” | “LIST” | “PROPERTYLIST”
From = number of first record to retrieve (default = position of current record)
#recs = number of records to retrieve (default value is Size of selection - From +1)
FieldDelimiter = delimiter between fieldsn (default = Tab, for “LITERAL” only)
RecordDelimiter = delimiter between record (default = Return, for “LITERAL” only))
FieldNames = any number of field names
Description
Retrieve one or more fields in one or more records of the selection. Optionally, you can specify
custom field and record delimiters (with the “Literal” option only. Delimiters are not supported
by the “List” and “PropertyList” options). If fieldNames are omitted, all fields are returned.
Otherwise, only the specified field are returned. “LITERAL” returns a string. “LIST” returns a
Lingo list. “PROPERTYLIST” returns a Lingo property list.
Example
set x = mGetSelection(gTable)
set x = mGetSelection(gTable, "LITERAL", mGetPosition(gTable), 1)
set x = mGetSelection(gTable, "LITERAL", 1, mSelectCount(gTable), TAB, RETURN,
"number", "name", "price")
Notes
Use mError to discover whether mGetField has succeeded, mGetField is the only method that
follows this rule.
See Also
mGetField, mSetField, mDataFormat
mGetUnique (V12Table)
-- similar to mGetSelection. Operates on Master Field only. Returns unique
values.
mGo (V12Table)
Syntax
mGo(gTable, toPosition)
Description
Set the current record to the toPosition nth record of the selection.
Example
-- set the current record to the 45th of the selection.
mGo(gTable, 45)
See Also
mGoFirst, mGoLast, mGoNext, mGoPrevious and mGetPosition
mGoFirst (V12Table)
Syntax
mGoFirst(gTable)
Parameters
(none)
Description
Set the current record to the first record of the selection.
Example
mGoFirst(gTable)
See Also
mGoLast, mGoPrevious, mGoNext, mGo and mGetPosition
mGoLast (V12Table)
Syntax
mGoLast(gTable)
Parameters
(none)
Description
Set the current record to the last record of the selection.
Example
mGoLast(gTable)
See Also
mGoFirst, mGoPrevious, mGoNext, mGo and mGetPosition
Syntax
mGoNext(gTable)
Parameters
(none)
Description
Set the current record to the record following the actual current record in the selection.
Example
mGoNext(gTable)
See Also
mGoFirst, mGoLast, mGoPrevious, mGo and mGetPosition
mGoPrevious (V12Table)
Syntax
mGoPrevious(gTable)
Parameters
(none)
Description
Set the current record to the record preceding the actual current record in the selection.
Example
mGoPrevious(gTable)
See Also
mGoFirst, mGoLast, mGoNext, mGo and mGetPosition
mImport (V12Table)
-- New method: import from Text, DBF, ODBC drivers
mImportFile (V12Table)
Syntax
mImportFile(gTable, inputType, inputData [, fieldDelimiter [, recordDelimiter]])
Parameters
inputType = type of the file to import: “LITERAL” | “TEXT” | “V12” | “DBF”.
inputData = pathname of file to import.
fieldDelimiter and recordDelimiter = single-character delimiters.
Description
Import the data from the specified source. Syntax varies according to inputType. See manual.
Example
-- import from within Director:
mImportFile(gTable, "LITERAL", field "data")
-- Default delemiters: TAB and RETURN:
mImportFile(gTable, "LITERAL", field "data", TAB, RETURN)
-- import from a TEXT file:
mImportFile(gTable, "TEXT", "data.txt", TAB, RETURN)
-- import from a V12 database file
-- you need to specify the password, put "" if there is
-- none, and specify from which table the data is taken
-- from:
mImportFile(gTable, "V12", the pathname & "data.v12", "password", "table")
-- import from a DBF database file:
mImportFile(gTable, "DBF", the pathname & "data.DBF")
Notes
During the importation of data from a V12 database, if two fields bear the same name but are of
different types, try type casting.
The index of the files from which you are importing the data are not taken into consideration.
Only the indexes of the host files are brought up-to-date.
See Also
mEditRecord, mUpdateRecord
mOrderBy (V12Table)
Syntax
mOrderBy(gTable, fieldName [, SortOrder])
Parameters
fieldName = name of field to use as the sorting key.
SortOrder = “ascending” | “descending”, Default = “ascending”
Description
Sort the selection according to field fieldName.This method is normally called just before the
mSelect method is used.
NOTE: when mOrderBy is used before mSelectAll, fieldName must be indexed.
Example
mOrderBy(gTable, "lastName") -- ascending by default.
mSelect(gTable)
mReadDBStructure (V12dbe)
Syntax
mReadDBStructure(gDB, inputType, inputData,[password])
-- accepts importing from ODBC drivers
Parameters
inputType = "LITERAL" | "TEXT" | "V12" | "DBF"
inputData = database descriptor expression (if inputType = "LITERAL”) or pathname of
template file (otherwise)
password is releavnt only if inputType = "V12".
Description
Create a new database or modify an existing one. mReadDBstructure can read a definition from
a string, field or variable (LITERAL), from a text file (TEXT), from another V12 database file
or from a DBF file (DBF).
The size of the database descriptor is limited to 32K.
Example
-- read a definition from a Director field member:
mReadDBStructure(gDB,"LITERAL",field "definition")
-- read a definition from a TEXT file:
mReadDBStructure(gDB,"TEXT", the pathname & "definition.txt")
-- read a definition from a V12 database file:
mReadDBStructure(gDB,"V12", the pathname & "definition.v12", "top secret")
-- read a definition from a DBF database file:
mReadDBStructure(gDB,"DBF", the pathname & "definition.dbf")
See Also
new, mBuild
mSelDelete (V12Table)
Syntax
mSelDelete(gTable)
Parameters
(none)
Description
Delete all the records of a selection. At the end of the operation, the selection is empty.
Example
-- the following will delete the current selection:
mSelDelete(gTable)
See Also
mDeleteRecord
Syntax
mSelect(gTable)
-- accepts partial selections
Parameters
(none)
Description
Trigger the selection process. This is required after calls to mSetIndex, mSetCriteria and/or
mOrderBy. If no record satisfies the search criteria, mSelect returns an empty selection and sets
the current record to an undefined value.
Example
-- select all records of the table and sort them by order of catalog number:
mSetIndex(gTable, "CatNumberNdx")
mSelect(gTable)
-- select all items that cost at least $20,
-- and at most $40:
mSetCriteria(gTable, "price", ">=", 20)
mSetCriteria(gTable, "and", "price", "<=", 40)
mSelect(gTable)
-- select all items that cost at most $40
-- and sort them by alphabetic order:
mSetCriteria(gTable, "price", "<=", 40)
mOrderBy(gTable, "name")
mSelect(gTable)
See Also
mSetIndex, mSetCriteria, mOrderBy
mSelectAll (V12Table)
Syntax
mSelectAll(gTable)
Parameters
(none)
Description
Select all the records of a table. The sorting order for the selection is the same as the most
recently chosen index unless it is preceded by mOrderby. That index is either explicitely chosen
by you (mSetIndex) or automatically chosen by mSetCriteria and/or mOrderBy.
Example
mOrderby(gT,"price")
mSelectAll(gTable)
See Also
mOrderby
Syntax
mSelectCount(gTable)
Parameters
(none)
Description
Return the number of records in the selection. If the selection is empty, this method returns 0.
Example
put mSelectCount(gTable) into field "TotalHits"
See Also
mGetPosition
mSetCriteria (V12Table)
Syntax
mSetCriteria(gTable, [boolOp,] fieldName, operator, value)
Parameters
boolOp = “and” | “or”
fieldName = fieldin which value must be searched.
Operator = "=" | "<>" | "<" | ">" | "<=" | ">=" | "starts" | "contains" | "wordEquals" |
"wordStarts"
value is value to look for.
Description
Specify a search criteria. A call or sequence of calls to mSetCriteria must be followed by a call
to mSelect to trigger the search process. If more than one criterion is used, subsequent criteria
must use the boolean operator “and” or “or”.
Example
-- finds all cases where the field "muffin"
-- contains "chocolate"
mSetCriteria(gTable, "muffin", "wordEquals", "chocolate")
-- This instruction combines a full text search
-- in two fields with an ordinary search
mSetCriteria(gTable, "muffin", "wordEquals", "chocolate")
mSetCriteria(gTable, "or", "donut","containsWord", "chocolate")
mSetCriteria(gTable, "and", "name", "starts", "Shlomo")
mOrderBy(gTable, "price")--selection doesn't apply to full Index
mSelect(gTable)
See Also
mSelect, mOrderBy
Syntax
mSetField(gTable, fieldName, value)
Parameters
fieldName = name of the field who's content is modified
in the current record.
value = value to assign to the field fieldName of the current record.
Description
Set the content of field fieldName, of the current record, to value. If value is not of the same
type as fieldName, V12-DBE casts it to the appropriate type. If fieldName is a date, value must
be a valid date in V12-DBE's raw format (YYYY/MM/DD). Calls to mSetField must be
preceded by a call to mEditRecord or to mAddRecord, and must be followed by a call to
mUpdateRecord.
Example
-- editing an existing record:
mEditRecord(gTable)
mSetField(gTable, "description", field "myDescription")
mSetField(gTable, "height", integer(field "height"))
mUpdateRecord(gTable)
-- adding a new record to the table gTable:
mAddRecord(gTable)
mSetField(gTable, "name", "hot dog")
mSetField(gTable, "length", 2)
mSetField(gTable, "price", 1.95)
mUpdateRecord(gTable)
See Also
mGetField, mSetMedia, mGetMedia, mEditRecord, mUpdateRecord
mSetIndex (V12Table)
Syntax
mSetIndex(gTable, indexName)
Parameters
indexName = name of the index to set as current index
Description
Set the index indexName as the current index.
A call to mSetIndex must be followed by a call to mSelect.
It is useless to call mSetIndex before setting search criteria as mSetCriteria selects the most
appropriate index for a given query.
mSetIndex is seldom used. It is still supported only for the purpose of backwarding
compatiblity.
See Also
mSelectAll, mOrderBy
mSetMedia (V12Table)
Syntax
mSetMedia(gTable, fieldName, Member)
Parameters
fieldName = name of the field in which media is to be stored.
Member = cast member from which media is retrieved.
Description
Replace the content of the field FieldName of the current record with the cast member Member.
Example
-- get the media from the cast named "thePhotoCast".
-- in cast 1 and store it in the field "photo",
-- of the current record:
mSetMedia(gTable, "photo", member "thePhotoCast")
-- or
mSetMedia(gTable, "photo", member "thePhotoCast" of CastLib "internal")
See Also
mSetField, mGetMedia
mSetPassword (V12dbe)
Syntax
mSetPassword(gDB, oldPassword, newPassword)
Parameters
oldPassword = current password.
newPassword = new password.
Description
Change the current password (oldPassword) to a new one (newPassword). Either oldPassword
and/or newPassword can be empty strings.
Example
-- change the password "very secret" to "even more secret":
mSetPassword(gDB, "very secret", "even more secret")
-- change from an empty password to "my new password":
mSetPassword(gDB, "", "my new password")
Syntax
mSetProperty(gDB, prop, value)
Parameters
Prop = "virtualCR" | "characterSet" | "weekDays" | "shortWeekDays" | "months" |
"shortMonths".
Description
Set an existing property Prop to value, or create a new property named Prop and assigns value
to it. Special rules apply to properties that start with “string.” (see manual)
Example
-- turn on the verbose property:
mSetProperty (gDB, "months", "January February March April May June July August
September October November December")
mSetProperty (gDB, "string.MinWordLength", String(5) )
See Also
mGetProperty
mUpdateRecord (V12Table)
Syntax
mUpdateRecord(gTable)
Parameters
(none)
Description
Save modifications of the current record to the database file. A call to mUpdateRecord must be
preceded by a call to mEditRecord or mAddRecord.
Example
mEditRecord(gTable)
mSetField(gTable, "name", field "name")
mUpdateRecord(gTable)
See Also
mEditRecord, mAddRecord, mSetField
new (V12dbe)
Syntax
new(Xtra "V12dbe", databaseName, openMode, password)
-- now accepts "Shared ReadWrite" mode
If openMode is "create", the third parameter is a password and it is stored in the database file
for later reference.
If openMode is "readOnly" or "readWrite", the third parameter is a password and it is checked
against the one provided with "create".
Description
Create a database Xtra instance and returns a reference to it. Usually, that reference is assigned
to a global variable and used throughout the Lingo script to refer to that database.
If openMode is "create" and new database file is created. Table, field and index definitions must
follow. That process must be terminated by a call to mBuild.
If openMode is "readOnly", data can be read but not be written to the database.
If openMode is "readWrite", data can be read and written to the database.
Example
-- create a new database named "myBase"
-- and lock it with password "very secret":
set gDB = New(Xtra "V12dbe", "myBase", "Create", "very secret")
-- open an existing database file named
-- "myBase" in Read-Only mode:
-- (i.e. the database cannot be modified).
set gDB = New(Xtra "V12dbe", "myBase", "ReadOnly", "very secret")
-- open an existing database (FirstDB.v12) and
-- clone it in the directory of the current movie:
set gDB1 = New(Xtra "V12dbe", "KrazyCD:DataFiles:FirstDB.v12", "ReadOnly", "top
secret")
new (V12Table)
Syntax
new(Xtra "V12table", mGetRef(gDB), tableName)
Parameters
gDB = reference to the database object that contains tableName.
tableName = name of table to open.
Description
Create a table Xtra instance and opens the table
tableName. new returns a reference to that Xtra instance, which is normally assigned to a global
variable for later reference.
Example
set gDB = New(Xtra "V12dbe", "myBase", "ReadOnly", "Exclusive", "very secret")
set gTable = New(Xtra "V12dbe", gDB, "MegaTable")
See Also
new (v12dbe)
Syntax
V12Error()
Parameters
err = an integer (optional parameter)
Description
If you call v12Error without the Err parameter and right after calling a V12 method, it returns
an accurate and contextual description of the result. When called with the Err parameter, a
generic explanation of that error code is provided. V12Error() is global method: it is an
alternate syntax to mError.
Example
set errMsg = V12Error()
set errMsg = V12Error(-30000)
See Also
V12status
V12status (Global)
Syntax
V12Status()
Parameters
(none)
Description
Return the result code of the last V12-DBE method called. A return code of 0 means no error
occurred. A positive code signals a warning. A negative call signals an error.
Call V12Error to get a complete explanation of the problem(s) that occurred in the last method.
Example
mSetCriteria(gTable,"name","=","buzzlightyear")
if V12Status() then Alert V12Error()
See Also
V12Error
XtraVersion(Global)
-- Return version of Xtra.
Errors
-82 Function not loaded
-83 Function not found
-101 File locked
-1 Selection empty -102 File mode error
-2 Not initialized properly -103 Not enough memory or not
-3 Internal error multiuser OS
-4 Bad global area -104 Not locked
-5 Disk read error -105 Current record locked by
-6 Disk Write Error other user
-7 Header Read Error -106 Locked by self
-8 Header Write Error -107 Reset error
-9 The file does not exist or -108 Clear schema error
is already opened -109 Bad clear byte
-10 Not closed properly -110 Bad set byte
-11 No Space -111 Current Record already
-12 File already exists locked
-13 Not created properly -201 Bad select position number
-14 Incomplete Data -202 Bad field number
-15 Bad Header -203 Bad select type
-16 Bad Node -204 Bad select Op
-17 Bad Split Entry -205 User abort
-18 File Not Open -206 Bad key number
-19 File Not Closed -207 Different select types
-20 No Root Node -520 Invalid open mode
-21 No Current -530 Invalid parameter
-22 Bad Index Number -540 Bad edit mode
-23 Bad data length -550 Unknown error
-24 Bad reference type -560 Invalid identifier. Valid
-25 Bad field reference identifiers must have at
-26 Bad field pointer least one character
-27 Bad field handle -570 Invalid identifier. First
-28 Bad field type character must be
-29 Bad Sequence type alphabetic
-30 Bad key length -580 Invalid character(s) in
-31 Bad key type identifier
-32 Bad Duplicate type -590 Invalid identifier length.
-33 Buffer overflow Valid identifiers have at
-34 Bad file specification most 32 characters
-35 Bad minimum extend -600 Table '%s' does not exist
-36 Over demo limit -610 Field '%s' does not exist
-37 File seek in table '%s'
-38 Log record number not used -620 Field '%s' of type '%s' of
-39 Double lock current info table '%s' is of a type
-40 Double unlock current info that cannot be full-indexed
-41 Entry has bad data length -630 Invalid field type
-42 Bad segment number -640 Invalid parameter. The
-44 Memory allocation error parameter must be a valid
-45 Data checksum error V12base component
-46 Data definition checksum -650 Invalid parameter. The
error parameter must be a valid
-47 Unable to open database. V12table component
The maximum of users as -660 The database used by the
been reached table is not opened
-48 Bad build key -1010 Bad table instance. Check
-49 Duplicate key current instance
-50 Invalid number of buffers -1030 Too many records
-51 Key too big -1050 Invalid object
-52 Too many segments -1060 Invalid database structure
-53 Bad lock current info -1070 Memory allocation error
-81 Bad load shared library -1080 Field does not exist