HTML clipboard 1. A brief presentation of SQL 3 The filing of the standard of the new version of SQL, SQL entitled 3 (1999) took place shortly before the arrival of 2000. By a what its essential elements are located within the main RDBMS it would take several years. We are in 2001 and only the publishers Oracle, IBM and Informix have started to communicate on the subject. We will see that SQL 3 presents significant progress, particularly in terms of types of data in the programming of RDBMS and the concept of relational object. 1.1. Triggers (Triggers) Non-existent in the standard SQL 2, but most of the time established by manufacturers RDBMS, SQL triggers with 3 become an inescapable reality. Briefly recall what a trigger: a trigger is a simple interceptor event-specific databases. His granularity is defined at the table. The syntax of a trigger SQL 3 is as follows: CREATE TRIGGER NAME_trigger BEFORE | AFTER INSERT | DELETE | UPDATE [OF liste_column] ON tablename [REFERENCING OLD [ROW] [AS] NAME_anciennes_valeurs_row | NEW [ROW] [AS] NAME_news_valeurs_row | OLD TABLE [AS] NAME_anciennes_valeurs_table | NEW TABLE [AS] NAME_news_valeurs_table ] FOR EACH STATEMENT | ROW [WHEN condition] BEGIN [ATOMIC] code_trigger END It is noticeable that the triggers SQL 3 have a fine enough granularity they can ask executable code before or after the events of insertion, deletion or modification, and in this last case, with a filter execution on the columns changed. Example: CREATE TRIGGER verif_PRICES_surrendere BEFORE UPDATE (PRICES_uht, quantity discount) ON command REFERENCING OLD ROW AS old_row_values NEW ROW AS new_row_values FOR EACH ROW WHEN new_row_values.surrender> old_row_values.PRICES_uht * new_row_values.quantite BEGIN ATOMIC DECLARED message VARCHAR (255) new_row_values.surrender = old_row_values.surrender SET message = 'Table ORDER, client' || cast (new_row_values.cli_id as CHAR (32)) INSERT INTO ALERT (USER, TROUBLE, DATE_TIME, LOCATION) VALUES (CURRENT_USER, 'Overtaking surrender acceptable', CURRENT_TIMESTAMP, Message) END The trigger is triggered if an update comes on the table ORDER and only if at least one of the columns PRICES_UHT, IN REMISSION or is modified. It reallocates the new value of the rebate if the latter exceeds the old price multiplied by the amount present. He also inserts a record in the table ALERT. The key word ATOMIC, said that the main trigger must be executed as a transaction, i.e. in one fell swoop without competition (atomic execution). They may point out that this type of trigger is much closer to those of Oracle as those of SQL Server. 1.2. Extension of language As a result of the introduction of triggers and many other extensions, SQL 3 gets a syntax provided. It becomes a real procedural language is very close to the syntax of Ada or Pascal. Thus, there is the concept of block, defined by the keywords BEGIN and END. The declaration of variable done using the keyword DECLARED and assignment using the keyword SET. Conditional new structures are emerging: IF, FOR, LOOP, REPEAT, DO WHILE, DO UNTIL, WHILE, LEAVE. The management of exceptions is now a reality, especially since the return codes of anomalies have been expanded, and it is possible to propagate errors to containers using the key words and RESIGNAL SIGNAL, a little the way RAISE ERROR language Ada. Finally, the external visibility, as encapsulation in languages guests are strengthened through SQL / CLI (Call-Level Interface, already present in version 2 of SQL), a real interface between applications and dynamic SQL. In conclusion, say that the most audacious in the field of relational object, Persistent Stored Module (PSM), real libraries procedures and routines that can perform functions use a different levels. 1.3. Library code (SHP - Persistent Stored Module) Since SQL 2 existed the concept of "module" to launch SQL said "dynamic". This concept becomes more important because of the breakthrough of the object and relational SQL 3 responds with the PSM (Persistent Stored Module) encompassing functions and procedures. In both cases, it is close to the UDF or User Define Function, including introduced by Borland InterBase. A PSM that we call library, built by example in the following manner: MODULE gestion_ACCOUNT LANGUAGE SQL; DECLARE total DECIMAL (16.2); FUNCTION balance (SQLCODE, client_id) RETURNS FLOAT; SELECT SUM (CPT_CREDIT) - SUM (CPT_DEBIT) INTO total FROM ACCOUNT_BANCAIRE WHERE CLI_ID client_id =; RETURN total; PROCEDURE credited (SQLCODE, client_id, amount DECIMAL (16.2)); INSERT INTO ACCOUNT (CLI_ID, CPT_CREDIT, DATE_TIME_TRANSACTION) VALUES (client_id, amount, CURRENT_TIMESTAMP); PROCEDURE charged (SQLCODE, client_id, amount DECIMAL (16.2)) INSERT INTO ACCOUNT (CLI_ID, CPT_DEBIT, DATE_TIME_TRANSACTION) VALUES (client_id, amount, CURRENT_TIMESTAMP); END MODULE; This small module brings together the functions to calculate the balance, credit or debit the account of a client. It can be done in another language SQL, among those provided by the standard: Ada, C, COBOL, FORTRAN, NUMPS, PASCAL and PL1. The module is absolutely committed, or to a client (and therefore outside a specific database) or the schema of a database (server module). It is in a PSM score that we will define procedures common to all bases as the test of whether an integer is the first.
1.4. Types abstract SQL 3 introduces some new types of commodities, as BOOLEAN (Boolean), BINARY LARGE OBJECT (binary large object), CHARACTER LARGE OBJECT (BLOB type string), ROW (column - as a column of table), SET ( set of values), MULTISET (combinations SET) and LIST (list). In SQL 3 typing data can become strong through the key word DISTINCT. Example: CREATE SEPARATE DT_TEMPERATURE TYPE AS FLOAT CREATE SEPARATE DT_VOLTAGE TYPE AS FLOAT Once a column created with the type DT_TEMPERATURE will no longer be compared to a column created with the type DT_VOLTAGE which prevents the mixture of cloths and towels. In addition, and to strengthen such a typing it is possible to redefine what operators (+ - * /) and comparison (= and <) may be on this type definition. But it is with Abstract Data Type (ADT) SQL 3 introduces a revolution ... An abstract data type can encapsulate any kind of basis and can be composed of several attributes that could even be virtual (methods). Of course, and visibility of these attributes meets the principles items using keywords PUBLIC (external visibility), PRIVATE (internal visibility) and PROTECTED (visibility limited to descendants). Example CREATE TYPE ADT_ADDRESS (ADR_ROW1 VARCHAR (32), ADR_ROW2 VARCHAR (32), ADR_ROW3 VARCHAR (32), ADR_CODE_POST CHAR (5), ADR_CITY VARCHAR (32)) CREATE TYPE ADT_PERSON (PRS_NAME CHAR (64), PRS_PRENAME CHAR (32), PRS_DATE_BIRTH DATE PRS_HOME ADT_ADDRESS, PRS_TITLE CHAR (6), PRIVATE PRS_SEX BOOLEAN DEFAULT 0) PUBLIC FUNCTION AGE (a_person ADT_PERSON) RETURN FLOAT BEGIN DECLARE: a_person ADT_PERSON; DECLARE: FLOAT retval; CASE PRS_DATE_BIRTH (a_person); NULL THEN WHEN IS SET retval = -1; OTHERWISE SET retval = CURDATE - PRS_DATE_BIRTH (a_person); RETURN retval; END; This example defines the types abstract ADT_ADDRESS (address) and ADT_PERSON (nobody). ADT_PERSON contains a private attributes which can for example be updated according to insert and update in correspondence with the choice of title before ( 'Mr.' => Male therefore 0, 'Mrs.' and 'Miss.' => Female therefore 1). In addition, a method of calculating age, scope public, was encapsulated in the type person and return the person's age at the time of day depending on the data returned to attribute PRS_DATE_BIRTH. Of course the abstract data types have a builder and a destroyer. The manufacturer may pre-initialize certain attributes and the destroyer can carry out routine cleaning before finalizing destruction. Access to data of an object of the database developed from an abstract data type is done either through interweaving of parenthesis, with a notation doubling pointing. Example: CREATE TABLE T_CLIENT (CLI_ID INTEGER, CLI_PERS ADT_PERSON) INSERT INTO T_CLIENT VALUES (1, CLI_PERS ( 'SMITH', 'Frank','1960-11-18 ', PRS_HOME ('124 street d''Alesia','','','75014 ',' PARIS ') ), 'Mr.') SELECT CLI_ID, CLI_PERS .. PRS_NAME FROM T_CLIENT WHERE CLI_PERS .. PRS_HOME .. ADR_CITY LIKE 'bets%' CLI_ID CLI_PERS .. PRS_NAME ---------- ----------------------- 1 DUPONT Rating doubling pointing explained by the fact that the simple notation in scoring is already used for nicknames given to particular tables in the joints and sub queries correlated. As a table may now have under tables with SQL 3, it is possible to activate the legacy in order of creation: CREATE TABLE CUSTOMER UNDER PERSON WITH (TAUGHT VARCHAR (255)) One could say many things about abstract types of standard SQL 3, but I let the specialists and scholars to speak in this area and can be found on the web and in the current release of many elements to continue his reading. 1.5. and yet ... A disturbing element in previous standards was unable to perform recursive queries. This is something gone now with SQL 3 which allows recursion using the concept of "expression table", defined by the WITH clause. Therefore it is possible to request a recursive execution of the request (keyword RECURSIVE) and to clarify the condition of judgment in a clause CYCLE. Such a mechanism can be more easily model graphs and trees and work more easily in the data representatives. The scheduling schemes are also new SQL 3 and allow to define specific object to a database, a sort of independent character sets. The introduction of Boolean requires a predicate "Boolean". Here it is: IS condition [NOT] FALSE | TRUE | UNKNOWN And we find there a logic in three states. As regards the management of transactions, the standard SQL 3 allows you to define the beginning of a transaction (START TRANSACTION), but also intermediate points (SAVE POINT) and all this by name. In terms of access rights, SQL 3 introduces the concept of role which are a collection of privileges or rights that a user can be assigned. Finally three major extensions to SQL 3 are already planned. It will be clearly defined in the future standard SQL 4. This is SQL Object, management of multimedia, and SQL / TR for applications such real-time. 2. XML, XQL and databases The rise of the Internet has produced different standards induced by the obligation to cooperate operating systems and graphical user interfaces from different backgrounds. Among these standard XML already very present and the language XQL still not widespread, will both come to upset the world of databases. 2.1. Extensible Markup Language (XML) XML (Extensible Markup Language) is a description language data presents a major step forward compared to HTML (Hyper Text Markup Language). The HTML and XML languages are using descriptive tags, which are usually interpreted on the fly to format the data, either in terms of graphics (HTML) either in terms of relationships or structural (XML). Both the HTML currently widely used for a vast majority of website was a driving force behind the rising power of the web, all he saw was becoming an obstacle to boosting websites simply by the fact that HTML mixture data and presentation in a single flow of information and to add new functions back to the highly complex. The idea has come to separate the two elements: the presentation, using style sheets (XSL: extended Style Language) and on the other hand data and their structure and relations. Thus, an XML document is applied XSL style sheet and one can see the data presented in the form, interlocking and structuring that you want. Better still, the application of style sheets type CSS (Cascading Style Sheets) can transform the flow of data in XML structured data and presented in the form of HTML stream directly readable in any web browser. At the root of XML we find the SGML (Structured, Generalized Markup Language) used mainly for technical documentation and mainly in the field of scientific research. In fact XML is a description language document structures. Its power is enormous and all the more spectacular it is proving to be of great simplicity. It serves both the storage of data in their research, and therefore it is very comfortable in the exchange of messages. Combining power and simplicity is a successful challenge in XML by a simple kitchen: decompose each role by a specific document. In fact XML is a document composed of two elements: the flow of data (XML) and grammar (DTD: Document Type Definition), ie syntax rules applicable to the document. It's a bit like if we separated in a computer program data and language that we provided a new language and its possibilities to use every execution. Such a mechanism may seem heavy, but we must understand that there is a DTD that can serve as a frame to all non-specific data. Conversely, construct DTD specific to talk in more detail, according to rules "occupations" such as those we will find in the chemical industry, the world of finance or mathematics. Today important websites (rosettanet, oasis, mtic ...) are used to publish documents and valid XML DTD so that computer operators working in these trades can communicate more easily information automatically. On the other side of new products, implementing XML, are published in software and are intended to facilitate the exchange computerized data interchange (EDI). For example, Microsoft BizTalk Server. The benefits of XML are immense ... XML: * Structure allows easy data * Is expected to manage relations between the data of the same document * Greatly facilitates the exchange computerized data Therefore XML tends to become the standard of conversation data between computer systems. For example, with XML it is now easier to replicate data base to another even if the bases have different structures, and even if the RDBMS are different. Here are two examples of using XML. The first is used to define types of data. This is equivalent to order SQL "CREATE DOMAIN: <datatype name = "ref_product" source = "string"> pattern value = "\ d (5) - \ d (5)" </ datatype> <datatype name = "temperature" source = "integer"> <minInclusive> -272 </ minInclusive> <maxInclusive> 10000 </ maxInclusive> </ datatype> The second allows you to send in a URL, an order SELECT directly to a database: SELECT CLI_NAME + + + CLI_PRENAME FROM t_CLIENT + + + + XML FOR AUTO The plus sign being converted into space and the key words "FOR XML AUTO" demands that the database server returns the flow of information to answer directly as XML. Many RDBMS start work in XML format. This is the case with SQL Server 2000 Microsoft but also Informix, DB2 (IBM) and Oracle. Workshops complete start to emerge, with the database and development tools capable of generating the web interfaces. This is the case of products XDBMS XML-centric, Excelon XML Data Server Object Design Inc. or even Tamino and its suite of Software AG. 2.2. extended Query Language (XQL) But the future of SQL entitled XQL (extended Query Language) that can reasonably be described as language query structured data in XML! Here is an example of XML document: <? xml version = "1.0"?> <auteur> <first name> Victor </ first name> HUGO <name> </ name> <work kind="novel"> <title>The Miserables </ title> <publication> 1861-11-17 </ publication> </ work> <work kind="novel"> <title> Our Dame of Paris </ title> <publication> 1831-02-27 </ publication> </ work> </ author> <auteur> VOLTAIRE <name> </ name> <work kind="new"> <title> Zadig or Destiny </ title> </ work> <work kind="Short"> <title> Philosophical Dictionary </ title> <publication> 1764-11-26 </ publication> </ work> <work kind="novel"> <title> Candide </ title> </ work> <work kind="tests"> <title> Treaty on Tolerance </ title> <publication> 1763-01-06 </ publication> </ work> </ author> Its content is a real database and its structure resembles a tree. author |> first_name |> name |> work |> title |> publication Here are some queries XQL using the example above: Look all works: Query XQL: / / work answer: <xql:result> <work kind="novel"> <title> the Miserables </ title> <publication> 1861-11-17 </ publication> </ work> <work kind="novel"> <title> Our Dame of Paris </ title> <publication> 1831-02-27 </ publication> </ work> <work kind="new"> <title> Zadig or Destiny </ title> </ work> <work kind="Short"> <title> Philosophical Dictionary </ title> <publication> 1764-11-26 </ publication> </ work> <work kind="novel"> <title> Candide </ title> </ work> <work kind="tests"> <title> Treaty on Tolerance </ title> <publication> 1763-01-06 </ publication> </ work> </ xql: result> Look for authors whose first name is Victor Query XQL: / / author [first name = 'Victor'] Answer: <xql:result> <author> <first name> Victor </ first name> HUGO <name> </ name> <work kind="novel"> <title>The Miserables </ title> <publication> 1861-11-17 </ publication> </ work> <work kind="novel"> <title> Our Dame of Paris </ title> <publication> 1831-02-27 </ publication> </ work> </ author> </ xql: result> Look all works published between 1764 and 1835: Query XQL: / / work [publication> = date ( "1764-01-01") $ and $ publication <= date ( "1835-12-31")] Answer: <xql:result> <work kind="novel"> <title>The Miserables</ title> <publication> 1861-11-17 </ publication> </ work> <work kind="Short"> <title> Dictionary Philosophical </ title> <publication> 1764-11-26 </ publication> </ work> </ xql: result> Of course these answers gross require the application of a style sheet XLS to be freed of all the elements to the kitchen XML.
|