Copyright © 2001, 2002 Harald Wabnig

email: wabnig@testready.net    

homepage: www.testready.net  

 

 

Test Environment Programmer Documentation

 

Test Environment Programmer Documentation. 1

Introduction. 5

Installation. 5

Special Installation under Windows. 5

General Configurations for Development under Microsoft Visual-C++ 6.0 and Windows ME. 5

Special Installation under Linux. 6

Library-Constants. 6

SQL-Codes. 6

Ranges of Data-Types. 7

SMALLINT/FShort: 7

INTEGER/FLong: 7

FLOAT/FDouble/FAmount: 7

DATE/FDate: 7

TIME/FTime: 7

TIMESTAMP/FTimestamp: 7

Enumerates. 7

DateType: 7

TimeType: 7

DatiType: 7

RndType: 7

ModeType: 8

Library-Datatypes. 8

C-Representation of Data-Types DATE, TIME and TIMESTAMP. 8

Data-Types for Database-Structure-Definition. 8

Msglog-Library-Functions. 9

Init_Msglog: 9

Close_Msglog: 9

Set_Msglog_Callback: 9

Set_Msglog_Close_Callback: 10

Log_Msg: 10

Msglog_Exit: 10

Basis-Library-Functions. 10

Memory-Handling. 10

mymalloc, myrealloc, myfree, mystrdup: 10

Hash-Tables. 10

htinit: 10

idstring: 10

htinsert: 10

htinsert: 10

htinsert: 11

Lists. 11

lsmeminit: 11

lsinit: 11

Make_List: 11

lsempty: 11

lsnumber: 11

lsinsert: 11

lssortinsert: 11

lsdelete: 11

lsdelfst: 11

lsfind: 11

lschange: 12

lsfree: 12

lsfreeall: 12

lsunify: 12

lsinitread: 12

lsinitread: 12

lsreadfst: 12

lsdelread: 12

lsinitsortread: 12

lssortread: 12

lscopy: 12

lscat: 12

lssortcat: 13

lssort: 13

lsmoveleft: 13

lsmoveright: 13

Trees. 13

ltmeminit: 13

ltinit: 13

Make_Tree: 13

ltempty: 13

ltnumber: 13

ltsearch: 13

ltinsert: 14

ltdelete: 14

ltchange: 14

ltfree: 14

ltfreeall: 14

ltdump: 14

ltdumpunsort: 14

ltdumpkeys: 14

ltdumpsortkeys: 14

Functions for Handling File-Extensions. 14

setsuffix: 14

clearsuffix: 14

getsuffix: 15

Functions for Handling Files. 15

filesize: 15

filemodified: 15

validfilename: 15

exists_file: 15

del_file: 15

Functions for Handling Directories. 15

exists_directory: 15

make_directory: 15

remove_directory: 15

genfnlist: 15

extractfnlist: 15

sortfnlist: 16

genfnpatternlist: 16

genfilelist: 16

Functions for Reading/Writing Files. 16

read_file: 16

read_binfile: 16

write_file: 16

write_binfile: 16

Test-Environment-Library-Functions. 16

String Manipulation Functions. 16

Hold_ValueStrings / Release_ValueStrings: 16

Set_DigitsAfterComma: 17

Make_<Type>String: 17

Free_ValueStrings: 17

Fillup_String/Reduce_<*>String: 17

Make_SearchString: 18

Make_SearchString_Size: 18

Make_SearchString_Size: 18

Functions for Caching. 18

CACHE_Add: 18

CACHE_GetPk: 18

CACHE_GetLk: 18

Functions for File-IO.. 18

Directory_Empty: 18

File_Exists: 18

File_Delete: 18

File_Read_Open / File_Write_Open / File_Append_Open: 18

File_Close: 19

File_Write: 19

File_Contents: 19

File_Add_Contents: 19

File_Get_Contents: 19

Functions for Random Number Generation. 19

