|
This section explains the tasks that you perform with SQL Editor. The tasks are divided into the following categories:
Note
If you use SQL Editor to change the structure of table with SQL statements, refresh the Pervasive PSQL Explorer to see the change. Right-click on the Tables node in Pervasive PSQL Explorer then click Refresh.
General tasks orient you to the overall use of SQL Editor.
Execution tasks apply to the running of SQL statements.
Grid tasks apply to working with the Grid window.
Text view tasks apply to working with the Text window.
Outline view tasks apply to working with the Outline window.
Common SQL Object tasks apply to working with triggers, stored procedures, user-defined functions, and views.
To start SQL Editor for a new SQL query
The Select Database dialog appears.
Note
The option None is selected by default if an object other than a database, or any of the nodes subordinate to a database, is selected in Pervasive PSQL Explorer.
Note that the commands to execute SQL statements are disabled if None is specified as the context. See To set database context for an SQL query .
SQL Editor appears as a new window view in PCC. By default, PCC names the new document SQLDocn, where n is an integer that starts with 1 and increments by 1. The document name appears in the tab for SQL Editor.
To start SQL Editor by displaying all records in a table
By default, PCC open SQL Editor and executes a SELECT * FROM statement for the table. Note that the SELECT statement can fail depending on user and column-level permissions.
To set database context for an SQL query
Note that the commands to execute SQL statements are disabled until a database is specified as the context to which the SQL statement applies.
To identify editor settings for SQL Editor

|
Block
|
Meaning
|
|---|---|
|
1
|
Identifies whether SQL Editor accepts character input (Writable).
|
|
2
|
Indicates whether the editor is in insert mode or overwrite mode for character input. The Insert key toggles the mode. Note that the cursor changes shape for each mode.
|
|
3
|
Indicates the row and column at which the cursor is positioned. The first value represents the row, the second the column. In the image above, the cursor is positioned on the first row at the first character position.
|
|
4
|
Identifies the computer and the database to which the SQL document applies. The computer name is listed first followed by the database name. In the image above, the computer is "tment" and the database is "DEMODATA."
Note: If None is specified as the database context, then the text "No Database Selected" appears instead of the name of the computer and database. The commands to execute SQL statements are disabled if None is specified. See To set database context for an SQL query .
|
To create an SQL query or script
By default, when you start SQL Editor, you may type in SQL statements. A script is one or more SQL statements saved as a text file.
Separate SQL statements with a delimiter. You can use the pound sign (#) or the semicolon (;).
To open an SQL script
A script is one or more SQL statements saved as a text file. You can execute the statements in SQL Editor after you open a script in the editor.
To select an SQL statement separator

Note
Based on the separator option you select, PCC looks for the selected character(s) and identifies each as the end of a statement. It sends each identified statement to the database engine and displays results of that statement before sending the next statement.If you use # as a separator in a script but do not select the # (Pound) option, you will receive an error message when you run the script.
If you do not select ; (Semicolon) as a separator, but use a semicolon as a separator in a script anyway, you will not receive an error message if the statements are properly parsed. This is because the database engine recognizes semicolons as separators. However, PCC will not display the results for all the statements. It will only display results for one statement (probably the first statement). As far as PCC is concerned, if you don't select a semicolon as a separator, statements separated by a semicolon are a single statement.
To type comments into SQL Editor
Single-line comments are indicated by double dashes (--) or double slashes (//). Each comment must be on a separate new line or after the statement separator on an existing line.
SQL Editor also supports the use of a start/end comment block that can span multiple lines (/* */).
The following example shows valid comments.
SELECT * FROM t1#
-- This is a valid comment
// and so is this
SELECT * FROM t2# -- This is valid after the # sign
The following example shows multi-line comments.
SELECT * FROM t1# -- single line comment
/* This is a comment block that spans two lines.
Statements inside this block are ignored */
SELECT * FROM t2#
To cancel (undo) or restore (redo) typing actions in SQL Editor
To find text or replace text in SQL Editor
To select text in SQL Editor
To perform basic editing functions in SQL Editor
To enable the execution commands and icons for SQL statements
To run a single SQL statement in SQL Editor
To run selected SQL statements in SQL Editor
To run all SQL statements in SQL Editor
To run SQL statements in Outline view
To execute one or more statements, click on the desired statement(s).
Note that you can select multiple statement by using Ctrl+click. The statements do not have to be contiguous.
To change data within the Grid
Tip
By default, the entire contents becomes selected when you click the cell. Press Delete or Backspace to delete the entire contents of the cell.
Caution
Moving the cursor from the cell automatically saves the data changes to physical storage. You cannot explicitly save the changes made to the cell.
To add rows of data to the Grid
Tip
You can copy data from Grid cells and paste it into the Value cells. Click on a Grid cell then right-click. Click Copy. Click on a Value cell on the Add Rows dialog then right-click. Click Paste. Also note that Ctrl+C and Ctrl+V provide the copy and paste actions, respectively.
The record is added to the table. Also note that the option Refresh Grid on Exit becomes enabled.
If you want to add multiple records, you can change values for specific value cells then click Add. If you want to clear all of the value cells, click Reset.

When you close the Add Rows dialog, a refresh re-executes the statement last executed in SQL Editor.
If Refresh Grid on Exit is enabled, the Grid displays the record(s) that you just added (assuming that the last statement executed in SQL Editor was SELECT * FROM Billing).

To delete row(s) of data from the Grid
Caution
Deleting a row from the Grid removes that record from physical storage. No undo feature is available to reclaim the deleted record.
To enter a date, time, or timestamp data type in the Grid using scalar functions
|
Data Type
|
Scalar Function1 As Typed in Grid Cell
|
|---|---|
|
Date
|
|
|
Time
|
|
|
Timestamp
|
See also NOW ( ) in SQL Engine Reference.
|
|
1 The names are case insensitive. NOW() and now() are equivalent. The parentheses are required. That is, NOW is invalid but NOW() is valid.
|
|
Note
You can also omit the seconds for a time data type provided that you include "AM" or "PM." For example, 10:30 AM is a valid entry. Time defaults to "AM" if you omit "AM" or "PM." For example, 10:30:00 is entered as 10:30:00 AM.
To refresh data in the Grid
To copy data from the Grid
Note
When you copy an entire row or multiple rows, the rows are pasted in the same layout as they appear in the Text window view. You can specify the number of characters between the pasted columns. Click Window then expand the Pervasive node in the Preferences tree. Click Text Output in the tree and set the desired value for Number of spaces between columns.
To clear results from Text view
To select and copy text from Text view
See also To run SQL statements in Outline view .
To minimize, maximize, or restore Outline view size
Common SQL objects include triggers, stored procedures, user-defined functions, and views.
To create a common SQL object
A new SQL Editor is opened that contains a default name for the object on a tab. The name is in the form object_n, where object is the name of the object and n is an integer that starts with one and increments by one. For example, if you create a new view, a new SQL Editor contains a tab named "View_1." After you save the object with a name of your choice, the tab reflects the saved name.
Tip
Hover the mouse cursor on the statement to obtain a tool tip on the syntax, which also includes an example.
To modify a common SQL object
A new SQL Editor is opened that contains a tab. The tab name reflects the name by which you saved the object.
To delete a common SQL object
|
Chapter contents
Prev topic: SQL Editor Used in SQL View Tab of Table Editor
|