Subject Re: sql
From Mervyn Bick <invalid@invalid.invald>
Date Tue, 11 Dec 2018 07:29:22 +0200
Newsgroups dbase.getting-started
Attachment(s) test_changeorder.wfm

On 2018-12-10 11:55 PM, Charlie wrote:
> Hi... In a form you make the sql statement for each query.  If you make the order (by order) how or what statement can you make later in the form to change the order?
>
> Thanks!!
>

When accessing data using an index to order the data all one needs to do
is change the rowset's active index and the new order is applied
immediately.  Unfortunately it's not quite as simple (although it's not
difficult) when using an ORDER BY clause in a query's SELECT statement.

You will need to set the query's active property false, replace the
query's SQL property with a SELECT statement which includes the new
ORDER BY clause and then set the query's active property true again.
You may also find it necessary to execute the rowset's refreshContols()
method if you change anything other than the order by clause.

A little example is attached.

Mervyn,




** END HEADER -- do not remove this line
//
// Generated on 2018-12-11
//
parameter bModal
local f
f = new test_changeorderForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class test_changeorderForm of FORM
   with (this)
      height = 26.3636
      left = 81.5714
      top = 1.8182
      width = 77.1429
      text = ""
   endwith

   this.DBASESAMPLES1 = new DATABASE(this)
   with (this.DBASESAMPLES1)
      left = 16.0
      top = 1.0
      width = 11.0
      height = 1.0
      databaseName = "DBASESAMPLES"
      active = true
   endwith

   this.EMPLOYEES1 = new QUERY(this)
   with (this.EMPLOYEES1)
      left = 6.0
      top = 1.0
      width = 8.0
      height = 1.0
      database = form.dbasesamples1
      sql = "select employeeId,firstName,lastName from EMPLOYEES.DBF"
      active = true
   endwith

   this.GRID1 = new GRID(this)
   with (this.GRID1)
      dataLink = form.employees1.rowset
      height = 15.5
      left = 3.0
      top = 5.5
      width = 68.0
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 1.0909
      left = 10.0
      top = 23.0
      width = 15.2857
      text = "Natural order"
   endwith

   this.PUSHBUTTON2 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON2)
      onClick = class::PUSHBUTTON2_ONCLICK
      height = 1.0909
      left = 28.0
      top = 23.0
      width = 15.2857
      text = "First name order"
   endwith

   this.PUSHBUTTON3 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON3)
      onClick = class::PUSHBUTTON3_ONCLICK
      height = 1.0909
      left = 48.0
      top = 23.0
      width = 15.2857
      text = "Last name order"
   endwith

   this.rowset = this.employees1.rowset

   function PUSHBUTTON1_onClick()
      form.employees1.active = false
      form.employees1.sql ="select employeeId,firstName,lastName from EMPLOYEES.DBF"
      form.employees1.active = true      
      return

   function PUSHBUTTON2_onClick()
      form.employees1.active = false
      form.employees1.sql ="select employeeId,firstName,lastName from EMPLOYEES.DBF order by firstName"
      form.employees1.active = true
      return

   function PUSHBUTTON3_onClick()
      form.employees1.active = false
      form.employees1.sql ="select employeeId,firstName,lastName from EMPLOYEES.DBF order by lastName"
      form.employees1.active = true
      return

endclass



Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0