randinit: 19

irand: 19

drand: 19

Functions for Handling Virtual Time. 19

DATE_Set: 20

DATE_Clear: 20

TIME_Set: 20

TIME_Clear: 20

Set_AktDateTime: 20

Set_AktDateTime: 20

TIME_Now: 20

DATE_Now: 20

DATI_Now: 20

Get_Timestamp: 20

Functions for Handling Data-Type DATE. 20

DATE_Copy: 20

DATE_IsDefault: 21

DATE_IsDefault: 21

DATE_Compare: 21

DATE_Compare: 21

DATE_FromString: 21

DATE_DayNumber: 21

DATE_AddDays: 21

DATE_AddMonths: 21

DATE_MonthDays: 21

DATE_GetUltimo: 21

DATE_LeapYear: 21

DATE_AddMonths_Ultimo: 21

DATE_LeapDays: 22

DATE_Diff: 22

DATE_Diff_Mode: 22

Functions for Handling Data-Type TIME. 22

TIME_Copy: 22

TIME_IsValid: 22

TIME_IsValidString: 22

TIME_Compare: 22

TIME_FromString: 22

Functions for Handling Data-Type TIMESTAMP. 22

DATI_IsValid: 22

DATI_IsValidString: 22

DATI_Compare: 22

DATI_FromString: 23

DATI_ToString: 23

DATI_Diff: 23

Functions for Handling Binary Large Objects. 23

TBL_Id: 23

COMPR_Init: 23

COMPR_fnInit: 23

COMPR_FmtBinFix: 23

COMPR_FmtCompVar: 23

COMPR_Free: 23

COMPR_Reset: 23

COMPR_AddBin: 23

COMPR_GetBin: 24

COMPR_Write: 24

COMPR_Read: 24

COMPR_GetId: 24

COMPR_Set_Length: 24

COMPR_SkipRead: 24

Functions for Storing/Loading Databases. 24

TABLE_File_Save: 24

TABLE_File_Load: 24

TABLE_File_Skip: 24

Functions for Analysing and Changing Database-Rows. 25

Get_TABLE_Attrib_Type: 25

Get_TABLE_Attrib_Value: 25

Set_TABLE_Attrib_Value: 25

Functions for Comparing and Rounding Double Values. 25

DATA_CmpDouble: 25

DATA_RndDouble: 25

Functions for Accessing the Database. 25

ARGV_GetDB_Name: 25

DB_Print_Error_String: 25

DB_Set_Error_Log: 25

DB_Set_Error_String: 25

DBHANDLE_Init: 26

DBHANDLE_Free: 26

Get_DBname: 26

DB_Exists_Table: 26

DB_Create_Table: 26

DB_Drop_Table: 26

DB_Exists_Index: 26

DB_Create_Index: 26

DB_Drop_Index: 26

DB_Begin: 26

DB_Commit: 26

DB_RollBack: 26

DB_Exec_SQL: 27

Functions for Handling Arrays. 27

ARRAY_New: 27

ARRAY_Init: 27

ARRAY_Assign: 27

ARRAY_Free: 27

ARRAY_GetPtr: 27

ARRAY_Remove: 27

ARRAY_Add: 27

ARRAY_Sort: 27

ARRAY_AddArray: 27

Other Functions. 27

Get_SysTimestamp: 27

Make_Surrogat: 28

DATA_GetNumber: 28

DATA_Assign: 28

DATA_Compare: 28

DATA_Add: 28

match_search_strg: 28

Matching_String: 28

Find_String: 28

String_Replace: 28

Plain_String_Replace: 29

Examples. 29

 

Introduction

 

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.

Installation

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.

Special Installation under Windows

General Configurations for Development under Microsoft Visual-C++ 6.0 and Windows ME

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”.

 

Special Installation under Linux

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>”.

Library-Constants

In this section you find library constants.

SQL-Codes

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.

Ranges of Data-Types

