GithubHelp home page GithubHelp logo

Comments (13)

simolus3 avatar simolus3 commented on May 20, 2024 1

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.

simolus3 avatar simolus3 commented on May 20, 2024 1

Now fixed on develop

from drift.

raphmte avatar raphmte commented on May 20, 2024 1

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.

simolus3 avatar simolus3 commented on May 20, 2024 1

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.

raphmte avatar raphmte commented on May 20, 2024

Hello @simolus3 , a tried your code, but:

image

This error appears on Where stantement.

from drift.

simolus3 avatar simolus3 commented on May 20, 2024

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.

raphmte avatar raphmte commented on May 20, 2024

@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();
    });
  }

The error:
image

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();
    });

Error:
image

How I solve this? =/

from drift.

simolus3 avatar simolus3 commented on May 20, 2024

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.

raphmte avatar raphmte commented on May 20, 2024

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.

simolus3 avatar simolus3 commented on May 20, 2024

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.

raphmte avatar raphmte commented on May 20, 2024

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.

raphmte avatar raphmte commented on May 20, 2024

Very good, worked perfectly. Thank you.
How do I use the dev version?

from drift.

simolus3 avatar simolus3 commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.