EasyQL Language Reference Manual, Study notes of Database Management Systems (DBMS)

Fall 2006 Columbia University ... different database management systems. ... This section deals with some exemplary codes that can illustrates usages of ...

Typology: Study notes

2022/2023

Uploaded on 05/11/2023

hollyb
hollyb 🇺🇸

4.8

(44)

431 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
EasyQL Project team
EasyQL
Language Reference Manual
CS W4115: Programming Languages and Translators
Professor Stephen A. Edwards
Computer Science Department
Fall 2006 Columbia University
EasyQL Members:
Kangkook Jee (kj2181)
Kishan Iyer (ki2147)
Smridh Thapar (st2385)
Sahil Peerbhoy (sap2126)
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download EasyQL Language Reference Manual and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

EasyQL

Language Reference Manual

CS W4115: Programming Languages and Translators

Professor Stephen A. Edwards

Computer Science Department

Fall 2006 Columbia University

EasyQL Members:

Kangkook Jee (kj2181)

Kishan Iyer (ki2147)

Smridh Thapar (st2385)

Sahil Peerbhoy (sap2126)

Table of Contents

    1. Lexical Conventions....................................................................................................
    • 1.1. Comments
    • 1.2. Tokens................................................................................................................
    • 1.3. Identifiers
    • 1.4. Keywords
    • 1.5. Literals
      • 1.5.1. Integer Constants
      • 1.5.2. Character Constants
      • 1.5.3. Floating Point Constants
      • 1.5.4. String Constants.........................................................................................
    • 1.6. Embedded SQL Blocks.......................................................................................
    1. Data Types
    • 2.1. Character Types..................................................................................................
      • 2.1.1. Characters – type ‘varchar’
    • 2.2. Number Types
      • 2.2.1. Integer – type ‘int’
      • 2.2.2. Real – type ‘float’
    • 2.3. Date Type...........................................................................................................
      • 2.3.1. Date – type ‘date’.......................................................................................
    • 2.4. Database object types
      • 2.4.1. Table – type ‘table’....................................................................................
      • 2.4.2. Connection – type ‘connection’..................................................................
    1. Expressions and Operators...........................................................................................
    • 3.1. Primary expressions............................................................................................
      • 3.1.1. Identifier....................................................................................................
      • 3.1.2. Number......................................................................................................
      • 3.1.3. Character
      • 3.1.4. Date...........................................................................................................
      • 3.1.5. Table
      • 3.1.6. Connection
    • 3.2. Expression and parenthesized-expression............................................................
      • 3.2.1. Expressions for basic data types.................................................................
      • 3.2.2. Operators for table type and connection type..............................................
      • 3.2.3. Operators for Connection Type................................................................
    1. Statements
    • 4.1. Expression statement
    • 4.2. Compound statement
    • 4.3. Conditional Statement.......................................................................................
    • 4.4. While statement................................................................................................
    • 4.5. PRE – DEFINED FUNCTIONS
      • 4.5.1. Display
      • 4.5.2. Connection
    1. Examples...................................................................................................................
    • 5.1. Table insertion example....................................................................................
    • 5.2. Connection retry example

1.5.2. Character Constants