SMALLINT/FShort:

*  SQL_DEFSHORT: The default-value is -32768.

*  SQL_MINSHORT: The minimum-value is –32768.

*  SQL_MAXSHORT: The maximum-value is 32767.

INTEGER/FLong:

*  SQL_DEFLONG: The default-value is -2147483647.

*  SQL_MINLONG: The minimum-value is -2147483647.

*  SQL_MAXLONG: The maximum-value is 2147483647.

FLOAT/FDouble/FAmount:

*  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.

DATE/FDate:

*  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’.

TIME/FTime:

*  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’.

TIMESTAMP/FTimestamp:

*  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’.

Enumerates

DateType:

*  DATE_YYYYMMDD: Defines format: 20020524

*  DATE_DDMMYYYY: Defines format: 24.05.2002

*  DATE_DEFAULT: Defines format: 2002.05.24

TimeType:

*  TIME_DEFAULT: Defines format: 22.25.17

DatiType:

*  DATI_DEFAULT Defines format: 2002.05.24.22.25.17.123456

RndType:

*  RND_FINANCE: Defines financial rounding

*  RND_UP: Defines upward rounding

*  RND_DOWN: Defines downward rounding

ModeType:

*  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

Library-Datatypes

C-Representation of Data-Types DATE, TIME and TIMESTAMP

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;

Data-Types for Database-Structure-Definition

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.

Msglog-Library-Functions

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.

Init_Msglog:

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.

Close_Msglog:

extern void Close_Msglog(void);

If message-logging is directed to a file the file is closed.

Set_Msglog_Callback:

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.

Set_Msglog_Close_Callback:

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.

Log_Msg:

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’.

Msglog_Exit:

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.

Basis-Library-Functions

The library contains basic-functions which help you to handle data-structures and file-io.

Memory-Handling

mymalloc, myrealloc, myfree, mystrdup:

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.

Hash-Tables

htinit:

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.

idstring:

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.

htinsert:

extern int htsearch(char * key_string);

Searches for a key-string in the hash-table. If the key is not found –1 is returned.

htinsert:

extern int htinsert(char * key_string);

Inserts a new item to the hash-table. The key for the new item is returned.

htinsert:

extern int htdelete(int key);

Deletes a key from the hash-table. If the key is not in the hash-table –1 is returned.

Lists

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’.

lsmeminit:

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.

lsinit:

extern void lsinit(List * ls);

Initialises a List-object.

Make_List:

extern void Make_List(List ** ls);

Generates a new List-object on the heap. The object is automatically initialised.

lsempty:

extern int lsempty(List * ls);

Returns TRUE if the list is empty.

lsnumber:

extern int lsnumber(List * ls);

Returns the number of elements in the list.

lsinsert:

extern void lsinsert(List * ls, void * item);

Inserts a new item to the beginning of the list.

lssortinsert:

extern void lssortinsert(List * ls, void * item);

Inserts a new item at the end of the list.

lsdelete:

extern int lsdelete(List * ls, void * item);

Deletes the item from the list.

lsdelfst:

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’.

lsfind:

extern int lsfind(List * ls, void * item);

Returns TRUE if the item is in the list.

lschange:

extern int lschange(List * list, void * old, void * new);

Changes item ‘old’ by item ‘new’ in the list.

lsfree:

extern void lsfree(List * list);

Frees all memory allocated internally for a list.

lsfreeall:

extern void lsfreeall(List * list);

Frees all memory allocated internally for a list and the memory of all items.

lsunify:

extern void lsunify(List * list);

Convert a list of lists into a single list.

lsinitread:

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.

lsinitread:

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.

lsreadfst:

extern int lsreadfst(List * list, void ** item);

Returns the first item from the list into the parameter ‘item’.

lsdelread:

extern int lsdelread(List * list, void ** item);

Returns the next item from the list into the parameter ‘item’ and deletes it.

lsinitsortread:

extern void lsinitsortread(List * list);

Initialises the read-pointer for access to the list-items in their reverse sequential order.

lssortread:

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.

lscopy:

extern void lscopy(List * ls1, List * ls2);

Assigns list ls2 to list ls1.

Note: The data items will only exists once!

lscat:

extern void lscat(List * ls1, List * ls2);

Adds all items from list ls2 to list ls1.

Note: The data items will only exists once!

lssortcat:

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!

lssort:

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.

lsmoveleft:

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.

lsmoveright:

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.

Trees

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’.

ltmeminit:

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.

ltinit:

extern void ltinit(Tree * tree);

Initialises a List-object.

Make_Tree:

extern void Make_Tree(Tree ** tree);

Generates a new Tree-object on the heap. The object is automatically initialised.

ltempty:

extern int ltempty(Tree);

Return TRUE if the tree-object is empty.

ltnumber:

extern int ltnumber(Tree tree);

Return the number of items in the tree-object.

ltsearch:

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.

ltinsert:

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.

ltdelete:

extern int ltdelete(Tree * tree, int key);

Deletes the key from the tree. If the key does not exists FALSE is returned.

ltchange:

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.

ltfree:

extern void ltfree(Tree * tree);

Frees all internal memory of the given Tree-object.

ltfreeall:

extern void ltfreeall(Tree * tree);

Frees all internal memory of the given Tree-object and all memory of the referenced items.

ltdump:

extern void ltdump(Tree tree, List * list);

Dumps all items to the list given in the parameter ‘list’. The items are sorted.

ltdumpunsort:

extern void ltdumpunsort(Tree tree, List * list);

Dumps all items unsorted to the list given in the parameter ‘list’.

ltdumpkeys:

extern void ltdumpkeys(Tree tree, List * list);

Dumps all keys to the list given in the parameter ‘list’.

ltdumpsortkeys:

extern void ltdumpunsortkeys(Tree tree, List * list);

Dumps all keys unsorted to the list given in the parameter ‘list’.

Functions for Handling File-Extensions

All functions returns strings which are allocated on the heap. You must free the memory on your own.

setsuffix:

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’.

clearsuffix:

extern char * clearsuffix(char * fn);

Removes the file-extension.

getsuffix:

extern char * getsuffix(char * fn);

Reads the file-extension; e.g. file ‘test.log’ will return ‘log’.

Functions for Handling Files

filesize:

extern int filesize(char * fn);

Returns the size of the file.

filemodified:

extern int filemodified(char * fn);

Returns TRUE if the file has been modified.

validfilename:

extern int validfilename(char * fn);

Returns TRUE if the file-name is a valid filename; i.e. filename consists only of ‘_’, letters, digits or ‘.’.

exists_file:

extern int exists_file(char * fn);

Returns TRUE if the file exists.

del_file:

extern int del_file(char * fn);

Deletes file defined by ‘fn’. Returns TRUE if the file has been deleted.

Functions for Handling Directories

exists_directory:

extern int exists_directory(char * dirname);

Returns TRUE if directory exists.

make_directory:

extern void make_directory(char * dirname);

Creates the directory ‘dirname’.

remove_directory:

extern void remove_directory(char * dirname);

Removes the directory with all files and sub-directories in the directory.

genfnlist:

extern List genfnlist(char * pattern);

Creates a list of filenames and directory-names which match the given patterns; e.g. “*.log;*.ext”.

extractfnlist:

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.

sortfnlist:

extern void sortfnlist(List * ls);

The list is sorted ascending.

genfnpatternlist:

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.

genfilelist:

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.

Functions for Reading/Writing Files

read_file:

extern char * read_file(char * filename);

Reads the text-file ‘filename’. You must take care to free the file-data returned.

read_binfile:

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.

write_file:

extern int write_file(char * filename, char * data);

Creates the text-file ‘filename’ with content ‘data’. If the file already exists it is overwritten.

