4D v11 SQL Release 1 (11.1) ADDENDUM Welcome to release 1 of 4D v11 SQL. This document outlines the new features and modifications provided in this version of 4D. Query Analysis 4D provides three new commands that can be used to analyze with precision the execution of queries carried out on the data. These commands are intended for developers seeking to optimize their applications. These three new commands are found in the Queries theme. DESCRIBE QUERY EXECUTION DESCRIBE QUERY EXECUTION (status) Parameter Type Description status Boolean True=Enable internal query analysis False=Disable internal query analysis The DESCRIBE QUERY EXECUTION command can be used to enable or disable the query analysis mode for the current process. The command takes into account both queries carried out via the 4D language or by SQL. Calling the command with the status parameter set to True enables the query analysis mode. In this mode, the 4D engine records internally two specific pieces of information for each subsequent query carried out on the data: A detailed internal description of the query just before its execution, in other words, what was planned to be executed (the query plan), A detailed internal description of the query that was actually executed (the query path). 4D v11 SQL Release 1 (11.1) Addendum 1
4D v11 SQL Release 1 (11.1) Addendum The information recorded includes the type of query (indexed, sequential), the number of records found and the time needed for every query criteria to be executed. You can then read this information using the new Get Last Query Plan and Get Last Query Path commands. Usually, the description of the query plan and its path are the same, but they may nevertheless differ because 4D might implement dynamic optimizations during the query execution in order to improve performance. For example, an indexed query may be converted dynamically into a sequential query if the 4D engine estimates that this might be faster this is sometimes the case, more particularly, when the number of records being queried is low. Pass False in the status parameter when you no longer need to analyze queries. The query analysis mode can slow down the application. The following example illustrates the type of information obtained using these commands in the case of an SQL query: C_TEXT($vResultPlan;$vResultPath) ARRAY TEXT(aTitles;0) ARRAY TEXT(aDirectors;0) DESCRIBE QUERY EXECUTION(True) `analysis mode Begin SQL SELECT ACTORS.FirstName, CITIES.City_Name FROM ACTORS, CITIES WHERE ACTORS.Birth_City_ID=CITIES.City_ID ORDER BY 1 INTO :atitles, :adirectors; End SQL $vresultplan:=get Last Query Plan(Description in Text Format) $vresultpath:=get Last Query Path(Description in Text Format) DESCRIBE QUERY EXECUTION(False) `End analysis mode After this code is executed, $vresultplan and $vresultpath contain descriptions of the queries carried out, for example: $vresultplan: [Join] : ACTORS.Birth_City_ID = CITIES.City_ID 2 4D v11 SQL Release 1 (11.1) Addendum
Query Analysis vresultpath: And [Merge] : ACTORS with CITIES [Join] : ACTORS.Birth_City_ID = CITIES.City_ID (1227 records found in 13 ms) --> 1227 records found in 13 ms --> 1227 records found in 14 ms If the Description in XML format constant is passed to the Get Last Query Path command, $vresultpath contains the description of the query expressed in XML: <QueryExecution> <steps description="and" time="0" recordsfounds="1227"> <steps description="[merge] : ACTORS with CITIES" time="13" recordsfounds="1227"> <steps description="[join] : ACTORS.Birth_City_ID = CITIES.City_ID" time="13" recordsfounds="1227"/> </steps> </steps> </QueryExecution> Get Last Query Plan Get Last Query Plan (descformat) String Parameter Type Description descformat Longint Description format: Text or XML Function result String Description of last executed query plan The Get Last Query Plan command returns the internal description of the query plan for the last query carried out on the data. For more information about query descriptions, please refer to the documentation of the DESCRIBE QUERY EXECUTION command. This description is returned in Text or XML format depending on the value passed in the descformat parameter. You can pass one of the following constants, found in the Queries theme: Constant Type Value Description in Text Format Longint 0 Description in XML Format Longint 1 This command returns a significant value if the DESCRIBE QUERY EXECUTION command has been executed during the session. 4D v11 SQL Release 1 (11.1) Addendum 3
4D v11 SQL Release 1 (11.1) Addendum The description of the last query plan can be compared to the description of the actual path of the last query (obtained using the Get Last Query Path command) for optimization purposes. For more information, please refer to the description of the DESCRIBE QUERY EXECUTION command. Get Last Query Path Get Last Query Path (descformat) String Parameter Type Description descformat Longint Description format: Text or XML Function result String Description of last executed query path The Get Last Query Path command returns the detailed internal description of the actual path of the last query carried out on the data. For more information about query descriptions, please refer to the documentation of the DESCRIBE QUERY EXECUTION command. This description is returned in Text or XML format depending on the value passed in the descformat parameter. You can pass one of the following constants, found in the Queries theme: Constant Type Value Description in Text Format Longint 0 Description in XML Format Longint 1 This command returns a significant value if the DESCRIBE QUERY EXECUTION command has been executed during the session. The description of the last query path can be compared to the description of the query plan provided for the last query (obtained using the Get Last Query Plan command) for optimization purposes. For more information, please refer to the description of the DESCRIBE QUERY EXECUTION command. SQL Engine The new features described in this paragraph concern the integrated SQL engine of 4D. 4 4D v11 SQL Release 1 (11.1) Addendum
SQL Engine Handling Character Case A new preference can be used to modify the way character cases are handled in SQL queries: Case-sensitive String Comparison. This option is found on the SQL/Configuration page of the Preferences: New option This option is checked by default, which means that the SQL engine differentiates between upper and lower case when comparing strings (sorts and queries). For example ABC = ABC but ABC # Abc. In certain cases, for example so as to align the functioning of the SQL engine with that of the 4D engine, you may wish for string comparisons to not be case-sensitive ( ABC = Abc ). To do so, you can simply uncheck this option. New Selector for SET DATABASE PARAMETER and Get Database Parameter The case-sensitive option for the SQL engine can be set and read by programming using the SET DATABASE PARAMETER and Get database parameter commands. For this purpose, a new selector has been added: Selector = 44 (SQL Engine Case Sensitivity) Possible values: 0 or 1 (0 = case not taken into account, 1 = case-sensitive) Description: Activates or deactivates case-sensitivity for string comparisons carried out by the SQL engine. 4D v11 SQL Release 1 (11.1) Addendum 5
4D v11 SQL Release 1 (11.1) Addendum Referencing Pointer Type Expressions It is now possible to reference pointer type expressions directly (dereferenced or not) in SQL queries. Passing a variable via a dereferenced pointer: C_LONGINT($vLongint) C_POINTER($vPointer) $vlongint:=1 $vpointer:=->$vlongint Begin SQL SELECT Col1 FROM TEST WHERE Col1=:$vPointer->; End SQL Passing a variable via a pointer that is not dereferenced: C_LONGINT($vLongint) C_POINTER($vPointer) $vlongint:=1 $vpointer:=->$vlongint Begin SQL SELECT Col1 FROM TEST WHERE Col1=:$vPointer; End SQL This works with all types of SQL queries: ODBC commands, Begin/End SQL tags and the QUERY BY SQL command. Note Only one pointer level is taken into account; pointers that reference other pointers cannot be used. Unicode Menus 4D v11 SQL Release 1 includes several new features concerning the extended support of Unicode. In a 4D application, menus and their items can now be displayed in Unicode. This means that it is possible to use, for example, Japanese and Greek characters in the same menu. This new feature concerns all types of menus, whether they were created by the Menu bar editor or by programming. Of course this function is only available when Unicode mode is activated in the database. 6 4D v11 SQL Release 1 (11.1) Addendum
Unicode Default Alpha Type Option The Default Alpha Type compilation option on the Design Mode/Compiler page is removed when the database operates in Unicode mode: Compatibility mode (non-unicode) Unicode mode In Unicode mode, the Text type is automatically used. Replace string Replace string (source; oldstring; newstring{; howmany}{; *}}) String Parameter Type Description source String Original string oldstring String Character(s) to replace newstring String Replacement string howmany Number How many times to replace * * If passed: diacritical evaluation Function result String Resulting string The Replace string command now accepts the asterisk * as the last parameter. If you pass this parameter, you indicate that the evaluation of the characters must be diacritical, in other words, it must be case sensitive and take any accented characters into account (a#a, a#à, etc.). This is illustrated in the following examples: vresult:=replace string("crème brûlée";"brulee";"caramel") `vresult is "Crème caramel" vresult:=replace string("crème brûlée";"brulee";"caramel";*) `vresult is "Crème brûlée" 4D v11 SQL Release 1 (11.1) Addendum 7
4D v11 SQL Release 1 (11.1) Addendum 4D View In the new version of the 4D View plug-in, the display and entry of characters is now carried out in Unicode. This mode is active regardless of the state of the Unicode option of 4D. 4D View v11.1 can open documents created with previous versions. However, 4D View documents created with version 11.1 cannot be reopened with version 11 or 2004.x. Other New Features Quick Reports and Print Settings To maintain the consistency of your interfaces, 4D has now made the pring settings uniform for both quick report areas and those of the application. In previous versions of 4D, the print settings for quick report areas were stored separately for each report. Any modifications of 4D print settings were not carried over to quick reports and vice versa. Beginning with version 11.1, the print settings are always identical in 4D and in the quick report areas. Any changes made to 4D print settings are carried out in those of the quick reports. Conversely, when loading a quick report, the print settings of the report replace those of 4D. Coordinates for Clicks on a Picture 4D now lets you retrieve the local coordinates of a click on a picture field or variable, even if a scroll or zoom has been applied to the picture. The click coordinates are returned in the MouseX and MouseY system variables. The coordinates are expressed in pixels with respect to the top left corner of the picture (0,0). You must get the value of these variables as part of the On Clicked or On Double Clicked form event. In order for this mechanism to work properly, the display format must be set to Truncated (non-centered). This mechanism, similar to that of a picture map, can be used, for example, to handle scrollable button bars or the interface of cartography software. 8 4D v11 SQL Release 1 (11.1) Addendum