TitanicLinux.Net :: Code Examples



Code Examples

Posted by danny 2:13:07 PM

Are there any examples of how to use the DaoGen code. More specifically the listQuery routine. I am getting errors.

Thanks...I think this is a great tool.


Re: Code Examples

Posted by Luigi 3:24:20 PM

> danny 2:13:07 PM
> Are there any examples of how to use the DaoGen code. More specifically the listQuery routine. I am getting errors.
>
> Thanks...I think this is a great tool.


First of all, thanks for your feedback.
The previous versions of DaoGen had some code examples but they were for PHP only. I am planning to include some complete examples in the DaoGen pages, but it will take some time before I can do it.

However here is a quick help for Java:
1. You can not use listQuery outside the Dao class, since it is protected. The *right* solution is to *extend* the generated dao-class.

2. Create new class like this: (I am assuming, you have generated classes MyTable and MyTableDao)
public class MyTableDaoExt extends MyTableDao {

3. Now create the method for your desired action, like this:

public List getMyList(Connection conn, int something) throws SQLException {
List searchResults = null;
PreparedStatement stmt = null;

String sql = "SELECT * FROM MyTable WHERE MyColumn = ?";
try {
stmt = conn.prepareStatement(sql);
stmt.setInt(1, something);
searchResults = listQuery(conn, stmt);
} finally {
if (stmt != null)
stmt.close();
}
return searchResults;
}

That is all you need to do. (the MyTableDaoExt class needs only this one method). Now, in your application you should no more create instances of MyTableDao but instead MyTableDaoExt. Then you have all the basic generated methods and also the new method(s) that you defined.

If you use PHP, the instructions are almost the same. The most important thing to remember is: *Never change the generated classes*, just *extend* Them.

Hope this helped!

// Luigi.


Re: Re: Code Examples

Posted by anonymous 8:38:14 PM

Thank you for you reply....

The problem more specifically that I am seeing in this error:
"Call to undefined function: setquestionid()"

Here is the generated Dao code:

function listQuery(&$conn, &$sql) {

$searchResults = array();
$result = $conn->execute($sql);

while ($row = $conn->nextRow($result)) {
$temp = new Question();

*error line-> $temp.setQuestionID($row[0]);
$temp.setSectionNumber($row[1]);
$temp.setQuestionNumber($row[2]);
$temp.setQuestionText($row[3]);
array_push($searchResults, $temp);
}

return $searchResults;
}

I looked in the Question.php file and the setQuestionID() method is present. It like the "new Question()" statement is failing, but there is no error message.

Have you ever seen this problem?


Re: Re: Re: Code Examples

Posted by anonymous 3:10:18 AM

> anonymous 8:38:14 PM
> Thank you for you reply....
>
> The problem more specifically that I am seeing in this error:
> "Call to undefined function: setquestionid()"
>
> Here is the generated Dao code:
>
> function listQuery(&$conn, &$sql) {
>
> $searchResults = array();
> $result = $conn->execute($sql);
>
> while ($row = $conn->nextRow($result)) {
> $temp = new Question();
>
> *error line-> $temp.setQuestionID($row[0]);
> $temp.setSectionNumber($row[1]);
> $temp.setQuestionNumber($row[2]);
> $temp.setQuestionText($row[3]);
> array_push($searchResults, $temp);
> }
>
> return $searchResults;
> }
>
> I looked in the Question.php file and the setQuestionID() method is present. It like the "new Question()" statement is failing, but there is no error message.
>
> Have you ever seen this problem?


I got it... I just changed the "." to "->" it works.


Re: Code Examples

Posted by Luigi 12:28:51 PM

Great that you located the problem! When I was re-implementing DaoGen for the 2.0 version, I was too busy to test the generated PHP code well enough. Now that you found a problem, I will fix it immediately.

// Luigi



viimeisin päivitys: 12.02.2005 13:05 Author: TitanicLinux.Net
Copyright TitanicLinux.Net 2003-2010