write_binfile:

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.

Test-Environment-Library-Functions

 

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”.

String Manipulation Functions

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.

Hold_ValueStrings / Release_ValueStrings:

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.

Set_DigitsAfterComma:

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.

Make_<Type>String:

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.

Free_ValueStrings:

extern void Free_ValueStrings();

This function is required to free all internal memory which has been allocated for the generation of strings.

Fillup_String/Reduce_<*>String:

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.

Make_SearchString:

extern void Make_SearchString(char * strg);

This function replaces all ‘*’ by ‘%’ to make search strings appropriate for SQL-queries.

Make_SearchString_Size:

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.

Make_SearchString_Size:

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.

Functions for Caching

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.

CACHE_Add:

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’.

CACHE_GetPk:

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’.

CACHE_GetLk:

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’.

Functions for File-IO

Directory_Empty:

extern int Directory_Empty(char * dir);

This function returns TRUE if the directory given by ‘dir’ is empty; else FALSE.

File_Exists:

extern int File_Exists(char * filename);

This function returns TRUE if the file given by ‘filename’ exists; else FALSE.

File_Delete:

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.

File_Read_Open / File_Write_Open / File_Append_Open:

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.

File_Close:

extern int File_Close(FILE * fp);

This function closes an open file descriptor.

File_Write:

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.

File_Contents:

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.

File_Add_Contents:

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.

File_Get_Contents:

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.

Functions for Random Number Generation

randinit:

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.

irand:

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.

drand:

extern double drand();

This function returns a random number in the range between 0.0 and 1.0. 

Functions for Handling Virtual Time

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.

DATE_Set:

extern void DATE_Set(void *);

Sets the virtual date.

DATE_Clear:

extern void DATE_Clear();

Inactivates the virtual date.

TIME_Set:

extern void TIME_Set(void *);

Sets the virtual time.

TIME_Clear:

extern void TIME_Clear();

Inactivates the virtual time.

Set_AktDateTime:

extern void Set_AktDateTime(void * date, void * time);

Sets the virtual date and time.

Set_AktDateTime:

extern void Set_AktTimestamp(void * dati);

Sets the virtual date and accurate time.

TIME_Now:

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.

DATE_Now:

extern void DATE_Now(void * date);

Gets the current date. If virtual time is active this function returns the virtual date.

DATI_Now:

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.

Get_Timestamp:

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”).

Functions for Handling Data-Type DATE

DATE_Copy:

extern void DATE_Copy(void * date1, void * date2);

This function assigns date2 to date1.

DATE_IsDefault:

extern int DATE_IsDefault(void * date);

This function returns TRUE if date is default.

DATE_IsDefault:

extern int DATE_IsValid(void * date);

This function returns TRUE if date is valid.

DATE_Compare:

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.

DATE_Compare:

extern int DATE_ToString(void * date, char * string, DateType);

This function converts date to a string using the defined DateType.

DATE_FromString:

extern int DATE_FromString(void * date, char * string, DateType);

This function reads a date from a string using the defined DateType.

DATE_DayNumber:

extern int DATE_DayNumber(void * date);

The actual number of the day in the year for the given date.

DATE_AddDays:

extern void DATE_AddDays(void * date, int days);

Adds the given number of days to the given date.

DATE_AddMonths:

extern void DATE_AddMonths(void * date, int months);

Adds given number of months to the given date.

DATE_MonthDays:

extern int DATE_MonthDays(void * date);

Returns the days of the month specified by the date.

DATE_GetUltimo:

extern void DATE_GetUltimo(void * date);

Returns the last day in the month specified by the date.

DATE_LeapYear:

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).

DATE_AddMonths_Ultimo:

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.

DATE_LeapDays:

extern int DATE_Diff_LeapDays (ADATE * date1, ADATE * date2);

Number of leap days within the given time period between date1 and date2.

DATE_Diff:

