Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sqlite3/lib/src/ffi/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ extension ValueUtils on Pointer<sqlite3_value> {
}
}

final utf8Encode = utf8.encoder.convert;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only define this once, the usage in memory.dart can just import this one.


extension ContextUtils on Pointer<sqlite3_context> {
Pointer<Void> aggregateContext(Bindings bindings, int bytes) {
return bindings.sqlite3_aggregate_context(this, bytes);
Expand All @@ -88,7 +90,7 @@ extension ContextUtils on Pointer<sqlite3_context> {
} else if (result is bool) {
bindings.sqlite3_result_int64(this, result ? 1 : 0);
} else if (result is String) {
final bytes = utf8.encode(result);
Uint8List bytes = utf8Encode(result);
final ptr = allocateBytes(bytes);

bindings.sqlite3_result_text(
Expand All @@ -104,7 +106,7 @@ extension ContextUtils on Pointer<sqlite3_context> {
}

void setError(Bindings bindings, String description) {
final bytes = utf8.encode(description);
final Uint8List bytes = utf8Encode(description);
final ptr = allocateBytes(bytes);

bindings.sqlite3_result_error(this, ptr.cast(), bytes.length);
Expand Down
3 changes: 2 additions & 1 deletion sqlite3/lib/src/ffi/memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Pointer<Uint8> allocateBytes(Uint8List bytes, {int additionalLength = 0}) {
return ptr;
}

final utf8Encode = utf8.encoder.convert;
Pointer<char> allocateZeroTerminated(String string) {
return allocateBytes(utf8.encode(string), additionalLength: 1).cast();
return allocateBytes(utf8Encode(string), additionalLength: 1).cast();
}
4 changes: 2 additions & 2 deletions sqlite3/lib/src/impl/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class DatabaseImpl implements Database {
final pzTail =
checkNoTail ? allocate<Pointer<char>>() : nullPtr<Pointer<char>>();

final bytes = utf8.encode(sql);
final bytes = utf8Encode(sql);
final sqlPtr = allocateBytes(bytes);

var prepFlags = 0;
Expand Down Expand Up @@ -229,7 +229,7 @@ class DatabaseImpl implements Database {
}

Pointer<Uint8> _functionName(String functionName) {
final functionNameBytes = utf8.encode(functionName);
final functionNameBytes = utf8Encode(functionName);

if (functionNameBytes.length > 255) {
throw ArgumentError.value(functionName, 'functionName',
Expand Down
2 changes: 1 addition & 1 deletion sqlite3/lib/src/impl/statement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PreparedStatementImpl implements PreparedStatement {
} else if (param is double) {
_bindings.sqlite3_bind_double(_stmt, i, param.toDouble());
} else if (param is String) {
final bytes = utf8.encode(param);
final bytes = utf8Encode(param);
final ptr = allocateBytes(bytes);
_allocatedWhileBinding.add(ptr);

Expand Down