来自:walkdan 时间:1998-11-28 下午 01:49:42 ID:93438
I can give you a brief description of what and how it works, but u'd better read manual book of interbase to understand clearly and deeply.
-----------------------------------------------------------
domain:A domain specifies a data type, and a set of column attributes and constraints.
Example : How to create a domain
CREATE DOMAIN myDataType
AS CHAR(5)
CHECK (VALUE = UPPER (VALUE));
-----------------------------------------------------------
table - A table is a data structure consisting of an unordered set of horizontal rows, each containing the same number of vertical columns.
Example : How to create a table
CREATE TABLE myTable(
userid AS INTEGER,
username AS myDataType,
address AS CHAR(40),
PRIMARY KEY (userid)
)
-----------------------------------------------------------
view - A view is a virtual table that is not physically stored in the database, but appears exactly like a "real" table.
Example: How to create a view
CREATE VIEW view_user_address (user_id) AS
SELECT address FROM myTable WHERE userid=user_id
You can use following statements to get user id 1's address
SELECT address FROM view_user_address(1)
-----------------------------------------------------------
procedure - such as function of Delphi, A internal function that can be defined in SQL and can directly be invoked in SQL statement and other system such as Delphi, VB.
Example: Create a procedure
/* delete user from myTable */
CREATE PROCEDURE delete_user(user_id AS INTEGER) AS
DELETE myTable WHERE user_id=:user_id
END;
Example : call procedure
/* call procedure delete_user to delete user 1 */
....
EXECUTE PROCEDURE delete_user(1);
...
-----------------------------------------------------------
function - A function is a User-defined functions(UDF) that created by other language. The function of Interbase is so limited that you must use UDF to perform special requests.
Example : How to defined a function
/*
* Function ADDRTONAME
* addrToName resolve the IP address to DNS address
*/
DECLARE EXTERNAL FUNCTION ADDRTONAME
CSTRING(32)
RETURNS CSTRING(254)
ENTRY_POINT "addrToName" MODULE_NAME
"/home/Project/NetCharge/bin/lib/libaddrToName.so"
/* in you C program you can write:
(char *) addrToName((char *) ip){
return = gethostbyAddress(ip);
}
-----------------------------------------------------------
generator - A generator is a mechanism that creates a unique, sequential number that is automatically inserted into a column by the database when SQL data manipulation operations such as INSERT or UPDATE occur.
Example: How to create a generator
CREATE GENERATOR userid_gen;
SET TERM ^ ;
CREATE TRIGGER CREATE_userid FOR myTable
BEFORE INSERT
POSITION 0
AS BEGIN
NEW.userid = GEN_ID(userid_gen, 1);
END
SET TERM ; ^
----------------------------------------------------------
exception - An exception is a named error message that can be raised from a trigger or a stored procedure.
Example : How to create a exception
/*Create exception unknow_userid:*/
CREATE EXCEPTION unknow_userid "Invalid user ID number ";
/*The following statement from a stored procedure raises the previously set exception when SQLCODE -530 is set, which is a violation of a FOREIGN KEY constraint.*/
. . .
WHEN SQLCODE -530 DO
EXCEPTION unknow_userid;
. . .
----------------------------------------------------------
Blob Filters - A BLOB filter is a routine that translates BLOB data from one subtype to another.
You cannot using blob Filters in your SQL statments directly.
Blob Filter is User-defined functions (UDFs) that written by other langruage such as C, C++. You could write a blob Filter routing using C, and you may use DECLARE FILTER statement to invoke to filter routing which you defined.
Example : defined a text_fileter filter which perform a special
function.
DECLARE FILTER BLOB_FORMAT
INPUT_TYPE 1 OUTPUT_TYPE -99
ENTRY_POINT "Text_filter" MODULE_NAME "myFilterModule";