Sisäänkirjautuminen| Uusi tunnus
FrontPage| Projects| Forums| Search|
^ DaoGen Forums: › Why? › PHP5? › Using ToString() with PHP › Next DaoGen version almost ready! › Create (insert) and Save (update) PHP examples › Support for numeric object types almost ready! › DaoGen 2.1.0 released! › Compliments and minor suggestion › variables within a class › Foreign key constraint in create() › Security issue!!! › auto-generated columns and create method › Oracle BLOB › DAO for cross-table queries › Please help me.. › Please use this forum for DaoGen related stuff › Call-time Pass-By-Reference › DaoGen 2.4.0 has been released! › How can I show relationships? › DaoGen & PHP 5 › PHP4 vs PHP5 and other considerations. › singleQuery example in php › Why are save and delete not synchronized? › Why are save and delete not synchronized? › DTD for generated XML › DaoGen 2.2.2 has been released! › DaoGen 2.0.2 is available. › For a thesis ?? › Extremely good idea ?? how can I ???? › Usability suggestions for DaoGen › Performance of DaoGen with Mapping tools › Performance with List › Some usage statistics › DaoGen 2.2.1 has been released! › Programming Examples are back! › DaoGen 2.0.1 is available. › Version 2.0.0 generates buggy PHP code! New version soon available! › Examples of DaoGen customizations » Code Examples
Sisäänkirjautuminen
» Käyttäjätunnus:
» Salasana:
» Muista kirjautuminen:
Suosituimmat sivut: › DaoGen 2.1.0 released! › Using ToString() with PHP › DaoGen Forums › Programming Examples › DaoGen Manual › DaoGen FAQ › DaoGen › Forums › Projects › Search
FrontPage » Forums » DaoGen Forums » 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