Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » [Mars][HowTo] insert multi records in SQL.insert statement(One of the ways to insert several records into the table)
[Mars][HowTo] insert multi records in SQL.insert statement [message #1724116] Sun, 21 February 2016 09:47 Go to next message
barust Mising name is currently offline barust Mising nameFriend
Messages: 57
Registered: February 2014
Member
For example,
I need to add to the table of the year and months, in my case it is 2016 and 12 months.
http://imageshack.com/i/poOm4Aivp
Naturally year repeated 12 times, but how to do it.

Here is my solution:

I have a table SCHEDULE with columns: PODR_ID, S_YEAR, S_MONTH.

On #Client/Forms I created form ScheduleForm with PodrNr and Year fields.
In #Server/Services/ScheduleService the solution is as follows:
@Override
  public ScheduleFormData create(ScheduleFormData formData) throws ProcessingException {
    if (!ACCESS.check(new CreateSchedulePermission())) {
      throw new VetoException(TEXTS.get("AuthorizationFailed"));
    }
   
    for (int k = 1; k <= 12; k++) {
      SQL.insert(""
          + "INSERT "
          + "INTO SCHEDULE (PODR_ID, S_YEAR, S_MONTH) "
          + "VALUES (:podrNr, :year, :k)"
          , new NVPair("k", k), formData);
    }

    return formData;
  }


Perhaps this is trivial, but I think somebody is handy.

I have a question, is there any other decision of this problem with SQL.insert?

Barust R
  • Attachment: Table.png
    (Size: 16.29KB, Downloaded 138 times)

[Updated on: Sun, 21 February 2016 09:49]

Report message to a moderator

Re: [Mars][HowTo] insert multi records in SQL.insert statement [message #1724361 is a reply to message #1724116] Tue, 23 February 2016 11:18 Go to previous messageGo to next message
Samuel   is currently offline Samuel Friend
Messages: 22
Registered: January 2012
Junior Member
Generally, Scout offers the possibility for a multi-insert if the data to be inserted is stored into an AbstractTableFieldData object.
In this case, you can use the syntax ewith curly braces:
SQL.insert(""
        + "INSERT INTO TABLE ( "
        + "  ROW1, "
        + "  ROW2) "
        + "VALUES ( "
        + "  :{myTable.row1}, "
        + "  :{myTable.row2}) "
        , formData);

You could also let the DBMS do the job by introducing a table (e.g. called MONTHS) containing the natural numbers between 0 and 11.
The following SQL snippet does the job.
INSERT INTO TABLE (
  ROW1,
  ROW2
SELECT SOMETHING,
       SOMETHING_ELSE
FROM   MONTHS
Re: [Mars][HowTo] insert multi records in SQL.insert statement [message #1724453 is a reply to message #1724361] Wed, 24 February 2016 04:33 Go to previous message
barust Mising name is currently offline barust Mising nameFriend
Messages: 57
Registered: February 2014
Member
Thank you Samuel Renold,
I will certainly write it down to my HowTo these decisions.
Previous Topic:[Neon][SDK] access Scout Model
Next Topic:[Neon] Multi line column header
Goto Forum:
  


Current Time: Thu Apr 25 09:36:05 GMT 2024

Powered by FUDForum. Page generated in 0.03909 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top