extern int DATE_Diff(void * date1, void * date2);

Returns the number of days between date1 and date2.

DATE_Diff_Mode:

extern int DATE_Diff_Mode(void * date1, void * date2, ModeType mode);

Returns the number of days between date1 and date2 using ModeType.

Functions for Handling Data-Type TIME

TIME_Copy:

extern void TIME_Copy(void * time1, void * time2);

Assigns time2 to time1.

TIME_IsValid:

extern int TIME_IsValid(void * time);

Returns TRUE if time is valid.

TIME_IsValidString:

extern int TIME_IsValidString(void * string);

Returns TRUE if string is a valid time-string.

TIME_Compare:

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.

TIME_FromString:

extern int TIME_FromString(void * time, char * string);

Gets time from the given time-string.

Functions for Handling Data-Type TIMESTAMP

DATI_IsValid:

extern int DATI_IsValid(void * dati);

Returns TRUE if dati is a valid time-stamp (ADATI or TFTimestamp).

DATI_IsValidString:

extern int DATI_IsValidString(void * string);

Returns TRUE if string is a valid time-stamp-string.

DATI_Compare:

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.

DATI_FromString:

extern int DATI_FromString(void * dati, char * string);

Gets dati from the given time-stamp-string.

DATI_ToString:

extern int DATI_ToString(void * dati, char * string, DatiType);

Generates a string from the given time-stamp ‘dati’ using DatiType-format.

DATI_Diff:

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.

Functions for Handling Binary Large Objects

See the Store/Store1-application for using the binary large objects with the Speedy/Speedy1-database.

TBL_Id:

extern int TBL_Id (void * ptable);

This function returns the database-structure-field ‘_iTable’.

COMPR_Init:

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.

COMPR_fnInit:

extern void   COMPR_fnInit     (COMPR * compr, void * fnInit);

Assigns the database-structure init-function (i.e. <TABLE>_Init).

COMPR_FmtBinFix:

extern void   COMPR_FmtBinFix  (COMPR * compr);

Defines binary format.

COMPR_FmtCompVar:

extern void   COMPR_FmtCompVar (COMPR * compr);

Defines compressed binary format.

COMPR_Free:

extern void   COMPR_Free       (COMPR * compr);

Frees internal used memory. Should be called as the last function when using the COMPR-functions.

COMPR_Reset:

extern void   COMPR_Reset      (COMPR * compr);

Resets the read-index for the data in the COMPR-buffer.

COMPR_AddBin:

extern void   COMPR_AddBin     (COMPR * compr, void * abin);

Adds data from the abin-buffer to the COMPR-buffer.

COMPR_GetBin:

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.

COMPR_Write:

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.

COMPR_Read:

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.

COMPR_GetId:

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.

COMPR_Set_Length:

extern void   COMPR_Set_Length (COMPR * compr, int size);

Redefines the length of the structure-items.

COMPR_SkipRead:

extern int    COMPR_SkipRead   (COMPR * compr);

Skips the next structure-item.

Functions for Storing/Loading Databases

TABLE_File_Save:

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.

TABLE_File_Load:

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.

TABLE_File_Skip:

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.

Functions for Analysing and Changing Database-Rows

Get_TABLE_Attrib_Type:

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.

Get_TABLE_Attrib_Value:

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.

Set_TABLE_Attrib_Value:

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.

Functions for Comparing and Rounding Double Values

DATA_CmpDouble:

extern int DATA_CmpDouble (double arg1, double arg2, double accuracy);

Compares arg1 and arg2 using accuracy.

DATA_RndDouble:

extern void DATA_RndDouble (double * arg1, double base, RndType);

Rounds arg1 by base using the given rounding convention in RndType.

Functions for Accessing the Database

ARGV_GetDB_Name:

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’.

DB_Print_Error_String:

extern void DB_Print_Error_String(void);

This function prints error-messages generated by the last database-access.

