Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3677

SQL documentation: executeInsert Javadoc error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.6.5, 1.7-beta-2
    • SQL processing
    • None

    Description

      It looks like there is a slight mistake in the executeInsert Javadoc, it shows an example with "insert" not executeInsert

      executeInsert

      public List executeInsert(GString gstring)

      Executes the given SQL with embedded expressions inside, and returns the values of any auto-generated colums, such as an autoincrement ID field. These values can be accessed using array notation. For example, to return the second auto-generated column value of the third row, use keys[3][1]. The method is designed to be used with SQL INSERT statements, but is not limited to them.

      The standard use for this method is when a table has an autoincrement ID column and you want to know what the ID is for a newly inserted row. In this example, we insert a single row into a table in which the first column contains the autoincrement ID:

      def sql = Sql.newInstance("jdbc:mysql://localhost:3306/groovy",
      "user",
      "password",
      "com.mysql.jdbc.Driver")

      def keys = sql.insert("insert into test_table (INT_DATA, STRING_DATA) "
      + "VALUES (1, 'Key Largo')")

      def id = keys[0][0]

      // 'id' now contains the value of the new row's ID column.
      // It can be used to update an object representation's

      // id attribute for example.

      Attachments

        Activity

          People

            paulk Paul King
            fjanon Fred Janon
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: