Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 5 additions & 0 deletions .changeset/selfish-worms-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@journeyapps/react-native-quick-sqlite": patch
---

Result object keys are no longer ordered alphabetically, but rather maintain insertion order. The behaviour now matches other libraries.
58 changes: 31 additions & 27 deletions cpp/JSIHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,40 +143,44 @@ jsi::Value createSequelQueryExecutionResult(jsi::Runtime &rt, SQLiteOPResult sta
// Converting row results into objects
size_t rowCount = results->size();
jsi::Object rows = jsi::Object(rt);
if (rowCount > 0)
if (rowCount > 0 && metadata != NULL)
{
auto array = jsi::Array(rt, rowCount);
for (int i = 0; i < rowCount; i++)
{
jsi::Object rowObject = jsi::Object(rt);
auto row = results->at(i);
for (auto const &entry : row)
auto row = results -> at(i);
// Iterate over metadata to maintain column order
for (const auto &column : *metadata)
{
std::string columnName = entry.first;
QuickValue value = entry.second;
if (value.dataType == TEXT)
std::string columnName = column.colunmName;
auto it = row.find(columnName);
if (it != row.end())
{
// using value.textValue (std::string) directly allows jsi::String to use length property of std::string (allowing strings with NULLs in them like SQLite does)
rowObject.setProperty(rt, columnName.c_str(), jsi::String::createFromUtf8(rt, value.textValue));
}
else if (value.dataType == INTEGER)
{
rowObject.setProperty(rt, columnName.c_str(), jsi::Value(value.doubleOrIntValue));
}
else if (value.dataType == DOUBLE)
{
rowObject.setProperty(rt, columnName.c_str(), jsi::Value(value.doubleOrIntValue));
}
else if (value.dataType == ARRAY_BUFFER)
{
jsi::Function array_buffer_ctor = rt.global().getPropertyAsFunction(rt, "ArrayBuffer");
jsi::Object o = array_buffer_ctor.callAsConstructor(rt, (int)value.arrayBufferSize).getObject(rt);
jsi::ArrayBuffer buf = o.getArrayBuffer(rt);
// It's a shame we have to copy here: see https://github.com/facebook/hermes/pull/419 and https://github.com/facebook/hermes/issues/564.
memcpy(buf.data(rt), value.arrayBufferValue.get(), value.arrayBufferSize);
rowObject.setProperty(rt, columnName.c_str(), o);
}
else
QuickValue value = it -> second;
if (value.dataType == TEXT)
{
// using value.textValue (std::string) directly allows jsi::String to use length property of std::string (allowing strings with NULLs in them like SQLite does)
rowObject.setProperty(rt, columnName.c_str(), jsi::String::createFromUtf8(rt, value.textValue));
} else if (value.dataType == INTEGER)
{
rowObject.setProperty(rt, columnName.c_str(), jsi::Value(value.doubleOrIntValue));
} else if (value.dataType == DOUBLE)
{
rowObject.setProperty(rt, columnName.c_str(), jsi::Value(value.doubleOrIntValue));
} else if (value.dataType == ARRAY_BUFFER)
{
jsi::Function array_buffer_ctor = rt.global().getPropertyAsFunction(rt, "ArrayBuffer");
jsi::Object o = array_buffer_ctor.callAsConstructor(rt, (int) value.arrayBufferSize).getObject(rt);
jsi::ArrayBuffer buf = o.getArrayBuffer(rt);
// It's a shame we have to copy here: see https://github.com/facebook/hermes/pull/419 and https://github.com/facebook/hermes/issues/564.
memcpy(buf.data(rt), value.arrayBufferValue.get(), value.arrayBufferSize);
rowObject.setProperty(rt, columnName.c_str(), o);
} else
{
rowObject.setProperty(rt, columnName.c_str(), jsi::Value(nullptr));
}
} else
{
rowObject.setProperty(rt, columnName.c_str(), jsi::Value(nullptr));
}
Expand Down
Loading