Character constants are one or more members of the source character set, the character set in which a program is written, surrounded by single quotation marks ('). They are used to represent characters in the execution character set, the character set on the machine where the program executes. Reserved Characters: 1 New line \n 2 Horizontal tab \t 3 Vertical tab \v 4 BEL \ 5 Question mark ? 6 Single quotation mark ' 7 Double quotation mark " 8 Null character \ 0

1.5.3. Floating Point Constants

Real constants specify values that may have a fractional part. These values contain decimal points (.) and can contain exponents.

1.5.4. String Constants

A string literal consists of zero or more characters from the source character set surrounded by double quotation marks ("). A string literal represents a sequence of characters that, taken together, form a null- terminated string.

1.6. Embedded SQL Blocks

Embedded SQL blocks begin with the character sequence ‘<$’ and end with the character sequence ‘$>’. The embedded code will be inserted into the generated query set. The compiler may inspect the SQL code and issue errors or warnings, but it is not required to do so. SQL block: <$ SQL statement $>

  1. Data Types EasyQL uses data types which are commonly used and are compatible with a large number of databases. This is done to ensure portability of tables defined in EasyQL. The categories of the data types are:
    • Character data types
    • Number data types
    • Date data type
    • Database object data types

2.1. Character Types

2.1.1. Characters – type ‘varchar’

Like the “varchar” type of SQL, this creates a character string of variable length, the maximum length in bytes restricted by “size”. Unlike the char type, there is no blank padding when fewer than “size” characters are supplied. However, inserting a value greater than “size” characters is not permitted. Their declaration syntax is: varchar(size) identifier_name ;

2.2. Number Types

2.2.1. Integer – type ‘int’

It maps on to the SQL type “INTEGER” and represents a 32-bit (signed) integer value. The value will range between integers - 2147483648 and 2147483647. Their declaration syntax is: int identifier_name;

2.2.2. Real – type ‘float’

This type corresponds to the SQL type “REAL”. In EasyQL, we define the float type to contain 15 bits of mantissa. Their declaration syntax is: float identifier_name;

2.3. Date Type

2.3.1. Date – type ‘date’

The date type in EasyQL represents a date comprising a date, month and year as well as for time. This will correspond to “DATE” in SQL. Their declaration syntax is: date identifier_name ;

2.4. Database object types

2.4.1. Table – type ‘table’

The table type in EasyQL is a collection of the attributes of a table. The attributes may be of different types and attributes within a table must have unique names, in order to distinguish between them. Their declaration syntax is: table identifier; Table variable can be initialized by retrieving existing table in the connection or by creating new one. An attribute name of a table tableA could be accessed thus : tableA[id]

2.4.2. Connection – type ‘connection’

The connection type specifies a connection to a particular database. A connection instance can be created by passing the right connection parameters when creating a connection type. Their declaration syntax is: connection identifier; Assignment to connection can be made by calling connect () built-in function Ex. connection conn = connect (localhost, 1521, testDB, mysql, msyqlpasswd); Since the connection is to a particular database, an attribute id of table table1 in a databsase connected to conn can be assigned to a variable attr1 by: Ex. attr1 = conn:table1[id]

3.2.1.1. Postfix expressions These are two postfix operators for incrementing and decrementing objects for number types. These will be placed after the operand and change the value of operand. The type won’t be changed after operation. Number type of expressions can be operand for these expressions. These are right-to-left operation. postfix-expression: number-expression ++ | number-expression -- 3.2.1.2. Unary operations + , - , ++, --, These are unary operators that will be placed in front of operand and change the value of operand. The type won’t be changed after operation. Number type of expressions can be operand for these expressions. These are left-to-right operations. prefix-expression: + number-expression | - number-expression prefix-expression: ++ number-expression prefix-expression: -- number-expression prefix-expression: !number-expression 3.2.1.3. Binary operations + - * / % Theses are binary operations and which means addition, subtraction, multiplication, division and modular operation respectively. Number type of expression can be operands for these expressions and these will return the same type expressions. These are left-to-right operations. binary-expression: number-expression * number-expression binary-expression: number-expression / number-expression binary-expression: number-expression % number-expression binary-expression: number-expression + number-expression binary-expression: number-expression - number-expression 3.2.1.4. Comparison operators == != >= > < <= , like These operators will compare operands and evaluate relationship between operands. These will return 0 if the relationship in the expression doesn’t hold, 1 otherwise. Operand for this operation can be number type expression, and date type expressions. These operations are for left-to-right evaluation. compare-expression: compare-expression == compare-expression compare-expression: compare-expression != compare-expression compare-expression: compare-expression > compare-expression compare-expression: compare-expression >= compare-expression compare-expression: compare-expression < compare-expression compare-expression: compare-expression <= compare-expression

3.2.1.5. Logical operators && || These operators will yield 1 (in case of TRUE) and 0 (in case of FALSE) otherwise. These operations are for left-to-right evaluation. This will return 1 if both operands are non-zero, 0 otherwise. logical-expression: logical-expression && logical-expression This will return 1 if any of operands is non-zero, 0 otherwise. logical-expression: logical-expression || logical-expression 3.2.1.6. Assignment expression The language provides one assignment operator as bellows. This will be used to assign a value of right expression to the modifiable identifiers of the left. assignment-operation: identifier-expression = expression

3.2.2. Operators for table type and connection type

In this section, we will cover operations between database objects. We will mostly deal with the operations of table data types and a couple of operators for connection data types will be mentioned briefly. 3.2.2.1. Sub-Table Operators [ ], () Programmers can retrieve data from a table type variable with these operators. These operators are to specify appropriate attributes and conditions. The output of sub-table operation is originally meant to be another type of table object. But in case of having just one element as a result of query, this can be treated as basic data types such as numbers, characters and date data types. sub-table-expression: table-expression [attr-expression-list] sub-table-expression: table-expression ( cond-expression-list) attr-expression-list(opt): attr-expression, attr-expression-list(opt) cond-expression-list: cond-expression, cond-expression-list Ex. tableA[ssn, name].display() This example operation will retrieve sub-table of ssn attribute and name attribute from tableA. display () function will print the records in sub-table. Ex. tableA(age>20).display(); This example operation will retrieve sub-table of tableA which satisfies the condition that is specified in the parenthesis. display () function will print the records in sub-table Ex. tableAname.display(); Programmer can specify attributes and conditions at the same time. Ex. table tableB; tableB =tableA.name.display(); Result of functions can be assigned to another table type variable, instead of displaying output to standard output.

3.2.2.6. Drop Table Expression This operation will cancel definition of table type object and drop the table schema in the table space. drop-expression: table-name-expression.drop() Ex. tableA.drop(); This will drop the existing table from the table space 3.2.2.7. Metadata Expression This operation .desc() and .list() can work on table or connection type and will retrieve the schema of the table and tables and connection related information (such as user name, address of database, database instance name …) that belongs to the connection respectively. Output of operations can be stored as table data-type or printed to the user screen by calling a built-in function .display (). meta-expression: table_expression.desc (); | connection_expression.desc(); Ex. table tableB tableA.desc(); tableB.display(); The next operation .list() can be applied only to connection data type to list table names which belongs to the connection. meta-expression:connection_expression.list(); Ex. connection conn = connect (localhost,1521,testDB, mysql,mysql123); conn.list().display();

3.2.3. Operators for Connection Type

The “::” operation will retrieve a table data type from a connection. connection-expression: connection-expressio::.table-name Ex. connection A = connect (localhost,1541,tablespaceA, mysql,passwd) table tableA = A::ProjectMemberTable; The .store operation will store a table data type into a connection. connection-expression: connection-expression.store(table-name); Ex. connection A = connect (localhost,1541,tablespaceA, mysql,passwd) connection B = connect (remotehost,1541,tablespaceB,mysql,passwd) table tableA = A::ProjectMemberTable; B.store(A);

  1. Statements Statements are generally always executed is sequence.

4.1. Expression statement

Most statements are expression statements, which have the form expression ; Usually expression statements are assignments or function calls.

4.2. Compound statement

So that several statements can be used where one is expected, the compound statement is provided compoundstatement: { statementlist } statementlist: statement statement statementlist

4.3. Conditional Statement

The two forms of the conditional statement are if ( expression ) statement if ( expression ) statement else statement In both cases the expression is evaluated and if it is nonzero, the first sub-statement is executed. In the second case the second sub-statement is executed if the expression is 0. As usual the ‘‘else’’ ambiguity is resolved by connecting an else with the last encountered else-less if.

4.4. While statement

The while statement has the form while ( expression ) statement The sub-statement is executed repeatedly so long as the value of the expression remains nonzero. The test takes place before each execution of the statement.

4.5. PRE – DEFINED FUNCTIONS

4.5.1. Display

This is a predefined function that is used to display the results of a query on the screen. database-expressions.display()

4.5.2. Connection

This is a predefined function that creates the connection to the database. connecton-type connection (ipaddress , port, instance_name, db_name, user, password);

  1. Examples This section deals with some exemplary codes that can illustrates usages of EasySQL

5.1. Table insertion example

This program is to merge a table from one database to the table of the other. connection A = connect(localhost, 1541, tablespaceA, root, passwd); connection B = connect(remotehost, 1541, tablespaceA, root, passwd); table emp1 = A::employee; table emp2 = B::employee; emp2.insert (emp1);