pgScript Developer Guide


Table of Contents

Additional programs required
Flex
Bison
Directory structure
Software architecture
Test pgScript
Unit tests
Integration tests
Preprocessor symbols
PGSCLI
PGSDEBUG
Automation scripts
Add a new expression
Properties of an expression
Operands
New expression
Add a new statement
Properties of a statement
New statement

Additional programs required

Flex

Flex 2.5.33 or later is required.

You need to use FlexLexer.h provided with your Flex distribution: copy this file into lib/include/pgscript.

For MinGW you can download flex-2.5.33 from MinGW Supplementary Tools download section. regex-0.12 is also required. Unzip the archives in msys/1.0 directory and then:

flex --version

This must print 2.5.33 or later.

Bison

Bison 2.3 or later is required.

For MinGW you can download bison-2.3 from MinGW Supplementary Tools download section. regex-0.12 is also required. Unzip the archives in msys/1.0 directory and then:

bison --version

This must print 2.3 or later.

Directory structure

Software architecture

This section describes the pgadmin/pgscript folder, which is very like pgadmin/include/pgscript.

Test pgScript

There are two steps: unit tests on classes and integration tests on pgScript executable.

Go to the root directory of pgAdmin and enter the following command:

./configure

Go to the xtra/pgscript directory and enter the following command:

make

This should compile both the pgScript command-line interface (bin) and the unit test suite (test).

Unit tests

Go to the xtra/pgscript directory and enter the following command:

./test/pgsTest

There should be no assertion failure otherwise there is a bug.

Integration tests

Go to the xtra/pgscript and enter the following command:

./file/test/execute.sh -h 192.168.190.1 -p 5432 -U postgres -W postgres -d testbase

The string -h 192.168.190.1 -p 5432 -U postgres -W postgres -d testbase are the parameters for pgScript. Replace them with your database parameters.

There should be no error during this process. An error is a line in the output that begins with [EXCEPT] or [ERROR] or a segmentation fault.

Note: use a LOG_ERRORS log level in main() in order not to display too many things on the screen, otherwise it would be hard to see if there was a failure.

Preprocessor symbols

PGSCLI

Automatically defined when compiling the command-line interface. PGSCLI stands for pgScript Command-Line Interface. This means not to compile specific parts of pgAdmin and pgScript code because the command-line interface does need them: this is mainly GUI code that is ignored.

Along with PGSCLI PGADMIN3_H is also defined because the command-line must not include pgAdmin3.h.

When compiled normally with pgAdmin this symbol is not defined.

PGSDEBUG

Compiles pgScript command-line interface or unit test suite with memory tracking features. At the end of the program undeallocated memory blocks are displayed. Use pnew instead of new, pdelete(x) instead of delete x and pdeletea(x) instead of delete[] x when programming pgScript in order to be able to use those features.

Automation scripts

pgadmin/pgscript/parser.sh

parser.sh must be called for regenerating Flex and Bison source files because it does some more processing that just executing bison and flex: it replaces some headers and adds other ones.

xtra/pgscript/file/test/execute.sh

See the Directory structure section. Runs the integration test suite.

Add a new expression

Properties of an expression

Operands

A pgsOperand is a smart pointer to a pgsVariable (pgsGenerator, pgsNumber, pgsRecord and pgsString).

To declare a pgsOperand:

pgsOperand operand(pnew pgsNumber(wxT("1")));

Then a pgsOperand is copied, duplicated and deleted automatically. In the example above there is no need to delete the new pgsNumber: the destructor is called automatically when operand is deleted.

pgsOperand copy(operand);
operand = copy;

To duplicate and retrieve the pgsNumber:

pgsNumber * number = operand->clone();

Even if copy and deletion are handled automatically, pgsOperand is accessed like a regular pointer with ->:

cout << operand->value() << endl;
return operand->eval(vars);

New expression

Note. The vars parameter is the symbol table: this is a map whose key is the variable name and whose value is a pgsOperand.

Note. Use parser.sh to regenerate the Flex/Bison parser.

The protected data is most of the time string identifiers and pointers to pgsExpression expressions that are used (evaluated) for evaluating the expression.

Add a new statement

Properties of a statement

New statement