![]() |
|
User variable names must begin with a letter and can include letters,
numbers, underscores ("_"), and embedded dollar signs ("$"). Names are
case-insensitive, meaning Account
and
AccOUNT
are treated as the same. By convention, multi-word
variable names are separated by underscores.
table_name(field_name)
.The most commonly used data types in Sheerpower are REAL, STRING, and BOOLEAN. INTEGER and DYNAMIC are less frequently used. By default, variables are of the REAL type.
In Sheerpower, variable types must remain consistent after they are
declared. For example, if you declare a = 18
, attempting to
use a
in a string context, like a + '9'
, will
result in a compile-time error. This type safety ensures
predictable results. However, table field references
(e.g., payroll(salary)
) are handled differently since the
data type of a field can only be determined at runtime. This allows dynamic
type handling for table fields but does not apply to regular
variables.
All database access uses the table_name(field_name)
syntax.
For instance, print payroll(salary)
retrieves the current
record from the payroll table, locks it if necessary, extracts the
salary
field, and prints its value.
When assigning a value to a database field, such as
payroll(salary) = 1234.56
, Sheerpower retrieves the current
record, locks it, assigns the value 1234.56
to the
salary
field, and writes the modified record back to the
database using a "lazy write" mechanism. This mechanism
ensures database integrity by delaying the write operation until it is
most efficient.
table_name(field_name)
In Sheerpower, the treatment of table_name(field_name)
is
dynamic and adjusts based on the context in which it is used. This
flexibility allows developers to handle different data types without the
need for explicit conversions, simplifying code and reducing potential
errors.
When a field from a database table is used in a numerical context, such as in mathematical operations, Sheerpower automatically interprets and converts the field's value to the appropriate numeric type. This makes it easy to perform calculations on database fields without requiring any manual type conversions.
In this case, payroll(salary)
retrieves the
salary
field from the payroll
table. The
value is automatically converted into a number, allowing it to be
multiplied by 1.5
seamlessly. This dynamic conversion
eliminates the need for explicit type management in mathematical
operations.
When a field is used in a string context, Sheerpower dynamically converts the value to a string. This is particularly useful when concatenating or formatting data from the database with other strings.
Here, payroll(salary)
retrieves the salary
field from the payroll
table, and the value is
automatically treated as a string for concatenation with the text
'my '
. The result, mysalary$
, will hold the
concatenated string without needing explicit conversion.
table_name(field_name)
syntax provides a clean and
efficient way to access and modify database fields, with built-in
protections against SQL injection attacks, further enhancing
security and performance.
This dynamic type conversion, coupled with the ease of use of
table_name(field_name)
, allows developers to focus more on
business logic rather than handling cumbersome type declarations or
conversions.
Comments in your code should explain the reasoning behind specific logic. Sheerpower ignores all comments since they are intended for your reference and for future developers who need to understand your code.
Comments are prefixed with either !
or //
! this is a comment
// this is a comment
Hide Description
|
|
Enter or modify the code below, and then click on RUN |
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |