Find() Search() always returns first record

I am using a custom controller that has global fieds for a number of fields. You type in the search parameters and then a method executes find() on another form fills in the values from the globals and then runs search() no matter what the firtst record appears in the foundset.
match or not.

Also the search doesn’t work for fields that are using related dataproviders

in this case (Jack, Room, Location, Unit, Port)

It works just fine when you do a ctrl-F and type it in when looking ONLY at the ListView Form.

Using the method, no dice… :cry:

Same thing goes for the QuickSort Method. Try clicking on the labels above the list. It sorts the foundset, but it doesn’t work for the related fields.

I just tried to import your solution to see if I could help you but got an error importing your solution on 2.0. Table or column name named “type” is a reserved word.

1)When you import a solution you can choose to allow reserved words.(checkbox)
This option refers to a list of reserved words defined by us in Servoy,
with basically reserved words from ALL common SQL databases.
So the situation might occur that you are importing a solution, and then get a message like "Table or column name named “type” is a reserved word.
Looking at the documentation of your database, it might be perfectly allowed to use the word “type”.(but NOT in other databases!)
In this case you could bypass the “Servoy reserved words” check.

  1. Can you post the solution with some sample data?
    I think your search has no results because the search query auto joins the tables jacks and devices, returning 0 results when your looking for eg a device record that has no related jack record

I checked the include sample data box last time, but here it is again. I am using MYSQL on a separate database server so maybe the sample data doesn’t get pulled if not in firebird.

Still the same problems as posted above.

Heres a MYSQL dump file

I just downloaded 2.0.1-build 274

Now the search form (custom controller) won’t come out of design mode, and there are no errors that pop up. (Actually if you switch back and forth from the MainView form to the Search form about 2 or 3 times, then it shows up for no apparently obvious reason) - I had to kill all my valuelists to get this to work. But the form is totally non-functional even though it is visible.

I think your search has no results because the search query auto joins the tables jacks and devices, returning 0 results when your looking for eg a device record that has no related jack record

There should be a jack record for every device record. The relationship is based on jackid and it is an autoincrementing field in the jacks table with a record for every # 1-666
The relationshp is one-to-many over on the devices table in which every device has a number 1-666.

What join Query is being run by servoy? Is there a way to see what database queries are going on in the background?

Does it matter what table the MainView form is based on? I am not putting any fields on it, only tabpanels. Which form controls the currently active record?

problem reproduced and i have fixed it.
Workaround for youre current build is to set all the globals you are using in the search form to null in a solution startup script.
If you switch out of designer you have to run that script first before going to a form with the search form…

Is there a way to see what database queries are going on in the background?

1)open servoy main folder
2)rightclick on “servoy_developer.bat” to edit.
3)make sure you have this line entered “java -DSTACKTRACE=true”
4)close and start servoy_developer.bat
5)stacktrace now runs in the console.

Thanks Maarten,

2)rightclick on “servoy_developer.bat” to edit.

I don’t see this on my MAC installation… is this functionality availible on OS X?

i needed my .bat file to have the following 2 lines

@echo off
java -DSTACKTRACE=true -jar servoy_developer.jar

-Greg

jcompagner
problem reproduced and i have fixed it.
Workaround for youre current build is to set all the globals you are using in the search form to null in a solution startup script.
If you switch out of designer you have to run that script first before going to a form with the search form…

I created a global method to preset all global vars to null and assigned it to run on Load of all my forms (I hope this is a temporary workaround until the next release?)
The search form shows up now, but it still can’t search for fields involved in a relationship.

Don’t forget the original question please. I still don’t have an answer.
Follow these steps to reproduce the problem.

a few noteworthy things i saw in the stacktrace:
This line is executed about 35-40 times whenever I use the search bar.

used sql select devices.id from devices where devices.jackid = ?  order by devices.id
questiondata[0]= 1

The first record always is returned is due to this line exectuting. I don’t know why it tacks on the questiondata[0] I searched for devices with asset 99.

used sql select devices.id from devices where (devices.jackid = ?  or devices.asset = ? ) order by devices.id
questiondata[0]= 1
questiondata[1]= 99

If you simply view the listview form and do ctrl-f and type in a location eg. 3329 the desired behavior executes:

mode change 1 -> 2
used sql select distinct(devices.id) from devices,jacks where jacks.location = ?  and devices.jackid = jacks.jackid
 order by devices.id
questiondata[0]= 3329
mode change 2 -> 1

My search method is designed to do just this. Why is it acting otherwise?

I ended up explicitly loading an empty foundset into the listview form before running a search. This fixed the problem of always returning the 1st record, and related finds seem to be working now too. I don’t think your search([clearlastresults]) is working.

Please make a function loademptyfoundset() availible soon! I had to do a blatant

find() 
field1="blahblahyouwontfindanything"
search() 
emptyfoundset=controller.duplicateFoundSet()

in order to have an empty foundset object to load before executing each search.

i still don’t really get what youre problem is because as far as i see there is no problem it is working fine.

what you do when you press search is that you are searching in the ListView. And if i search for Asset = 24 the list view (as FORM not in tabpanel of course because you re not searching in the form the Searchbar is the controller of (MainView) but you are searchin in the form ListView!!)
But if i search for asset == 24 and then go to the ListView form i see that it did search for 24. Exactly as you do in youre script.

I think what you want to do is do a related search in the MainView.. But if you want to do related search. Then you have to set the values through the relation.

so instead of this:

if (globals.asset){
asset = globals.asset;
}

do this:

controller.find()
if (globals.asset){
jacks_to_devices.asset = globals.asset;
}

if (globals.jack){
jack = “#%” + globals.jack + “%”;
}

if (globals.mac){
jacks_to_devices.mac = “#%”+globals.mac+“%”;
}

if (globals.lab){
jacks_to_devices.lab = globals.lab;
}

if (globals.type){
jacks_to_devices.type = globals.type;
}

(this is the start if the RunSearch script that i moved to the mainview from the listview.
and then if i fill in for asset >24 it works great.

I think you are right that what I want is a related find. Just to clarify what I want this solution to do.

The only form that will ever be the current controller is the MainView form. It must be based on the jacks table it is related to the devices table(1 Jack - Many Devices).

The custom controller is a form based entirely off of globals.
It will run a method whose primary function is to load a list of devices that match the search criteria into the ListView Form.

Once this foundset is loaded, each time a record is selected from this list, all other forms within tabpanels should switch to the related jack records.