If tableName element is missing in a select annotation, EOD should issue proper error message

XMLWordPrintable

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: P3
    • None
    • Affects Version/s: javadb_10.2
    • Component/s: core-libs
    • None
    • generic
    • generic

      Today if the tableName ellement is missing from a disconnected, updatable select annotation, an erroneous SQL statement is created, causing a syntax eror from the DB. A proper error message should be issued.

      Example:

      @Select(sql="select firstName, lastName from persons",
             readOnly=false, connected=false)
                 DataSet<Person> getAndUpdatePersons();

      will lead to the SQL statement (when used with Derby)

          INSERT INTO APP. (FIRSTNAME, LASTNAME) VALUES (?, ?)

      which again gives the following exception:

      java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 18.



      Program that reproduces the error:

      ------8<---------------------------------------------------------------

      import java.sql.*;

      public class EODMissingTableName
      {
          static public class Person {
              public Person() {
                  // Needed for DataSet
                  firstName = null;
                  lastName = null;
              }
              public Person(String f, String l) {
                  firstName = f;
                  lastName = l;
              }
              public String firstName;
              @ResultColumn(uniqueIdentifier=true)
                  public String lastName;
              public String toString()
              {
                  if (firstName == null) {
                      return lastName;
                  } else {
                      return lastName + ", " + firstName;
                  }
              }
              public boolean equals(Person other)
              {
                  if (firstName == null) {
                      return lastName.equals(other.lastName);
                  } else {
                      return lastName.equals(other.lastName) &&
                          firstName.equals(other.firstName);
                  }
              }
          }
              
          interface PersonQueryObject extends BaseQuery {

              @Select(sql="select firstName, lastName from persons", readOnly=false, connected=false)
                  DataSet<Person> getAndUpdatePersons();

              @java.sql.Update(sql="insert into persons values (?1,?2)")
                  int insertPerson(String a, String b);

              @java.sql.Update(sql="create table persons (firstName varchar(256), lastName varchar(256) unique not null)")
                  int createTable();
          }
          
          
          
          static public void main(String []args)
              throws Exception
          {
      String driver = "org.apache.derby.jdbc.EmbeddedDriver";
      String url = "jdbc:derby:/export/home/tmp/DB/eod;create=true";
              Class.forName(driver);
              
              Connection conn = DriverManager.getConnection(url);

              PersonQueryObject pqo = conn.createQueryObject(PersonQueryObject.class);
              pqo.createTable();
              pqo.insertPerson("John","Doe");

              DataSet<Person> dsp = pqo.getAndUpdatePersons();

              for (Person p: dsp) {
                  p.firstName = "Wu";
                  p.lastName = "Ming";
                  dsp.modify();
              }

              dsp.sync(conn);
              dsp.close();
              pqo.close();
              
          }
      }

            Assignee:
            Unassigned
            Reporter:
            Bernt Marius Johnsen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: