Copyright © 2001, 2002
Harald Wabnig
email: wabnig@testready.net
homepage: www.testready.net
Test Environment Programmer Documentation
Test Environment Programmer Documentation
Special Installation under Windows
General Configurations for Development under Microsoft Visual-C++ 6.0
and Windows ME
Special Installation under Linux
C-Representation of Data-Types DATE, TIME and TIMESTAMP
Data-Types for Database-Structure-Definition
mymalloc, myrealloc, myfree, mystrdup:
Functions for Handling File-Extensions
Functions for Handling Directories
Functions for Reading/Writing Files
Test-Environment-Library-Functions
Hold_ValueStrings / Release_ValueStrings:
Fillup_String/Reduce_<*>String:
File_Read_Open / File_Write_Open / File_Append_Open:
Functions for Random Number Generation
Functions for Handling Virtual Time
Functions for Handling Data-Type DATE
Functions for Handling Data-Type TIME
Functions for Handling Data-Type TIMESTAMP
Functions for Handling Binary Large Objects
Functions for Storing/Loading Databases
Functions for Analysing and Changing Database-Rows
Functions for Comparing and Rounding Double Values
Functions for Accessing the Database
The test
environment library contains many functions which allows you to access the
Speedy/Speedy1-databases more comfortable from your C-application. Furthermore
it allows you to use extended functionality like binary large objects, database
saving and “tolerant” database loading and much more.
You must copy the
“dbsys”-library for Speedy and the “dbsys1”-library for Speedy1 to a directory
which is searched by your compiler.
If you want to use some
of the test environment functions without the Speedy/Speedy1-database you must
link your program to the “msglog”-library.
Required
C/C++-Options (in “Project-Settings/C/C++”):
/Zp4 sets
the correct alignment
/D _WIN32_WINNT=0x0400 defines
that Windows is used
/D "SPEEDY1" must
be defined to build with Speedy1-database (none defines Speedy-database)
Visual-C++
6.0 project-files are included for all examples which allows you to build the
binaries from the given source-codes.
You must
add the paths for the include- and lib-directories (this is done in
“Extras/Options/Directories”).
You can use
a bat-file to start the VC++ environment setting the include- and lib-directories
automatically.
The
bat-file would look like:
SET
PATH="c:\programme\microsoft visual
studio\common\MSDev98\bin";"c:\programme\microsoft visual
studio\VC98\bin"; C:\WINDOWS;C:\WINDOWS\COMMAND;
SET
INCLUDE="C:\Programme\Microsoft Visual Studio\VC98\INCLUDE";"C:\Programme\Microsoft
Visual Studio\VC98\MFC\INCLUDE";"C:\Programme\Microsoft Visual
Studio\VC98\ATL\INCLUDE";d:\<Speedy-path>\INCLUDE
SET
LIB="C:\Programme\Microsoft Visual
Studio\VC98\LIB";"C:\Programme\Microsoft Visual Studio\VC98\MFC\LIB";d:\<Speedy-path>\LIB
SET
DPATH=
start
"C:\Programme\Microsoft Visual Studio\Common\MSDev98\Bin\MSDEV.EXE"
Of course,
you must adjust the paths according to your local settings.
Note: You have to set up the MSDOS-program
to use maximum possible environment space (4096). Furthermore you should set up
the MSDOS-program to “close window on program termination”.
Make-files are
include for all the applications and examples. If you have already installed
the gcc-compiler you just have to type “make” in the directory of the
application and the application is built. You can create a debug-version if you
edit the “Makefile” (“Makefile1” for Speedy1).
Change
[…]
#CFLAGS = -g
CFLAGS = -O2
[…]
to
[…]
CFLAGS = -g
#CFLAGS = -O2
[…]
and execute
“make clean”. If you have installed the “ddd”-debugger you can then debug the
application by typing “ddd <application>”.
In this
section you find library constants.
Each
database-table-structure has an iDB-field. You can set this field to the given
constant and perform an <TABLE>_Do command which invokes the selected
command.
SQL_NONE (0): Do nothing.
SQL_SELECTPK (1): Select element by primary
key.
SQL_SELECTLK (2): Select element by logical
key.
SQL_INSERT (5): Insert the given
database-table-structure.
SQL_UPDATE (6): Update the given
database-table-structure.
SQL_DELETE (7): Delete the given database-table-structure.
SQL_DEFSHORT: The default-value is -32768.
SQL_MINSHORT: The minimum-value is –32768.
SQL_MAXSHORT: The maximum-value is 32767.
SQL_DEFLONG: The default-value is -2147483647.
SQL_MINLONG: The minimum-value is -2147483647.
SQL_MAXLONG: The maximum-value is 2147483647.
SQL_DEFDOUBLE: The default-value is -1.E+20.
SQL_MINDOUBLE: The minimum-value is -1.E+20.
SQL_MAXDOUBLE: The maximum-value is 1.E+20.
SQL_DEFDATE: The default-value is
‘1800-01-01’.
SQL_MINDATE: The minimum-value is
‘1800-01-01’.
SQL_MAXDATE: The maximum-value is
‘2800-12-31’.
SQL_DEFTIME: The default-value is ’00:00:01’.
SQL_MINTIME: The minimum-value is ’00:00:01’.
SQL_MAXTIME: The maximum-value is ’23:59:59’.
SQL_DEFDATI: The default-value is
‘1800-01-01-00.00.00.000000’.
SQL_MINDATI: The minimum-value is
‘1800-01-01-00.00.00.000000’.
SQL_MAXDATI: The maximum-value is
‘2800-12-31-23.59.59.000000’.
DATE_YYYYMMDD: Defines format: 20020524
DATE_DDMMYYYY: Defines format: 24.05.2002
DATE_DEFAULT: Defines format: 2002.05.24
TIME_DEFAULT: Defines format: 22.25.17
DATI_DEFAULT
Defines format: 2002.05.24.22.25.17.123456
RND_FINANCE: Defines financial rounding
RND_UP: Defines upward rounding
RND_DOWN: Defines downward rounding
MODE_30: Defines 30 days a month
MODE_30F: Defines 30 days a month, February
has 30 days at 28th or 29th
MODE_ACT: Defines month has actual number of
days
The
data-type DATE is internally represented by the structure ADATE
which is defined by:
short sYear;
unsigned char sMonth, sDay;
The
data-type TIME is internally represented by the structure ATIME
which is defined by:
unsigned char sHour, sMin, sSec ;
The
data-type TIMESTAMP is internally represented by the structure ADATI
which is defined by:
short sYear ;
unsigned char sMonth, sDay, sHour, sMin,
sSec;
long
lMicro;
The
available data-types are stored in the file “typename.dat”. This file must be either
in the current directory or in the directory defined by the environment
variable “DBDAT_PATH”.
FSurrogat STRING
[8]
FLogical LOGICAL
FChar_1 CHAR
FChar_2 STRING
[2]
FChar_3 STRING
[3]
FChar_4 STRING
[4]
FChar_5 STRING
[5]
FChar_6 STRING
[6]
FChar_7 STRING
[7]
FChar_8 STRING
[8]
FChar_10 STRING
[10]
FChar_12 STRING
[12]
FChar_15 STRING
[15]
FChar_16 STRING
[16]
FChar_19 STRING
[19]
FChar_20 STRING
[20]
FChar_21 STRING
[21]
FChar_24 STRING
[24]
FChar_25 STRING
[25]
FChar_30 STRING
[30]
FChar_32 STRING
[32]
FChar_35 STRING
[35]
FChar_40 STRING
[40]
FChar_46 STRING
[46]
FChar_55 STRING
[55]
FChar_58 STRING
[58]
FChar_60 STRING
[60]
FChar_68 STRING
[68]
FChar_80 STRING
[80]
FChar_120 STRING
[120]
FChar_132 STRING
[123]
FChar_140 STRING
[140]
FChar_146 STRING
[146]
FChar_160 STRING
[160]
FChar_254 STRING
[254]
FChar_255 STRING
[255]
FChar_4000 STRING
[4000]
FBinary_255 BINARY
[255]
FBinary BINARY
[4000]
FShort SHORT
FInt INT
FLong LONG
FAmount DOUBLE
FDouble DOUBLE
FDay SHORT
FMonth SHORT
FYear SHORT
FDate DATE
FTime TIME
FTimestamp DATI
Note: If you want to use the data-types in your
program you must add a leading ‘T’ to the data-type-name; e.g. FTime will name
TFTime. You can initialise variables by the INIT_<type-name> macro; e.g.
INIT_FDate(a). You can assign values by the COPY_<type-name> macro; e.g.
COPY_FDate(a,b). The default-value for each data-type can be named by
DEF_<type-name>; e.g. DEF_FDate.
The library
contains functions to handle error-output. If you are using the
Speedy/Speedy1-library you must not link with the msglog-library because this functionality
is already included in the Speedy/Speedy1-library.
extern
int Init_Msglog(char * filename, int kz_empty);
Initialises
the message-logging functionality. If a file-name is given the messages are
logged to this file. The file will get the extension “.log”. If the parameter
‘kz_empty’ is TRUE the log-file will be overwritten if it already exists; else
new data will be added.
Note: You can specify an absolute path
for the log-file. If you want to do so you must not use the “.log”-extension.
The extension will be added automatically.
extern
void Close_Msglog(void);
If
message-logging is directed to a file the file is closed.
extern
void Set_Msglog_Callback(void (* cb_func)(char*));
Defines a
callback-function which shall be called every time an insert into the log
happens.
extern
void Set_Msglog_Close_Callback(void (* cb_func)(char*));
Defines a
callback-function which shall be called when the Close_Msglog-function is
invoked.
extern void Log_Msg(char * fmt, ...);
Adds data
to the log. The function can be used very similar to the printf-function. The
parameter ‘fmt’ is capable of the following variables: ‘%s’, ‘%d’, ‘%f’, ‘%ld’,
‘%lf’.
extern void Msglog_Exit(int rcode);
This
function can be called to exit a program with the exit-code given by ‘rcode’.
The function calls Close_Msglog and terminates the program.
The library
contains basic-functions which help you to handle data-structures and file-io.
extern
void * mymalloc(int size);
extern
void * myrealloc(void * ptr, int size);
extern
char * mystrdup(char * strg);
extern
void myfree(void * ptr);
These functions
check “out-of-memory”-errors and exit with return-code 1 in this case.
extern
void htinit(int max, int size);
Initialises
the hash-table. The parameter ‘max’ defines the maximum number of characters to
hold the identifiers in the hash-table. The parameter ‘size’ defines the
maximum number of entries in the hash-table. The parameter must be a
prime-number (e.g.
3001,5003,10007,15013,20011,30011,50021,100003,150001,200003,250007,300017).
The function checks that the given size is a prime-number.
extern
char * idstring(int key);
Retrieves
the key-string for a given key from the hash-table. The function returns NULL
if the key is not found.
extern
int htsearch(char * key_string);
Searches
for a key-string in the hash-table. If the key is not found –1 is returned.
extern
int htinsert(char * key_string);
Inserts a
new item to the hash-table. The key for the new item is returned.
extern
int htdelete(int key);
Deletes a
key from the hash-table. If the key is not in the hash-table –1 is returned.
These
functions defines access-methods for the List-data-type. You must initialise
the list-functionality by calling ‘lsmeminit’ at program startup. Then you can
allocate List-objects by declaring them (e.g. “List ls;”). You must initialise
each List-object by calling ‘lsinit’.
extern void
lsmeminit(int max);
Initialises
the global cache memory for lists. The parameter ‘max’ defines the number of
list elements which will be allocated and managed in a cache-function
internally.
extern void
lsinit(List * ls);
Initialises
a List-object.
extern
void Make_List(List ** ls);
Generates a
new List-object on the heap. The object is automatically initialised.
extern int
lsempty(List * ls);
Returns
TRUE if the list is empty.
extern
int lsnumber(List * ls);
Returns the
number of elements in the list.
extern void
lsinsert(List * ls, void * item);
Inserts a
new item to the beginning of the list.
extern
void lssortinsert(List * ls, void * item);
Inserts a
new item at the end of the list.
extern
int lsdelete(List * ls, void * item);
Deletes the
item from the list.
extern
int lsdelfst(List * ls, void ** item);
Deletes the
first item of the list. The pointer to the first item is returned in the
parameter ‘item’.
extern
int lsfind(List * ls, void * item);
Returns
TRUE if the item is in the list.
extern
int lschange(List * list, void * old, void * new);
Changes
item ‘old’ by item ‘new’ in the list.
extern
void lsfree(List * list);
Frees all
memory allocated internally for a list.
extern
void lsfreeall(List * list);
Frees all memory
allocated internally for a list and the memory of all items.
extern
void lsunify(List * list);
Convert a
list of lists into a single list.
extern
void lsinitread(List * list);
Initialises
the read-pointer for sequential access to the list-items. The items in the list
are returned from the start to the list to the end of the list.
extern
int lsread(List * list, void ** item);
Returns the
next item from the list and sets the list-pointer to the next item in the list.
extern
int lsreadfst(List * list, void ** item);
Returns the
first item from the list into the parameter ‘item’.
extern
int lsdelread(List * list, void ** item);
Returns the
next item from the list into the parameter ‘item’ and deletes it.
extern
void lsinitsortread(List * list);
Initialises
the read-pointer for access to the list-items in their reverse sequential
order.
extern
int lssortread(List * list, void ** item);
Returns the
next item from the list and sets the list-pointer to the next item in the list
in the reverse sequential order.
extern
void lscopy(List * ls1, List * ls2);
Assigns
list ls2 to list ls1.
Note: The data items will only exists
once!
extern
void lscat(List * ls1, List * ls2);
Adds all
items from list ls2 to list ls1.
Note: The data items will only exists
once!
extern
void lssortcat(List * ls1, List * ls2);
Adds all items
from list ls2 to list ls1. The items in list ls2 will be read in the reverse
order.
Note: The data items will only exists
once!
extern
void lssort(List * ls, void * sortfunc);
Sorts all
items in the list using the sort-function given by ‘sortfunc’. The sort
function takes two item-objects as arguments. It must return –1 if the left
item is smaller than the right item, 0 if they are equal and 1 if the left item
is greater than the right item. Sorting is only possible it the list has less
than 10000 items.
extern
void lsmoveleft(List * list, void * item);
Moves the
item one item towards the beginning of the list. If it is already the first
item no moving occurs.
extern
void lsmoveright(List *, void *);
Moves the
item one item towards the end of the list. If it is already the last item no
moving occurs.
These
functions defines access-methods for the Tree-data-type. You must initialise
the list-functionality by calling ‘ltmeminit’ at program startup. Then you can
allocate Tree-objects by declaring them (e.g. “Tree lt;”). You must initialise
each Tree-object by calling ‘ltinit’.
extern
void ltmeminit(int max);
Initialises
the global cache memory for tree-objects. The parameter ‘max’ defines the
number of tree elements which will be allocated and managed in a cache-function
internally.
extern
void ltinit(Tree * tree);
Initialises
a List-object.
extern
void Make_Tree(Tree ** tree);
Generates a
new Tree-object on the heap. The object is automatically initialised.
extern
int ltempty(Tree);
Return TRUE
if the tree-object is empty.
extern
int ltnumber(Tree tree);
Return the
number of items in the tree-object.
extern
int ltsearch(Tree tree, int key, void ** item);
Searches
for the item in the tree. The item is identified by the given key. If the item
is found it is returned in the parameter ‘item’. The function returns TRUE if
the item is found; else FALSE.
extern
int ltinsert(Tree * tree, int key, void * item);
Inserts the
item with its key into the tree. If the key is already defined FALSE is
returned and no insert occurs.
extern
int ltdelete(Tree * tree, int key);
Deletes the
key from the tree. If the key does not exists FALSE is returned.
extern
int ltchange(Tree * tree, int key, void * item);
Changes the
item with the given key to the new value given in parameter ‘item’. If the key
is not found FALSE is returned.
extern
void ltfree(Tree * tree);
Frees all
internal memory of the given Tree-object.
extern
void ltfreeall(Tree * tree);
Frees all
internal memory of the given Tree-object and all memory of the referenced
items.
extern
void ltdump(Tree tree, List * list);
Dumps all
items to the list given in the parameter ‘list’. The items are sorted.
extern
void ltdumpunsort(Tree tree, List * list);
Dumps all
items unsorted to the list given in the parameter ‘list’.
extern
void ltdumpkeys(Tree tree, List * list);
Dumps all
keys to the list given in the parameter ‘list’.
extern
void ltdumpunsortkeys(Tree tree, List * list);
Dumps all
keys unsorted to the list given in the parameter ‘list’.
All functions
returns strings which are allocated on the heap. You must free the memory on
your own.
extern
char * setsuffix(char * fn, char * suffix);
Sets the
file-extension to ‘suffix’; e.g. file-name ‘test’ will get ‘test.log’ with
suffix = ‘log’.
extern
char * clearsuffix(char * fn);
Removes the
file-extension.
extern
char * getsuffix(char * fn);
Reads the
file-extension; e.g. file ‘test.log’ will return ‘log’.
extern
int filesize(char * fn);
Returns the
size of the file.
extern
int filemodified(char * fn);
Returns
TRUE if the file has been modified.
extern
int validfilename(char * fn);
Returns
TRUE if the file-name is a valid filename; i.e. filename consists only of ‘_’,
letters, digits or ‘.’.
extern
int exists_file(char * fn);
Returns
TRUE if the file exists.
extern
int del_file(char * fn);
Deletes
file defined by ‘fn’. Returns TRUE if the file has been deleted.
extern
int exists_directory(char * dirname);
Returns
TRUE if directory exists.
extern
void make_directory(char * dirname);
Creates the
directory ‘dirname’.
extern
void remove_directory(char * dirname);
Removes the
directory with all files and sub-directories in the directory.
extern List genfnlist(char * pattern);
Creates a
list of filenames and directory-names which match the given patterns; e.g.
“*.log;*.ext”.
extern
List extractfnlist(List * ls, char * pattern);
Creates a
list of filenames from a list of filenames which match the given pattern. You
can use ‘*’ for any characters or ‘$’ for a single character.
extern void sortfnlist(List * ls);
The list is
sorted ascending.
extern
List genfnpatternlist(char * path, char * pattern);
Creates a
list of filenames and directories which match the given patterns; e.g.
“*.log;*.ext”. You can specify the path to look for filenames.
extern
List genfilelist(char * path, char * pattern);
Creates a
list of filenames which includes the directory-path and match the given
patterns; e.g. “*.log;*.ext”. You can specify the path to look for filenames.
Directories are ignored.
extern
char * read_file(char * filename);
Reads the
text-file ‘filename’. You must take care to free the file-data returned.
extern
void * read_binfile(char * filename, int * fsize);
Reads the binary
file ‘filename’. The size of the file is returned in ‘fsize’. You must take
care to free the file-data returned.
extern
int write_file(char * filename, char * data);
Creates the
text-file ‘filename’ with content ‘data’. If the file already exists it is
overwritten.
extern
int write_binfile(char * filename, char * data, int size);
Creates the
binary file ‘filename’ with content ‘data’ of size given by the parameter
‘size’. If the file already exists it is overwritten.
The library
contains a rich set of functions which helps you develop Speedy/Speedy1
applications. The library-name for Speedy is “dbsys”, the library-name for
Speedy1 is “dbsys1”.
These
functions are mainly internally used by the DB-Preparator to generate the
database-access-functions. Nevertheless you can use them in your applications
to print data.
extern
int Hold_ValueStrings();
extern
int Release_ValueStrings();
These
functions are required to manage the memory used by the string functions. The
hold-function is required if you use the string manipulation functions.
Otherwise internal used memory may be reused and the result string can be
damaged. The hold-function must be always followed by a release-function-call.
extern
void Set_DigitsAfterComma(int comma);
This
function can be used to set the number of digits after the comma for FDouble-
and FAmount-data-types.
extern
char * Make_ValueString(char *strg, int size);
extern
char * Make_DbValueString(char *strg, int size);
extern
char * Make_String(char * strg);
extern
char * Make_BinaryString(char * strg, int size);
extern
char * Make_TimeString(ATIME * time);
extern
char * Make_DateString(ADATE * dat);
extern
char * Make_DatiString(ADATI * dati);
extern
char * Make_FETimeString(ATIME * time);
extern
char * Make_FEDateString(ADATE * dat);
extern
char * Make_FETimestampString(ADATI * dati);
extern char
* Make_CharString(char ch);
extern
char * Make_LogicalString(char ch);
extern
char * Make_AmountString(double btrg);
extern
char * Make_ShortString(short int sval);
extern
char * Make_LongString(long int lval);
extern
char * Make_DoubleString(double dval);
extern
char * Make_DoubleIntString(double dval);
extern
char * Make_Reduce_String(char * strg);
extern
char * Make_Reduce_NumString(char * strg);
extern
char * Make_Reduce_HTML_String(char * strg);
extern
char * Make_Reduce_HTML_NumString(char * strg);
extern
char * Make_Reduce_HTML_Leading_Zeros(char * strg);
extern
char * Make_HTML_DateString(ADATE * dat);
extern
char * Make_HTML_TimestampString(ADATI * dati);
extern
char Make_CharValue(char ch);
These
functions are used to generate string-representations for data-types. The
FE-functions do not show the default-values but an empty string. The
HTML-functions generate html-code. Please see the code generated by
DB-Preparator as examples for the usage of these functions.
Note: The default-number of digits after
the comma is 2 for FAmount and 6 for FDouble; the digits are only shown if they
are required.
extern
void Free_ValueStrings();
This
function is required to free all internal memory which has been allocated for
the generation of strings.
extern
char * Reduce_String(char * strg);
extern
char * Reduce_NumString(char * strg);
extern
char * Reduce_Leading_Zeros(char * strg);
extern
char * Reduce_HTML_String(char * strg);
extern char
* Reduce_HTML_NumString(char * strg);
extern
char * Reduce_HTML_Leading_Zeros(char * strg);
The main
difference to the Make_<*>-functions is that these functions do allocate
the result string. The user must free them on his own.
The
fillup-function can be used to add spaces at the end of a string if the string
is smaller than ‘size’. The
reduce-functions helps to skip characters which shall not be displayed; e.g.
‘Reduce_String’ skips trailing spaces, ‘Reduce_NumString’ skips trailing zeros.
extern
void Make_SearchString(char * strg);
This
function replaces all ‘*’ by ‘%’ to make search strings appropriate for
SQL-queries.
extern
void Make_SearchString_Size(char * strg, int size);
This
function replaces all ‘*’ by ‘%’ to make search strings appropriate for
SQL-queries. If there is enough space a ‘%’ will be added at the end of the
string.
extern
int Is_EmptyString(const char * strg);
This
function returns TRUE if the string is empty or only contains space-characters
(note: space-characters are detected by the isspace-function of the C-library);
else FALSE is returned.
These
functions use global memory to save database-table-structures. The number of
tables which can be saved is limited by 50. The number of items stored by table is limited by 1000. So
you should only cache tables which are often accessed but rather small.
extern
void CACHE_Add(void * pDBHANDLE, void * ptr);
This
function adds the database-structure to the cache. The cache is searched using
the logical key of the table specified by table-number given in the
database-structure-field ‘_iTablenr’.
extern
void * CACHE_GetPk(void * pDBHANDLE, int tablenr, void * ptr);
This
function checks if the database-structure is already in the cache. The cache is
searched using the primary key of the table specified by ‘tablenr’.
extern
void * CACHE_GetLk(void * pDBHANDLE, void * ptr);
This
function checks if the database-structure is already in the cache. The cache is
searched using the logical key of the table specified by table-number given in
the database-structure-field ‘_iTablenr’.
extern
int Directory_Empty(char * dir);
This
function returns TRUE if the directory given by ‘dir’ is empty; else FALSE.
extern
int File_Exists(char * filename);
This
function returns TRUE if the file given by ‘filename’ exists; else FALSE.
extern
int File_Delete(char * filename);
This function
deletes the file defined by ‘filename’. TRUE is returned if the file could
successfully be deleted; else FALSE is returned.
extern
FILE * File_Read_Open(char * fn);
extern
FILE * File_Write_Open(char * fn);
extern
FILE * File_Append_Open(char * fn);
These
functions open a file-descriptor for reading, writing or appending. The file
descriptor is returned on success; NULL is returned on failure.
extern
int File_Close(FILE * fp);
This function
closes an open file descriptor.
extern
int File_Write(FILE * fp, char * strg);
This
function writes to the file-descriptor the string given by ‘strg’. Hence the
function is only useful for text-files.
extern
int File_Contents(char * filename, char * data);
This
function creates or changes a text-file given by ‘filename’ to the string given
by ‘data’. The function is only useful for text-files.
extern
int File_Add_Contents(char * filename, char * data);
This
function adds the string given by ‘data’ to the text-file given by ‘filename’.
Hence the function is only useful for text-files.
extern
char * File_Get_Contents(char * filename);
This
function reads the data of the file given by ‘filename’ and returns the data as
string. Hence it is only useful for text-files. You must free the string after
usage.
extern
void randinit(int freq);
A call to
this function initialises the random number generator by using the microseconds
value of the internal timer. In addition a frequency can be specified at which the random number
generator is reinitialised. If the frequency is 0 no re-initialisation occurs.
If the frequency is negative a default-value (40) is used.
extern int irand(int min, int max);
This
function returns a random integer number in the range between ‘min’ and ‘max’
(the minimum and maximum values are included). Although the simple random number
generator function rand() is used, the results should be quite good.
extern
double drand();
This
function returns a random number in the range between 0.0 and 1.0.
These
functions defines virtual time.
Note: If a parameter requires a
time-definition you can use TFTime or ATIME as parameter. If a parameter
requires a date-definition you can use TFDate or ATIME as parameter. If a
parameter requires a time-stamp-definition you can use TFTimestamp or ADATI as
parameter.
extern
void DATE_Set(void *);
Sets the
virtual date.
extern
void DATE_Clear();
Inactivates
the virtual date.
extern
void TIME_Set(void *);
Sets the
virtual time.
extern void
TIME_Clear();
Inactivates
the virtual time.
extern
void Set_AktDateTime(void * date, void * time);
Sets the
virtual date and time.
extern
void Set_AktTimestamp(void * dati);
Sets the
virtual date and accurate time.
extern
void TIME_Now(void * time);
Gets the
current time. If virtual time is active this function returns the virtual time.
You can use FTime or ATIME as parameter.
extern
void DATE_Now(void * date);
Gets the current
date. If virtual time is active this function returns the virtual date.
extern void DATI_Now(void * dati);
Gets the
current date and accurate time. If virtual time is active this function returns
the virtual time-stamp.
extern
void Get_Timestamp(TFTimestamp *timestamp);
This
function returns the current time-stamp. If virtual time is active the current
time-stamp is virtual.
Note: If you want accurate timing you
must use the Get_SysTimestamp-function (yet it provides not virtual time; see
section “Other Functions”).
extern
void DATE_Copy(void * date1, void * date2);
This
function assigns date2 to date1.
extern
int DATE_IsDefault(void * date);
This
function returns TRUE if date is default.
extern
int DATE_IsValid(void * date);
This
function returns TRUE if date is valid.
extern
int DATE_Compare(void * date1, void * date2);
This
function returns –1 if date1 is smaller than date2, 0 if date1 is equal date2
and 1 if date 1 is greater than date2.
extern
int DATE_ToString(void * date, char * string, DateType);
This
function converts date to a string using the defined DateType.
extern
int DATE_FromString(void * date, char * string, DateType);
This
function reads a date from a string using the defined DateType.
extern
int DATE_DayNumber(void * date);
The actual
number of the day in the year for the given date.
extern void
DATE_AddDays(void * date, int days);
Adds the
given number of days to the given date.
extern
void DATE_AddMonths(void * date, int months);
Adds given
number of months to the given date.
extern
int DATE_MonthDays(void * date);
Returns the
days of the month specified by the date.
extern
void DATE_GetUltimo(void * date);
Returns the
last day in the month specified by the date.
extern
int DATE_LeapYear(void * date);
Returns
TRUE if the year specified by date is a leap-year (i.e. it includes the 29th
of February).
extern
int DATE_AddMonths_Ultimo (ADATE * date, short months);
Adds months
to the given date. If the start date is the last day in the month the end date
will also be the ultimo of this month.
extern
int DATE_Diff_LeapDays (ADATE * date1, ADATE * date2);
Number of
leap days within the given time period between date1 and date2.
extern
int DATE_Diff(void * date1, void * date2);
Returns the
number of days between date1 and date2.
extern int
DATE_Diff_Mode(void * date1, void * date2, ModeType mode);
Returns the
number of days between date1 and date2 using ModeType.
extern void
TIME_Copy(void * time1, void * time2);
Assigns
time2 to time1.
extern
int TIME_IsValid(void * time);
Returns
TRUE if time is valid.
extern
int TIME_IsValidString(void * string);
Returns
TRUE if string is a valid time-string.
extern
int TIME_Compare(void * time1, void * time2);
Returns –1
if time1 is smaller than time2, 0 if time1 is equal time2 and 1 if time1 is
greater than time2.
extern
int TIME_FromString(void * time, char * string);
Gets time
from the given time-string.
extern int DATI_IsValid(void * dati);
Returns TRUE if dati is a valid time-stamp (ADATI or
TFTimestamp).
extern int DATI_IsValidString(void * string);
Returns TRUE if string is a valid time-stamp-string.
extern int DATI_Compare(void * dati1, void * dati2);
Returns –1
if dati1 is smaller than dati2, 0 if dati1 is equal dati2 and 1 if dati1 is
greater than dati2.
extern int DATI_FromString(void * dati, char *
string);
Gets dati
from the given time-stamp-string.
extern int DATI_ToString(void * dati, char * string,
DatiType);
Generates a
string from the given time-stamp ‘dati’ using DatiType-format.
extern int DATI_Diff(void * dati1, void * dati2,
double * time);
Returns the time-duration between dati1 and dati2 in
seconds as double-value with fractions.
See the
Store/Store1-application for using the binary large objects with the
Speedy/Speedy1-database.
extern
int TBL_Id (void * ptable);
This
function returns the database-structure-field ‘_iTable’.
extern void COMPR_Init (COMPR * compr, int size, int cprow_min, int cprow_more, int cprow_write_min, int cprow_write_more);
Initialises
the COMPR-functions. If cprow_min/cprow_more = -1 the default values
10000/1000000. If cprow_write_min/cprow_write_more = -1 the default values
10000/100000.
extern
void COMPR_fnInit (COMPR * compr, void * fnInit);
Assigns the
database-structure init-function (i.e. <TABLE>_Init).
extern
void COMPR_FmtBinFix (COMPR * compr);
Defines
binary format.
extern
void COMPR_FmtCompVar (COMPR * compr);
Defines
compressed binary format.
extern
void COMPR_Free (COMPR * compr);
Frees
internal used memory. Should be called as the last function when using the
COMPR-functions.
extern
void COMPR_Reset (COMPR * compr);
Resets the
read-index for the data in the COMPR-buffer.
extern
void COMPR_AddBin (COMPR * compr, void * abin);
Adds data
from the abin-buffer to the COMPR-buffer.
extern
int COMPR_GetBin (COMPR * compr, void * abin);
Reads data
from the COMPR-buffer to the abin-buffer. If the function returns FALSE no more
data is available.
extern
int COMPR_Write (COMPR * compr, void * abin);
Adds data
defined by ‘abin’-pointer to the COMPR-buffer. The data can be a structure or a
multiple.
extern
int COMPR_Read (COMPR * compr, void * abin);
Reads the
next item from the COMPR-buffer. The data item can be a single or a multiple.
extern
short COMPR_GetId (const COMPR * compr);
Determines
the type-id (structure-number) of the next item that will be read. This
function can be used to check what structure will be read next by the
COMPR_Read function. You can use COMPR_SkipRead to skip the structure.
extern
void COMPR_Set_Length (COMPR * compr,
int size);
Redefines
the length of the structure-items.
extern
int COMPR_SkipRead (COMPR * compr);
Skips the
next structure-item.
extern
int TABLE_File_Save(DBHANDLE * pDBHANDLE, FILE * ofp, char * pDefinition, char
* pTable,
void
* TABLE_Select, void * TABLE_Fetch);
This
function saves the database-table (defined by the pDefinition, TABLE_Init and
TABLE_Insert parameters) to the file specified by the file-descriptor ‘ofp’.
Note: You can get the table-definition by
the function <TABLE>_Definition generated by DB-Preparator.
extern int
TABLE_File_Load(DBHANDLE * pDBHANDLE, FILE * ifp, char * pDefinition,
void
* TABLE_Init, void * TABLE_Insert);
This
function loads the database-table (defined by the pDefinition, TABLE_Init and
TABLE_Insert parameters) from the file specified by the file-descriptor ‘ifp’.
Note: You can get the table-definition by
the function <TABLE>_Definition generated by DB-Preparator.
extern
int TABLE_File_Skip(FILE * ifp, char * pDefinition);
This
function skips the database-table (defined by the pDefinition) from loading.
You may want to use this function if a table has been deleted.
Note: You can get the table-definition by
the function <TABLE>_Definition generated by DB-Preparator.
extern
int Get_TABLE_Attrib_Type(char * pDefinition, int idx, int * size);
Returns the
type of the column idx in the table defined by the parameter pDefinition. The
size of the data-attribute is returned in the parameter ‘size’.
Note: You can get the table-definition by
the function <TABLE>_Definition generated by DB-Preparator.
extern
char * Get_TABLE_Attrib_Value(char * pDefinition, int idx, char * info);
Returns the
value of the column idx in the table-row given by info using the
table-definition defined by the parameter pDefinition.
Note: You can get the table-definition by
the function <TABLE>_Definition generated by DB-Preparator.
extern int Set_TABLE_Attrib_Value(char * pDefinition, int idx, char * info, char * data);
Sets the
value of the column idx to ‘data’ in the table-row given by info using the
table-definition defined by the parameter pDefinition.
Note: You can get the table-definition by
the function <TABLE>_Definition generated by DB-Preparator.
extern
int DATA_CmpDouble (double arg1, double arg2, double accuracy);
Compares
arg1 and arg2 using accuracy.
extern
void DATA_RndDouble (double * arg1, double base, RndType);
Rounds arg1
by base using the given rounding convention in RndType.
extern void
ARGV_GetDB_Name(char ** argv, int argc, char * dbname);
Scans the
program-arguments for the database-name. You must initialise the parameter
dbname to ‘-‘ if you do not want the function to use the default-value ‘sdsys’
if no database-name is given by the command-line option ‘-db’.
extern
void DB_Print_Error_String(void);
This
function prints error-messages generated by the last database-access.
extern
void DB_Set_Error_Log(void);
Defines
that the errors shall be directly logged to the log-file of the database.
extern
void DB_Set_Error_String(void);
Defines
that the errors shall be stored in the error-string. You can use the
DB_Print_Error_String to output the error-message.
extern
int DBHANDLE_Init(DBHANDLE **pDBHANDLE, char * dbname);
Initialises
the test environment library and connects the system to the database with name
‘dbname’.
extern
void DBHANDLE_Free(DBHANDLE *pDBHANDLE);
Frees all
memory allocated by the test environment library and disconnects from the
database.
extern
const char * Get_DBname(DBHANDLE * pDBHANDLE);
Returns the
database-name.
extern
int DB_Exists_Table(DBHANDLE *pDBHANDLE, char * tablename);
Returns
TRUE if the table defined by tablename exists.
extern
int DB_Create_Table(DBHANDLE *pDBHANDLE, char * sql);
Returns
TRUE if the table could be created by the SQL-command given by sql.
extern int
DB_Drop_Table(DBHANDLE *pDBHANDLE, char * tablename);
Returns
TRUE if the table defined by tablename could be dropped.
extern
int DB_Exists_Index(DBHANDLE *pDBHANDLE, char * indexname);
Returns
TRUE if the index defined by indexname exists.
extern
int DB_Create_Index(DBHANDLE *pDBHANDLE, char * sql);
Returns
TRUE if the index could be created by the SQL-command given by sql.
extern
int DB_Drop_Index(DBHANDLE *pDBHANDLE, char * indexname);
Returns
TRUE if the index defined by indexname could be dropped.
extern
int DB_Begin(DBHANDLE *pDBHANDLE);
This
function opens a database-transaction. You must use DB_Commit or DB_Rollback
for every DB_Begin to close the transaction.
Note: To perform a cursor-select you must
open a transaction.
extern
int DB_Commit(DBHANDLE *pDBHANDLE);
This
function successfully closes a transaction. All database-changes are conserved.
extern
int DB_RollBack(DBHANDLE *pDBHANDLE);
This
function closes a transaction not successfully. All database-changes are
undone.
extern
int DB_Exec_SQL(DBHANDLE *pDBHANDLE, char * sql, int * cnt, int print);
This
function executes SQL-commands. The parameter ‘cnt’ returns the number of
affected rows. If the parameter ‘print’ is TRUE the results are printed.
These
functions are used to handle multiples. All database-table-structures are
generated to have multiple-definitions. Hence you can use data-types
M<TABLE> for each database-table existing.
extern
ARRAY * ARRAY_New(void);
This
function creates a multiple and initialises it.
extern
ARRAY * ARRAY_Init(ARRAY *arr);
This
function initialises an existing array.
extern ARRAY
* ARRAY_Assign(ARRAY * arr1, ARRAY * arr2);
Assigns
arr2 to arr1. The data-items are copied.
extern
void ARRAY_Free(ARRAY *arr);
Frees the
memory hold by the elements in the array ‘arr’ and of the array.
extern
void * ARRAY_GetPtr(const ARRAY *arr, int idx);
Gets a
pointer to the item with index idx in the array arr.
extern
void ARRAY_Remove(ARRAY *arr, int idx);
Removes
item idx from array arr.
extern
void ARRAY_Add(ARRAY *arr, void * info);
Adds an item
info to array arr.
extern
void ARRAY_Sort(ARRAY *arr);
Sorts the
elements in the array arr. The items in the array must be structures which have
assigned a compare-function.
extern
void ARRAY_AddArray(ARRAY *arr1, ARRAY *arr2);
Adds an
array arr2 to the existing array arr1.
extern
void Get_SysTimestamp(TFTimestamp *timestamp);
This
function returns accurate timing (microseconds). No virtual timing is applied.
You can use this function for performance measurement.
extern
void Make_Surrogat(TFSurrogat *surr);
Generates a
random surrogate which can be tried as a primary key.
extern
void DATA_GetNumber(DBHANDLE * pDBHANDLE, long * num, int len);
Generates a
random number ‘num’ of length ‘len’.
extern
void DATA_Assign(void *lptr, int ltyp, void *rptr, int rtyp);
Assigns
value ‘rptr’ of type ‘rtyp’ to value ‘lptr’ of type ‘ltyp’. Types can be
TYP_LOGICAL, TYP_CHAR, TYP_STRING, TYP_DATI, TYP_DATE, TYP_TIME, TYP_SHORT,
TYP_INT, TYP_LONG, TYP_DOUBLE.
Note: This function is required by the
database-access-functions which are automatically generated by the
DB-Preparator.
extern
int DATA_Compare(void *lptr, int ltyp, void *rptr, int rtyp);
Compares
value ‘rptr’ of type ‘rtyp’ to value ‘lptr’ of type ‘ltyp’. Types can be
TYP_LOGICAL, TYP_CHAR, TYP_STRING, TYP_DATI, TYP_DATE, TYP_TIME, TYP_SHORT,
TYP_INT, TYP_LONG, TYP_DOUBLE.
The
function returns –1 if lptr is smaller than rptr, 0 if they are equal and 1 if
lptr is greater than rptr.
extern void
STRUCT_Assign(void *lptr, void *rptr);
extern
int DATA_Add(int size, char * bdata, int bsize, char * data, int max, char **
pdata, int * pmax,
int data_min, int data_more, void * malloc_func(), void * realloc_func());
Adds data
to a buffer; first stack memory (data) is used if available, i.e. max != -1;
then dynamic data is used (pdata);
pmax
defines size of dynamic data; if more memory is required data_min/more defines
the allocated size of the memory; malloc/realloc-functions can be given (if
they are not given malloc/realloc are used).
extern
int match_search_strg(char * strg, char * search_strg);
This function returns TRUE is the search-string
‘search_strg’ is included in given string ‘strg’. The character ‘*’ can be used
to define arbitrary data in the search-string.
extern
int Matching_String(char * line, char * str1);
Returns TRUE
if the search-string ‘str1’ is found in string ‘line’. The
character ‘*’ can be used to define arbitrary data in the search-string.
extern
int Find_String(char * line, char * str1);
Returns the
index where the search-string ‘str1’ is found in string ‘line’. The
character ‘*’ can be used to define arbitrary data in the search-string. If the
search-string is not found –1 is returned.
extern
int String_Replace(char * line, char * str1, char * str2);
Replaces
string ‘str1’ by string ‘str2’ in string ‘line’. The
character ‘*’ can be used to define arbitrary data in the search-string. If the
search-string is not found –1 is returned.
extern
int Plain_String_Replace(char * line, char * str1, char * str2);
Replaces
string ‘str1’ by string ‘str2’ in string ‘line’. The
character ‘*’ is not used to define arbitrary data but is taken literally. If
the search-string is not found –1 is returned.
Three
examples are provided in the Speedy- and Speedy1-distribution. The source-codes
of the three examples are the same. Using the #define SPEEDY1 shows the small
differences which are required to develop for Speedy vs. development for
Speedy1.
The three
examples are:
DBTest (Speedy)/DBTest1 (Speedy1): A simple
application which shows you how to connect to the database and how to use
transactions. Automatic comparison of table-rows is also demonstrated.
Phone (Speedy)/Phone1 (Speedy1): A small application which handles phone
numbers and some other information.
Store (Speedy)/Store1 (Speedy1): An
application for storing arbitrary data in Speedy/Speedy1-databases. It shows
how you can use the test-environment library for managing binary large objects
in compressed and uncompressed manner.