Comments (13)
When you call join
after calling where
or orderBy
, these get reset, so you first need to use join
and apply filters afterwards. There's no a good reason for that, so I'll consider this a bug. Nevertheless, you can "fix" your query with:
final query = await (select(serviceOrders)
..join([
leftOuterJoin(serviceOrdersStatus,
serviceOrdersStatus.sstStatus.equalsExp(serviceOrders.sorStatus)),
leftOuterJoin(placeLoading,
placeLoading.plaCode.equalsExp(serviceOrders.plaCodeLoading)),
leftOuterJoin(
cityLoading, cityLoading.citCode.equalsExp(placeLoading.citCode)),
leftOuterJoin(placeDischarge,
placeDischarge.plaCode.equalsExp(serviceOrders.plaCodeDischarge)),
leftOuterJoin(cityDischarge,
cityDischarge.citCode.equalsExp(placeDischarge.citCode)),
]
..where(serviceOrders.sorCode.equals(sorCode)))
).get();
from drift.
Now fixed on develop
from drift.
I really wish you did not feel sorry for the problems, you have done a work of art with Moor and the only thing I have to do is thank you and report the problems I encounter to make it better every day.
And also thank you for seeing this bizarre typing error, your last code worked perfectly and the SQL error was that the table was wrong even:
Stream<List<ServiceOrderExpenseWithCatyegory>> getExpensesStream(
{int sorCode}) {
final query = select(serviceOrdersExpenses)
.join([
leftOuterJoin(
expensesTypes,
expensesTypes.etyCode.equalsExp(serviceOrdersExpenses.etyCode)),
])
..where(serviceOrdersExpenses.sorCode.equals(sorCode));
return query.watch().map((rows) {
return rows.map((row) {
return ServiceOrderExpenseWithCatyegory(
row.readTable(serviceOrdersExpenses), row.readTable(expensesTypes));
}).toList();
});
}
All filters have been performed correctly and now I just get the records I need, I will work on the other tables now to improve the code also with these new changes. Thank you very much again.
from drift.
Your query should work on develop
. If you're using the latest release version, you can again work around the bug with
final query = await (
select(serviceOrders)
.join([
leftOuterJoin(serviceOrdersStatus,
serviceOrdersStatus.sstStatus.equalsExp(serviceOrders.sorStatus)),
leftOuterJoin(placeLoading,
placeLoading.plaCode.equalsExp(serviceOrders.plaCodeLoading)),
leftOuterJoin(
cityLoading, cityLoading.citCode.equalsExp(placeLoading.citCode)),
leftOuterJoin(placeDischarge,
placeDischarge.plaCode.equalsExp(serviceOrders.plaCodeDischarge)),
leftOuterJoin(cityDischarge,
cityDischarge.citCode.equalsExp(placeDischarge.citCode)),
])
..where(serviceOrders.sorCode.equals(sorCode))
).get();
from drift.
Hello @simolus3 , a tried your code, but:
This error appears on Where stantement.
from drift.
Ah sorry, stupid mistake I made above - you need to call .where
on the select statement, not on the list. So line 159 in your code should probably be ])
, like this:
final query = await (select(serviceOrders)
..join([
leftOuterJoin(serviceOrdersStatus,
serviceOrdersStatus.sstStatus.equalsExp(serviceOrders.sorStatus)),
// ...
])
..where(serviceOrders.sorCode.equals(sorCode))
).get();
from drift.
@simolus3 Hello again man, pls help in this Where instantement pls, I tried your last response but now I get an error:
Stream<List<ServiceOrderExpenseWithCatyegory>> getExpensesStream(
{int sorCode}) {
final query = (select(serviceOrdersExpenses)
..join([
leftOuterJoin(
serviceOrdersExpenses,
serviceOrdersExpenses.etyCode.equalsExp(serviceOrdersExpenses.etyCode)),
])
..where((expense) => expense.sorCode.equals(sorCode))
);
return query.watch().map((rows) {
return rows.map((row) {
return ServiceOrderExpenseWithCatyegory(
row.readTable(serviceOrdersExpenses), row.readTable(expensesTypes));
}).toList();
});
}
If I try the Join with one point the error turn to Where:
final query = (select(serviceOrdersExpenses)
.join([
leftOuterJoin(
serviceOrdersExpenses,
serviceOrdersExpenses.etyCode.equalsExp(serviceOrdersExpenses.etyCode)),
])
..where((expense) => expense.sorCode.equals(sorCode))
);
return query.watch().map((rows) {
return rows.map((row) {
return ServiceOrderExpenseWithCatyegory(
row.readTable(serviceOrdersExpenses), row.readTable(expensesTypes));
}).toList();
});
How I solve this? =/
from drift.
Hopefully this one works 😬
Stream<List<ServiceOrderExpenseWithCatyegory>> getExpensesStream(
{int sorCode}) {
final query = select(serviceOrdersExpenses)
.join([
leftOuterJoin(
serviceOrdersExpenses,
serviceOrdersExpenses.etyCode.equalsExp(serviceOrdersExpenses.etyCode)),
])
..where(serviceOrderExpenses.sorCode.equals(sorCode));
return query.watch().map((rows) {
return rows.map((row) {
return ServiceOrderExpenseWithCatyegory(
row.readTable(serviceOrdersExpenses), row.readTable(expensesTypes));
}).toList();
});
}
If you use the ..
operator before the join, the joined select statement will be created but not used, it would still be the regular select statement - sorry. It's okay to use it before the where
because at that point we already have the joined select statement.
from drift.
Well this one did not generate error in the code, but ended up generating a SQL error:
Unhandled Exception: DatabaseException(ambiguous column name: service_orders_expenses.sexCode (code 1 SQLITE_ERROR)
Let's do the following, as you commented in the previous answers that have corrected this problem for the next versions, for now I'm giving that developer way here to get going with my app, and so you update I go back and review these things. = D
Thank you very much for the help and I will let you work.
from drift.
Sorry that you keep getting these problems :/ I think I know where that one is coming from as well, but I don't want to make false promises. Can you give me the definition for the "ServiceOrderExpenses" table? Then I can debug that query and be certain that it works when I have it figured out.
Btw, you run a select on serviceOrdersExpenses
and then join serviceOrdersExpenses
(the same table). Later, you want to read both serviceOrdersExpenses
and expensesTypes
(a table which doesn't appear in the select statement). Is this a typo?
from drift.
Simo, me again. Sorry for the inconvenience, but how do I do the same where with Get?
final query = await (select(serviceOrders)
..where((s) => s.sorCode.equals(sorCode)))
.join([
leftOuterJoin(serviceOrdersStatus,
serviceOrdersStatus.sstStatus.equalsExp(serviceOrders.sorStatus)),
leftOuterJoin(placeLoading,
placeLoading.plaCode.equalsExp(serviceOrders.plaCodeLoading)),
leftOuterJoin(
cityLoading, cityLoading.citCode.equalsExp(placeLoading.citCode)),
leftOuterJoin(placeDischarge,
placeDischarge.plaCode.equalsExp(serviceOrders.plaCodeDischarge)),
leftOuterJoin(cityDischarge,
cityDischarge.citCode.equalsExp(placeDischarge.citCode)),
]).get();
List<ServiceOrderWithDetails> finalList = query.map((resultRow) {
return ServiceOrderWithDetails(
resultRow.readTable(serviceOrders),
resultRow.readTable(serviceOrdersStatus),
resultRow.readTable(placeLoading),
resultRow.readTable(cityLoading),
resultRow.readTable(placeDischarge),
resultRow.readTable(cityDischarge),
);
}).toList();
from drift.
Very good, worked perfectly. Thank you.
How do I use the dev
version?
from drift.
Put this in your pubspec.yaml
:
dependency_overrides:
moor_flutter:
git:
url: https://github.com/simolus3/moor.git
ref: develop
path: moor_flutter/
moor_generator:
git:
url: https://github.com/simolus3/moor.git
ref: develop
path: moor_generator/
Be aware that these development releases can be very unstable at times. I might set up a more stable prerelease branch after the next release 🤔
from drift.
Related Issues (20)
- SqliteException(14):while opening the database, unable to open database file (code 14)
- Encryption Example - libsqlite3.so not found HOT 2
- duplicate column name HOT 2
- error DioException HOT 1
- TableUpdates data HOT 1
- [drift_postgres] Cannot insert null value to default column HOT 1
- feat: Get references from manager HOT 4
- Package import mismatch in generated file HOT 2
- [drift_postgres] Postgres implicit type casts not working in raw queries HOT 1
- Manager: Support tables with custom row classes HOT 1
- Share db with host Android app embedded flutter readonly/read write problems HOT 5
- disk I/O error
- `enableMigrations` param for web implementation. HOT 1
- feat: Common Root Manager Operations should work with id
- postgresql arrays? HOT 7
- Error while trying to run in flutter web HOT 1
- Upsert against db object behaves differently to upsert against batch HOT 2
- Allow QueryInterceptor to ignore/exclude specified tables HOT 1
- Converting database keys in toJson from camelCase to snake_case HOT 1
- LazyDatabase is imposible to execute queries when reopen HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drift.