QVar<T> class
Represents a value in SQL with proper escaping and formatting.
The QVar class is responsible for converting Dart values into their SQL representation with proper escaping to prevent SQL injection attacks. It handles various data types including strings, numbers, dates, lists, and null values.
Type parameter T
can be used for type hints but doesn't affect the
conversion logic.
Example usage:
var stringVar = QVar('Hello World'); // 'Hello World'
var numberVar = QVar(42); // 42
var dateVar = QVar(DateTime.now()); // '2023-12-01T10:30:00.000Z'
var listVar = QVar([1, 2, 3]); // (1, 2, 3)
var nullVar = QVar(null); // NULL
- Implemented types
Constructors
- QVar.new(dynamic value)
- Creates a new SQL value wrapper.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value ↔ dynamic
-
The Dart value to be converted to SQL
getter/setter pair
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toSQL(
) → String -
Converts this value to its SQL string representation.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
date(
DateTime date) → QVar - Creates a QVar containing a date formatted as 'yyyy-MM-dd'.
-
dateNow(
) → QVar - Creates a QVar containing today's date formatted as 'yyyy-MM-dd'.
-
dateTime(
DateTime datetime) → QVar - Creates a QVar containing a DateTime value formatted as ISO 8601 string.
-
dateTimeNow(
) → QVar - Creates a QVar containing the current DateTime as ISO 8601 string.
-
escape(
String input) → String - Escapes special characters in strings to prevent SQL injection.
-
password(
String password, {HashType type = HashType.md5, String hmacKey = 'unknown_default_key'}) → QVar -
Creates a QVar containing a password hash using the specified hashing algorithm.
MD5, SHA-1, SHA-256, SHA-512, and HMAC (SHA-256) are supported.
password
The password string to hash.type
The hashing algorithm to use (default is HashType.md5).hmacKey
The key for HMAC hashing (default is 'unknown_default_key').