### SQL UPDATE Examples Source: https://www.componentace.com/help/absdb_manual/updatestatement Illustrates how to use the UPDATE command with different scenarios. Examples include simple value assignment, updating with a scalar subquery, and updating multiple columns using a row subquery. ```sql UPDATE MyTable SET val2 = 'Many' WHERE val1 > 2; ``` ```sql UPDATE Events e SET Ticket_price = (SELECT Capacity FROM Venues WHERE VenueNo=e.VenueNo)*2 WHERE Ticket_price <= 5 ``` ```sql UPDATE Orders SET (ShipToAddr1,ShipToAddr2) = (SELECT Addr1, Addr2 FROM Customer WHERE CustNo=Orders.CustNo) WHERE CustNo IN (1221, 2156) ``` -------------------------------- ### Create Table Example using ABSDatabase and ABSTable Components Source: https://www.componentace.com/help/absdb_manual/createtableexample This code demonstrates how to configure and create a database and a table using ABSDatabase and ABSTable components. It includes setting database properties, defining table fields with their types and lengths, and specifying table indexes. The code also includes checks to ensure the database and table are created only if they do not already exist. ```Pascal ABSDatabase1.DatabaseName := 'emp_db'; ABSDatabase1.DatabaseFileName := 'c:\data\employee_db.abs'; ABSTable1.DatabaseName := 'emp_db'; ABSTable1.TableName := 'employee'; with ABSTable1 do begin with FieldDefs do begin Clear; Add('EmpNo',ftAutoInc,0,False); Add('LastName',ftString,20,False); Add('FirstName',ftString,15,False); Add('PhoneExt',ftString,4,False); Add('HireDate',ftDate,0,False); Add('Salary',ftCurrency,0,False); end; with IndexDefs do begin Clear; Add('idxPrimary','EmpNo',[ixPrimary]); Add('idxByLastNameFirstName','LastName;FirstName',[ixCaseInsensitive]); end; end; with ABSDatabase1 do if not Exists then CreateDatabase; with ABSTable1 do if not Exists then CreateTable; ``` -------------------------------- ### Starting a Database Transaction (Pascal) Source: https://www.componentace.com/help/absdb_manual/tabsdatabase_starttransaction Initiates a new transaction against the TABSDatabase. Ensure InTransaction is false before calling to prevent exceptions. Changes are pending until Commit or Rollback is called. ```Pascal procedure StartTransaction; // Description: // Call StartTransaction to begin a new transaction against the database. // Before calling StartTransaction, an application should check the status of the InTransaction property. // If InTransaction is true, indicating that a transaction is already in progress, a subsequent call to StartTransaction without first calling Commit or Rollback to end the current transaction raises an exception. // // Updates, insertions, and deletions that take place after a call to StartTransaction are held by the database engine until an application calls Commit to save the changes or Rollback is to cancel them. // // Note: ReadCommitted isolation level is used in multi-user mode. ``` -------------------------------- ### Exact Match Search using GotoKey Source: https://www.componentace.com/help/absdb_manual/searchingdatasets This example shows how to perform an exact match search on a dataset using the GotoKey method. It first sets the index and then specifies the search criteria before attempting to locate the record. ```delphi procedure TSearchDemo.SearchExactClick(Sender: TObject); begin ABSTable1.IndexName := 'idxByLastNameFirstName'; ABSTable1.SetKey; ABSTable1.Fields[0].AsString := Edit1.Text; if not ABSTable1.GotoKey then ShowMessage('Record not found'); end; ``` -------------------------------- ### Simple CASE Function Example in SQL Source: https://www.componentace.com/help/absdb_manual/conditionalexpressions Demonstrates the simple CASE function in SQL, which compares an input expression to a series of when expressions to return a corresponding result. It supports an optional ELSE clause for a default value. This example maps state abbreviations to full state names. ```SQL SELECT first_name, last_name, CASE state WHEN 'CA' THEN 'California' WHEN 'KS' THEN 'Kansas' WHEN 'TN' THEN 'Tennessee' WHEN 'OR' THEN 'Oregon' WHEN 'MI' THEN 'Michigan' WHEN 'IN' THEN 'Indiana' WHEN 'MD' THEN 'Maryland' WHEN 'UT' THEN 'Utah' END AS StateName FROM clients ORDER BY last_name ``` -------------------------------- ### Control Transactions with SQL Statements Source: https://www.componentace.com/help/absdb_manual/transactions Illustrates how to control database transactions using standard SQL statements. This includes starting a transaction with 'START TRANSACTION', applying changes, and finalizing the transaction with either 'COMMIT' to make changes permanent or 'ROLLBACK' to discard them. This approach is database-agnostic. ```SQL START TRANSACTION; -- Multiple table updates or some other actions -- { ... } COMMIT; -- or ROLLBACK; ``` -------------------------------- ### TDataSet.Prior Method Example (Pascal) Source: https://www.componentace.com/help/absdb_manual/tdataset_prior This code demonstrates the usage of the Prior method in Pascal. It positions the cursor on the previous record of a TDataSet object. ```Pascal procedure TMyDataModule.MoveToPreviousRecord(DataSet: TDataSet); var PreviousRecordExists: Boolean; begin PreviousRecordExists := not DataSet.Bof; if PreviousRecordExists then begin DataSet.Prior; // Perform actions with the previous record // For example, update UI elements end else begin // Handle the case where there is no previous record ShowMessage('Already at the beginning of the dataset.'); end; end; ``` -------------------------------- ### ABSDB Table Creation with AutoInc and Blob Settings (SQL) Source: https://www.componentace.com/help/absdb_manual/createtablestatement Example of creating a 'developers' table in ABSDB, showcasing AutoInc column with specified Blob settings like BlobCompressionMode, BlobBlockSize, and BlobCompressionAlgorithm. ```sql CREATE TABLE developers ( ID AutoInc, Code Integer, Name Char(20), Birthday Date, Photo Graphic BlobCompressionMode 1 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib ); ``` -------------------------------- ### Copy Table to Same Database - ABSTable Component Source: https://www.componentace.com/help/absdb_manual/copyingtables This example demonstrates how to copy a table to the same database file using the ABSTable component. It involves setting the DatabaseName and TableName properties and then calling the CopyTable method without a second parameter. ```pascal ABSTable1.DatabaseName := 'emp_db'; ABSTable1.TableName := 'employee'; ABSTable1.CopyTable('new_employee'); ``` -------------------------------- ### POWER(base, exponent) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns base raised to the exponent power. Example: POWER(3,2) returns 9. ```APIDOC ## POWER(base, exponent) ### Description The power function returns base raised to the exponent power. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **base** (numeric) - Required - The base number. - **exponent** (numeric) - Required - The exponent to which the base is raised. ### Request Example ``` POWER(3, 2) ``` ### Response #### Success Response (200) - **result** (numeric) - The result of base raised to the exponent power. #### Response Example ``` 9 ``` ``` -------------------------------- ### SQL INSERT Statement with Named Parameters Source: https://www.componentace.com/help/absdb_manual/usingparametersinqueries An example of an SQL INSERT statement utilizing named parameters for specifying values. Parameters are prefixed with a colon (:) to distinguish them from literal values and are replaced by application-supplied values at runtime. ```sql INSERT INTO Country (Name, Capital, Population) VALUES (:Name, :Capital, :Population) ``` -------------------------------- ### AppendRecord Procedure Example (Delphi) Source: https://www.componentace.com/help/absdb_manual/tdataset_appendrecord Demonstrates the usage of the TDataSet.AppendRecord procedure to add a new record to a dataset. This procedure is commonly used in Delphi applications for database manipulation. ```Delphi procedure TMyDataModule.AddUserRecord; var NewRecord: TBookRec; begin // Assuming MyDataSet is a TDataSet descendant MyDataSet.AppendRecord([ 'John Doe', 30, 'New York' ]); // The record is automatically posted to the database. // The newly appended record becomes the active record. end; ``` -------------------------------- ### SQL: CREATE TABLE with Autoinc Options Source: https://www.componentace.com/help/absdb_manual/createtablestatement This example illustrates how to define an auto-incrementing column within a table creation statement. It showcases options for specifying the auto-increment data type, increment value, initial value, and range. ```sql CREATE TABLE [ IF NOT EXISTS ] [ MEMORY ] _table_name_ ( _column_name_ _data_type_ (_autoinc_data_type_ [ INCREMENT _increment_value_ ] [ INITIALVALUE _start_value_ ] [ MAXVALUE _max_value_] [ MINVALUE _min_value_] [ CYCLED | NOCYCLED ]) [ NOT NULL | NULL ] ... ); ``` -------------------------------- ### COUNT(*) Function Example - SQL Source: https://www.componentace.com/help/absdb_manual/aggregatefunctions Shows the COUNT(*) function, which returns the total number of rows in a selected set, regardless of NULL values. This is commonly used to get the total record count. ```sql SELECT COUNT(*) FROM employee ``` -------------------------------- ### SQL SELECT Statement Examples Source: https://www.componentace.com/help/absdb_manual/selectstatement Demonstrates basic and advanced usage of the SQL SELECT statement, including selecting all columns, specific columns, calculated columns, and using the INTO clause to create a new table. Supports correlated and uncorrelated subqueries. ```SQL SELECT TOP 10,20 * FROM employee /* returns rows 20-29 */ ``` ```SQL SELECT FirstName, LastName FROM employee ``` ```SQL SELECT Price * Quantity AS Total FROM orders ``` ```SQL SELECT DISTINCT FirstName INTO names FROM employee ``` -------------------------------- ### Extract Substring from String Source: https://www.componentace.com/help/absdb_manual/stringfunctions The SUBSTRING function extracts a portion of a string. It requires the string expression, a starting position, and optionally, the length of the substring to extract. For example, SUBSTRING('ABCDE', 4, 2) returns 'DE'. ```sql SELECT SUBSTRING('ABCDE', 4, 2); ``` -------------------------------- ### Get Length of String Source: https://www.componentace.com/help/absdb_manual/stringfunctions The LENGTH function returns the total number of characters in a given string expression. It takes one argument: the string whose length is to be determined. For example, LENGTH('ABCEDFG') returns 7. ```sql SELECT LENGTH('ABCEDFG'); ``` -------------------------------- ### SQL: Basic CREATE TABLE Syntax Source: https://www.componentace.com/help/absdb_manual/createtablestatement This snippet demonstrates the fundamental syntax for creating a table with columns and an optional primary key. It includes basic column definitions with data types and constraints. ```sql CREATE TABLE [ IF NOT EXISTS ] [ MEMORY ] _table_name_ ( _column_name_ _data_type_ [ NOT NULL | NULL ] [ DEFAULT _default_value_ ] [ MINVALUE _min_value_ | NOMINVALUE ] [ MAXVALUE _max_value_ | NOMAXVALUE ] [ { PRIMARY [KEY] | UNIQUE } [ ASC | DESC ] [ CASE | NOCASE ] [, PRIMARY [ KEY ] [_index_name_] ( _column_name_ [ ASC | DESC ] [ CASE | NOCASE ] [, ... ] ) ] [, [ UNIQUE ] [INDEX] [_index_name_] ( _column_name_ [ ASC | DESC ] [ CASE | NOCASE ] [, ... ] ) ] [, ... ] ); ``` -------------------------------- ### Find Position of Substring Source: https://www.componentace.com/help/absdb_manual/stringfunctions The POS function returns the starting position of the first occurrence of a substring within a larger string. It takes two arguments: the substring to find and the string to search within. For example, POS('CDE', 'ABCDEFG') returns 3. ```sql SELECT POS('CDE', 'ABCDEFG'); ``` -------------------------------- ### TABSAdvIndexDef.Options Source: https://www.componentace.com/help/absdb_manual/tabsadvindexdef_options Explains the use of the Options property for index creation and inspection. ```APIDOC ## TABSAdvIndexDef.Options ### Description Describes the characteristics of the index. When creating a new index, use Options to specify the attributes of the index. Options can contain zero or more of the TIndexOption constants ixPrimary, ixUnique, ixDescending, ixCaseInsensitive. When inspecting the definitions of existing indexes, read Options to determine the option(s) used to create the index. ### Property - **Options** (TIndexOptions) - Describes the characteristics of the index. ``` -------------------------------- ### MAX Function Example - SQL Source: https://www.componentace.com/help/absdb_manual/aggregatefunctions Provides an example of the MAX function, used to retrieve the highest value from a numeric or character column or expression. Useful for finding maximum values in datasets. ```sql SELECT MAX(commission_rate) FROM sales_rep_tbl ``` -------------------------------- ### Use Query Parameters for Date Insertion (Pascal) Source: https://www.componentace.com/help/absdb_manual/formats Demonstrates the recommended method of using query parameters to insert date values into an SQL query. This approach bypasses string conversion issues and is generally safer for handling date/time data. ```Pascal ABSQuery1.SQL.Text := 'INSERT INTO Orders (ID, BillDate) VALUES (2, :BillDate)'; ABSQuery1.Params[0].AsDateTime := Date; ``` -------------------------------- ### COALESCE Function Examples in SQL Source: https://www.componentace.com/help/absdb_manual/conditionalexpressions Showcases the COALESCE function, which returns the first non-NULL expression from a list of expressions. This is helpful for providing default values when a field might be null. Examples include returning a specific number and a default string. ```SQL COALESCE(NULL, 34, 13) ``` ```SQL COALESCE(FirstName, 'N/A') ``` -------------------------------- ### OpenDatabase Method - Pascal Source: https://www.componentace.com/help/absdb_manual/tabssession_opendatabase Opens an existing database or creates a temporary one. It connects to a database, manages database components, and increments the session's database reference count. Accepts a DatabaseName string as input and returns a TABSDatabase object. ```Pascal function OpenDatabase(const DatabaseName: String): TABSDatabase; ``` -------------------------------- ### Set up and Open Database Table in Delphi Source: https://www.componentace.com/help/absdb_manual/openingtables Configures the TABSDatabase and TABSTable components and opens the table. It includes checks for the existence of the database and table before attempting to open. This code is intended for use in a Delphi environment. ```Delphi ABSDatabase1.DatabaseName := 'emp_db'; ABSDatabase1.DatabaseFileName := 'c:\data\employee_db.abs'; ABSTable1.DatabaseName := 'emp_db'; ABSTable1.TableName := 'employee'; if (not ABSDatabase1.Exists) then raise Exception.Create('Database file does not exist'); if (not ABSTable1.Exists) then raise Exception.Create('Table "employee" does not exist'); ABSTable1.Active := True; ``` -------------------------------- ### COS(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns the cosine of a number. Example: COS(-3.15) returns -0.999964658471342. ```APIDOC ## COS(numeric_exp) ### Description The cos function returns the cosine of a number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The angle (in radians) for which to return the cosine. ### Request Example ``` COS(-3.15) ``` ### Response #### Success Response (200) - **result** (numeric) - The cosine of the input angle. #### Response Example ``` -0.999964658471342 ``` ``` -------------------------------- ### ATAN(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns the arctangent of a number. Example: ATAN(0) returns 0. ```APIDOC ## ATAN(numeric_exp) ### Description Returns the arctangent of a number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number for which to return the arctangent. ### Request Example ``` ATAN(0) ``` ### Response #### Success Response (200) - **result** (numeric) - The arctangent of the input number. #### Response Example ``` 0 ``` ``` -------------------------------- ### SQL: CREATE TABLE with BLOB Settings Source: https://www.componentace.com/help/absdb_manual/createtablestatement This snippet shows how to configure BLOB (Binary Large Object) settings for a column when creating a table. It includes options for block size, compression algorithm, and compression mode. ```sql CREATE TABLE [ IF NOT EXISTS ] [ MEMORY ] _table_name_ ( _column_name_ _data_type_ [ BLOBBLOCKSIZE {1..4294967295} ] [ BLOBCOMPRESSIONALGORITHM {NONE | ZLIB | BZIP | PPM} ] [ BLOBCOMPRESSIONMODE {1 .. 9} ] ... ); ``` -------------------------------- ### SQL FROM Clause with Joins Source: https://www.componentace.com/help/absdb_manual/selectstatement Illustrates the FROM clause in SQL, which specifies the data sources for a SELECT query. This includes referencing tables, subqueries, and using various join types (INNER, LEFT, RIGHT, FULL, CROSS) to combine data from multiple tables. ```SQL FROM employee AS e ``` ```SQL FROM "my_database.db".my_table AS t PASSWORD 'secret_password' ``` ```SQL FROM (SELECT * FROM orders) AS subquery ``` ```SQL FROM table1 INNER JOIN table2 ON table1.id = table2.id ``` ```SQL FROM table1 LEFT OUTER JOIN table2 USING (id) ``` ```SQL FROM table1 RIGHT JOIN table2 ON table1.id = table2.id ``` ```SQL FROM table1 FULL JOIN table2 ON table1.id = table2.id ``` ```SQL FROM table1 CROSS JOIN table2 ``` -------------------------------- ### Create Absolute DB Database Programmatically (Pascal) Source: https://www.componentace.com/help/absdb_manual/creatingdatabases This code demonstrates how to create an Absolute DB database file programmatically using the TABSDatabase component. It sets the database name and file name, checks if the database exists, and creates it if it doesn't. Ensure the path for the database file is accessible. ```Pascal ABSDatabase1.DatabaseName := 'emp_db'; // unique name used further to identify db ABSDatabase1.DatabaseFileName := 'c:\data\employees.abs'; if (not ABSDatabase1.Exists) then ABSDatabase1.CreateDatabase; ``` -------------------------------- ### LOG(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns the natural logarithm of a number. Example: LOG(20) returns 2.99573227355399. ```APIDOC ## LOG(numeric_exp) ### Description The log function returns the natural logarithm of a number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number for which to return the natural logarithm. ### Request Example ``` LOG(20) ``` ### Response #### Success Response (200) - **result** (numeric) - The natural logarithm of the input number. #### Response Example ``` 2.99573227355399 ``` ``` -------------------------------- ### ABS(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns the absolute value of a number. Example: ABS(-2.9) returns 2.9. ```APIDOC ## ABS(numeric_exp) ### Description Returns the absolute value of a number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number for which to return the absolute value. ### Request Example ``` ABS(-2.9) ``` ### Response #### Success Response (200) - **result** (numeric) - The absolute value of the input number. #### Response Example ``` 2.9 ``` ``` -------------------------------- ### Delphi Example: Executing a Query with Named Parameters Source: https://www.componentace.com/help/absdb_manual/usingparametersinqueries A Delphi code snippet demonstrating how to execute a SQL query with a named parameter. It shows setting the database name, the SQL text with a parameter (:FirstName), assigning a value to the parameter, and opening the dataset. ```delphi with ABSQuery1 do begin DatabaseName := 'emp_db'; SQL.Text := 'select * from employee where FirstName=:FirstName'; Params[0].AsString := 'Leslie'; Open; end; ``` -------------------------------- ### MIMETOBIN Function for MIME to Binary Conversion Source: https://www.componentace.com/help/absdb_manual/dataconversionfunctions The MIMETOBIN function converts MIME-encoded data to a binary data type. It accepts a MIME-encoded expression as input. An example demonstrates its basic usage with a placeholder for MIME-encoded data. Refer to the DBManager utility for examples of MIME-encoded binary data in SQL commands. ```SQL MIMETOBIN('') ``` -------------------------------- ### Mathematical Functions Overview Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions This section provides a list of all supported mathematical functions and a brief description of each. ```APIDOC ## Mathematical Functions Overview ### Description Lists the available mathematical functions and their general purpose. ### Functions - **ABS**: Returns the absolute value of a number. - **ACOS**: Returns the inverse cosine of a given number. - **ASIN**: Returns the inverse sine of a given number. - **ATAN**: Returns the arctangent of a number. - **CEIL**: Rounds variables up toward positive infinity. - **COS**: Returns the cosine of an angle. - **EXP**: Returns the exponential of a number. - **FLOOR**: Rounds variables toward negative infinity. - **LOG**: Returns the natural log of a real expression. - **POWER**: Raises Base to any power. - **RAND**: Generates random numbers within a specified range. - **ROUND**: Returns the value of a number rounded to the specified length or precision. - **SIGN**: Indicates whether a numeric value is positive, negative, or zero. - **SIN**: Returns the sine of the angle in radians. - **SQR**: Returns the square of a number. - **SQRT**: Returns the square root of a number. ### Request Example N/A ### Response Example N/A ``` -------------------------------- ### SIGN(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns a value indicating the sign of a number. Example: SIGN(10) returns 1. ```APIDOC ## SIGN(numeric_exp) ### Description The sign function returns a value indicating the sign of a number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number for which to determine the sign. ### Request Example ``` SIGN(10) SIGN(-5) SIGN(0) ``` ### Response #### Success Response (200) - **result** (integer) - Returns 1 if the number is positive, -1 if negative, and 0 if zero. #### Response Example ``` 1 ``` ``` -------------------------------- ### ASIN(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns the inverse sine of a given number. Example: ASIN(0) returns 0. ```APIDOC ## ASIN(numeric_exp) ### Description Returns the inverse sine of a given number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number for which to return the inverse sine. ### Request Example ``` ASIN(0) ``` ### Response #### Success Response (200) - **result** (numeric) - The inverse sine of the input number. #### Response Example ``` 0 ``` ``` -------------------------------- ### TDataSet.Create Constructor Source: https://www.componentace.com/help/absdb_manual/tdataset_create Explains how to create an instance of a TDataSet component at runtime. Note that TDataSet itself is abstract and intended for use via its descendants. ```APIDOC ## TDataSet.Create Constructor ### Description Creates an instance of a TDataSet component. This constructor is intended for internal use and for creating descendants of TDataSet, as TDataSet itself is an abstract base class and cannot be directly instantiated in applications. ### Method constructor ### Endpoint N/A (This is a class constructor, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```delphi // This is a conceptual example, as TDataSet is abstract. // You would typically use descendants like TClientDataSet, TTable, TQuery. var MyDataSet: TDataSet; begin MyDataSet := TDataSet.Create(Self); // Incorrect usage: TDataSet is abstract // ... MyDataSet.Free; end; ``` ### Response #### Success Response (200) N/A (This is a constructor, not an API endpoint) #### Response Example N/A ``` -------------------------------- ### ACOS(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns the inverse cosine of a given number. Example: ACOS(1) returns 0. ```APIDOC ## ACOS(numeric_exp) ### Description Returns the inverse cosine of a given number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number for which to return the inverse cosine. ### Request Example ``` ACOS(1) ``` ### Response #### Success Response (200) - **result** (numeric) - The inverse cosine of the input number. #### Response Example ``` 0 ``` ``` -------------------------------- ### ABSDB Table Creation with Configured AutoInc (SQL) Source: https://www.componentace.com/help/absdb_manual/createtablestatement Demonstrates creating a 'test' table in ABSDB with a specifically configured AutoInc column, including data type, initial value, increment, max value, min value, and cycling behavior. ```sql CREATE TABLE test ( id AutoInc(Byte, INITIALVALUE 3, INCREMENT 3, MAXVALUE 7 minvalue 2 CYCLED), s String(100) ); ``` -------------------------------- ### Delphi: SetRange Procedure for TABSTable Source: https://www.componentace.com/help/absdb_manual/tabstable_setrange This procedure sets the starting and ending values of a range within a TABSTable dataset and applies it. It internally manages setting the dataset to dsSetKey state, clearing previous ranges, setting new start and end values, and applying the range. This function is optimized for indexed fields and combines the actions of SetRangeStart, SetRangeEnd, and ApplyRange. ```delphi procedure SetRange(const StartValues, EndValues: array of const); var i: Integer; begin // 1. Puts the dataset into dsSetKey state. InternalDatasetState := dsSetKey; // 2. Erases any previously specified starting range values and ending range values. // This is implicitly handled by overwriting or clearing internal range variables. FStartKey.Clear; FEndKey.Clear; // 3. Sets the start and end range values. // If StartValues/EndValues have fewer elements than fields, remaining are set to NULL. for i := 0 to High(StartValues) do FStartKey.Add(StartValues[i]); for i := 0 to High(EndValues) do FEndKey.Add(EndValues[i]); // 4. Applies the range to the dataset. ApplyRange; end; ``` -------------------------------- ### Set up TABSQuery Component Source: https://www.componentace.com/help/absdb_manual/executingqueries Configures the TABSQuery component by linking it to a TABSDatabase and assigning SQL commands. The RequestLive property determines if the query returns a modifiable record set. ```Delphi ABSQuery1.DatabaseName := 'emp_db'; ABSQuery1.SQL.Text := 'select * from employee'; ABSQuery1.RequestLive := True; ``` -------------------------------- ### FLOOR(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns the largest integer value that is equal to or less than a number. Example: FLOOR(3.67) returns 3. ```APIDOC ## FLOOR(numeric_exp) ### Description The floor function returns the largest integer value that is equal to or less than a number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number to round down. ### Request Example ``` FLOOR(3.67) ``` ### Response #### Success Response (200) - **result** (integer) - The largest integer value less than or equal to the input number. #### Response Example ``` 3 ``` ``` -------------------------------- ### EXP(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns e raised to the nth power, where e = 2.71828183. Example: EXP(3) returns 20.0855369231877. ```APIDOC ## EXP(numeric_exp) ### Description The exp function returns e raised to the nth power, where e = 2.71828183. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The exponent to which e is raised. ### Request Example ``` EXP(3) ``` ### Response #### Success Response (200) - **result** (numeric) - e raised to the power of the input exponent. #### Response Example ``` 20.0855369231877 ``` ``` -------------------------------- ### Fastest Bulk Inserts/Updates with Buffered Transactions (Pascal) Source: https://www.componentace.com/help/absdb_manual/increasingbatchuptaesspeed Demonstrates the recommended method for high-performance batch data insertion using buffered transactions. It involves starting a transaction before the bulk operation and committing it afterward. This approach minimizes overhead and accelerates the process of inserting multiple records. ```Pascal ABSDatabase1.StartTransaction; for i := 1 to 2000 do with ABSTable1 do begin Insert; FieldByName('Name').AsString := 'John'; Post; end; ABSDatabase1.Commit(False); ``` -------------------------------- ### CEIL(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns the smallest integer value that is greater than or equal to a number. Example: CEIL(11.22) returns 12. ```APIDOC ## CEIL(numeric_exp) ### Description The ceil function returns the smallest integer value that is greater than or equal to a number. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number to round up. ### Request Example ``` CEIL(11.22) ``` ### Response #### Success Response (200) - **result** (integer) - The smallest integer value greater than or equal to the input number. #### Response Example ``` 12 ``` ``` -------------------------------- ### Set up TABSDatabase Component Source: https://www.componentace.com/help/absdb_manual/executingqueries Configures the TABSDatabase component by assigning a unique name and specifying the database file. This component is essential for connecting to and managing the database. ```Delphi ABSDatabase1.DatabaseName := 'emp_db'; ABSDatabase1.DatabaseFileName := 'c:\data\employee_db.abs'; ``` -------------------------------- ### RAND(numeric_exp) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Generates random numbers within a specified range. Example: RAND(10) may return 0..9. ```APIDOC ## RAND(numeric_exp) ### Description Generates random numbers within a specified range. Note: The description in the source text appears to be incorrect and describes a string conversion function instead. Assuming it generates random numbers as per the function name and example. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The upper limit (exclusive) for the random number generation. If the input is 10, it might generate numbers between 0 and 9. ### Request Example ``` RAND(10) ``` ### Response #### Success Response (200) - **result** (numeric) - A random number within the specified range. #### Response Example ``` 5 ``` ``` -------------------------------- ### TABSSession.OpenDatabase Source: https://www.componentace.com/help/absdb_manual/tabssession_opendatabase Opens an existing database component, or creates a temporary database component and opens it. The DatabaseName parameter specifies the database to open. ```APIDOC ## TABSSession.OpenDatabase ### Description Opens an existing database, or creates a temporary database component and opens it. The DatabaseName parameter specifies the database to open. ### Method `FUNCTION` ### Endpoint `N/A` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example `N/A` ### Response #### Success Response (TABSDatabase) - **TABSDatabase** (TABSDatabase) - Represents the opened database component. #### Response Example `N/A` ``` -------------------------------- ### Transaction Control Source: https://www.componentace.com/help/absdb_manual/transactions This section details how to control the lifecycle of a transaction, including starting, committing, and rolling back operations. ```APIDOC ## Transaction Control ### Description Applications control transactions mainly by specifying when a transaction starts and ends. This can be specified using either TABSDatabase methods or SQL statements. ### Methods #### Starting a Transaction * **`StartTransaction`**: Initiates a new transaction using the TABSDatabase method. * **`START TRANSACTION`**: Initiates a new transaction using Absolute Database SQL statement. ### Committing a Transaction * **`Commit`**: Guarantees all modifications made within the transaction are made permanent. It also frees resources like locks. * **`COMMIT`**: SQL statement to commit a transaction. * **`DoFlushBuffers`**: Setting this parameter to `false` can improve performance by allowing the OS to perform lazy writes to disk, but it is not recommended for critical data integrity. ### Rolling Back a Transaction * **`Rollback`**: Reverts all modifications made within the transaction, returning the data to its state at the start of the transaction. It also frees resources held by the transaction. * **`ROLLBACK`**: SQL statement to roll back a transaction. * It is recommended to refresh open tables after a rollback to avoid displaying data that has been reverted, ensuring no pending inserts or edits exist on those tables. ### Request Example (Pascal-like Pseudocode) ```pascal with MyABSDatabase do begin StartTransaction; try // Multiple table updates or other actions // ... Commit; except Rollback; end; end; ``` ### Response #### Success Response (200) * **Transaction Status**: Indicates whether the transaction was successfully committed or rolled back. #### Response Example * (No specific response body is detailed, operation is typically confirmed by subsequent data state or lack of errors.) ``` -------------------------------- ### CREATE TABLE Command Source: https://www.componentace.com/help/absdb_manual/createtablestatement This section details the syntax and options for creating a new table. ```APIDOC ## CREATE TABLE Command ### Description Creates a new, initially empty table in the current database. ### Method SQL Command ### Endpoint N/A (Database Command) ### Parameters #### Syntax `CREATE TABLE [ IF NOT EXISTS ] [ MEMORY ] _table_name_ ( _column_definition_ [, ... ] | _index_definition_ [, ... ] )` #### Column Definition `_column_name_ _data_type_ [ _autoinc_options_] [ _blob_settings_] [ NOT NULL | NULL ] [ DEFAULT _default_value_ ] [ MINVALUE _min_value_ | NOMINVALUE ] [ MAXVALUE _max_value_ | NOMAXVALUE ] [ { PRIMARY [KEY] | UNIQUE } [ ASC | DESC ] [ CASE | NOCASE ] ]` #### Autoinc Options `[_autoinc_data_type_] [ INCREMENT _increment_value_ ] [ INITIALVALUE _start_value_ ] [ MAXVALUE _max_value_] [ MINVALUE _min_value_] [ CYCLED | NOCYCLED ]` #### Blob Settings `[ BLOBBLOCKSIZE {1..4294967295} ] [ BLOBCOMPRESSIONALGORITHM {NONE | ZLIB | BZIP | PPM} ] [ BLOBCOMPRESSIONMODE {1 .. 9} ]` #### Index Definition `[ PRIMARY [ KEY ] [ _index_name_ ] ( _column_name_ [ ASC | DESC ] [ CASE | NOCASE ] [, ... ] ) ]` `[ [ UNIQUE ] [INDEX] [_index_name_] ( _column_name_ [ ASC | DESC ] [ CASE | NOCASE ] [, ... ] ) ]` #### Key Word Descriptions - **IF NOT EXISTS**: Creates the table only if a table with the same name does not exist. If not specified and the table exists, an exception is raised. - **MEMORY**: Creates an in-memory table instead of a disk table. - **_table_name_**: The name of the table to be created. - **_column_name_**: The name of a column to be created. - **_data_type_**: The data type of the column. Refer to the Field Data Types topic. - **NOT NULL**: The column cannot contain null values. - **NULL**: The column can contain null values (default). - **DEFAULT _default_value_**: Assigns a default data value for the column. The value must be a constant expression matching the column's data type. - **MINVALUE _min_value_**: Sets the minimum value for the column. The expression must match the column's data type. - **NOMINVALUE**: No restriction on minimum value (default). - **MAXVALUE _max_value_**: Sets the maximum value for the column. The expression must match the column's data type. - **NOMAXVALUE**: No restriction on maximum value (default). - **PRIMARY [KEY]**: Specifies that a column must contain only unique, non-null values. It serves as a unique identifier for rows. - **UNIQUE**: Specifies that all values in the column must be unique. Null values are considered equal for this constraint. - **_autoinc_data_type_**: Data type for auto-increment columns (e.g., Byte, Integer, LargeInteger). - **INCREMENT _increment_value_**: The value added to the next generated auto-increment value. - **INITIALVALUE _start_value_**: The starting value for the auto-increment column. - **MINVALUE _min_value_**: The minimum value for a cycled auto-increment column. - **MAXVALUE _max_value_**: The maximum value for a cycled auto-increment column. - **CYCLED**: Auto-increment values will cycle after reaching their maximum value. - **NOCYCLED**: Auto-increment values will not cycle (default). - **BLOBBLOCKSIZE**: Sets the block size for BLOB data. - **BLOBCOMPRESSIONALGORITHM**: Sets the compression algorithm for BLOB data (NONE, ZLIB, BZIP, PPM). - **BLOBCOMPRESSIONMODE**: Sets the compression mode for BLOB data (1-9). ### Request Example ```sql CREATE TABLE IF NOT EXISTS my_table ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT UNIQUE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); ``` ### Response #### Success Response (200) Table creation is typically a command execution, success is indicated by no error being raised. #### Response Example N/A ``` -------------------------------- ### Create and Add Index Definition (Pascal) Source: https://www.componentace.com/help/absdb_manual/tabsadvindexdefs_add The Add method creates a new index definition and populates its properties based on the provided parameters. It raises an exception if an index with the same name already exists. This procedure is part of the TABSAdvIndexDefs object. ```Pascal procedure Add(const Name, Fields: String ; Options: TIndexOptions; DescFields: string = ''; CaseInsFields: string = ''; MaxIndexedSizes: string = ''); ``` -------------------------------- ### ABSDB INSERT Statement Examples Source: https://www.componentace.com/help/absdb_manual/insertstatement Demonstrates various ways to use the INSERT statement in ABSDB. This includes inserting a single row with specified columns and values, inserting multiple rows with explicit values, and inserting data from a SELECT query. It highlights the flexibility of populating tables. ```SQL INSERT INTO developers (code, name) VALUES (5, 'Bob'); ``` ```SQL INSERT INTO developers (code, name) VALUES (5, 'Bob'), (6,'John'); ``` ```SQL INSERT INTO new_developers (SELECT * FROM developers WHERE code > 5) ``` -------------------------------- ### ROUND(numeric_exp, [decimals = 0 [, rounding_mode = HalfEven]]) Source: https://www.componentace.com/help/absdb_manual/arithmeticfunctions Returns a number rounded to the specified length or precision. Supports various rounding modes. Example: ROUND(4.56, 1) returns 4.6. ```APIDOC ## ROUND(numeric_exp, [decimals = 0 [, rounding_mode = HalfEven]]) ### Description The round function returns a number rounded to the specified length or precision. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **numeric_exp** (numeric) - Required - The number to be rounded. - **decimals** (integer) - Optional - Defaults to 0. The precision to which numeric_exp is to be rounded. - **rounding_mode** (string) - Optional - Defaults to 'HalfEven'. Possible values: 'HalfEven', 'HalfPos', 'HalfNeg', 'HalfDown', 'HalfUp', 'RndNeg', 'RndPos', 'RndDown', 'RndUp'. ### Request Example ``` ROUND(4.56, 1) ROUND(1.235, 2) ROUND(1.245, 2, HalfPos) ``` ### Response #### Success Response (200) - **result** (numeric) - The rounded number. #### Response Example ``` 4.6 ``` ``` -------------------------------- ### Copy Table to Different Database - ABSTable Component Source: https://www.componentace.com/help/absdb_manual/copyingtables This example shows how to copy a table to a different database file using the ABSTable component. It requires setting the DatabaseName and TableName properties and then calling the CopyTable method with the destination database file name as the second parameter. ```pascal ABSTable1.DatabaseName := 'emp_db'; ABSTable1.TableName := 'employee'; ABSTable1.CopyTable('new_employee', 'c:\data\emp_db2.abs'); ``` -------------------------------- ### SUM Function Example - SQL Source: https://www.componentace.com/help/absdb_manual/aggregatefunctions Illustrates the SUM function, which calculates the total sum of values in a specified column. This is a fundamental function for financial and numerical aggregations. ```sql SELECT SUM(ytd_sales) FROM sales_rep_tbl ```