DB_Set_Error_Log:

extern void DB_Set_Error_Log(void);

Defines that the errors shall be directly logged to the log-file of the database.

DB_Set_Error_String:

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.

DBHANDLE_Init:

extern int DBHANDLE_Init(DBHANDLE **pDBHANDLE, char * dbname);

Initialises the test environment library and connects the system to the database with name ‘dbname’.

DBHANDLE_Free:

extern void DBHANDLE_Free(DBHANDLE *pDBHANDLE);

Frees all memory allocated by the test environment library and disconnects from the database.

Get_DBname:

extern const char * Get_DBname(DBHANDLE * pDBHANDLE);

Returns the database-name.

DB_Exists_Table:

extern int DB_Exists_Table(DBHANDLE *pDBHANDLE, char * tablename);

Returns TRUE if the table defined by tablename exists.

DB_Create_Table:

extern int DB_Create_Table(DBHANDLE *pDBHANDLE, char * sql);

Returns TRUE if the table could be created by the SQL-command given by sql.

DB_Drop_Table:

extern int DB_Drop_Table(DBHANDLE *pDBHANDLE, char * tablename);

Returns TRUE if the table defined by tablename could be dropped.

DB_Exists_Index:

extern int DB_Exists_Index(DBHANDLE *pDBHANDLE, char * indexname);

Returns TRUE if the index defined by indexname exists.

DB_Create_Index:

extern int DB_Create_Index(DBHANDLE *pDBHANDLE, char * sql);

Returns TRUE if the index could be created by the SQL-command given by sql.

DB_Drop_Index:

extern int DB_Drop_Index(DBHANDLE *pDBHANDLE, char * indexname);

Returns TRUE if the index defined by indexname could be dropped.

DB_Begin:

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.

DB_Commit:

extern int DB_Commit(DBHANDLE *pDBHANDLE);

This function successfully closes a transaction. All database-changes are conserved.

DB_RollBack:

extern int DB_RollBack(DBHANDLE *pDBHANDLE);

This function closes a transaction not successfully. All database-changes are undone.

DB_Exec_SQL:

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.

Functions for Handling Arrays

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.

ARRAY_New:

extern ARRAY * ARRAY_New(void);

This function creates a multiple and initialises it.

ARRAY_Init:

extern ARRAY * ARRAY_Init(ARRAY *arr);

This function initialises an existing array.

ARRAY_Assign:

extern ARRAY * ARRAY_Assign(ARRAY * arr1, ARRAY * arr2);

Assigns arr2 to arr1. The data-items are copied.

ARRAY_Free:

extern void ARRAY_Free(ARRAY *arr);

Frees the memory hold by the elements in the array ‘arr’ and of the array.

ARRAY_GetPtr:

extern void * ARRAY_GetPtr(const ARRAY *arr, int idx);

Gets a pointer to the item with index idx in the array arr.

ARRAY_Remove:

extern void ARRAY_Remove(ARRAY *arr, int idx);

Removes item idx from array arr.

ARRAY_Add:

extern void ARRAY_Add(ARRAY *arr, void * info);

Adds an item info to array arr.

ARRAY_Sort:

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.

ARRAY_AddArray:

extern void ARRAY_AddArray(ARRAY *arr1, ARRAY *arr2);

Adds an array arr2 to the existing array arr1.

Other Functions

Get_SysTimestamp:

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.

Make_Surrogat:

extern void Make_Surrogat(TFSurrogat *surr);

Generates a random surrogate which can be tried as a primary key.

DATA_GetNumber:

extern void DATA_GetNumber(DBHANDLE * pDBHANDLE, long * num, int len);

Generates a random number ‘num’ of length ‘len’.

DATA_Assign:

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.

DATA_Compare:

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);

DATA_Add:

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).

match_search_strg:

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.

Matching_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.

Find_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.

String_Replace:

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.

Plain_String_Replace:

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.

Examples

 

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.