Jump to content


Photo

DBGRID Sql Sort

TNextDBGrid6 dbgrid sql sort

  • Please log in to reply
10 replies to this topic

#1 andry

andry
  • Members
  • 6 posts

Posted 06 December 2015 - 01:09 PM

Hi, 

I'm trying to use NextSuite6 and I begin with this problem:

 

 

in Version 5 (TNextDBGrid) I done so and work fine:

 

// this script is used with NexusDB database but I think can be used also with other one

procedure TfrmMain.dbGridAnagPreviewSortColumn(Sender: TObject; ACol: Integer;
  Ascending: Boolean);
var  DirectionStr: string;
begin
  if dbGridAnagPreview.Columns[ACol].FieldName = '' then Exit;
  if Ascending then DirectionStr := 'ASC' else DirectionStr := 'DESC';
  DataModule1.nxQueryAnagPreview.Close;
  DataModule1.nxQueryAnagPreview.SQL.Text := changeSQLOrder(DataModule1.nxQueryAnagPreview.SQL.Text,    //<<<< 'changeSQLOrder' function change ORDER in sql script 
                                                dbGridAnagPreview.Columns[ACol].FieldName + ' ' + DirectionStr);
  DataModule1.nxQueryAnagPreview.Open;
end;
 
In version 6 (TNextDBGrid6) I'm doing so (I don't know if is the right method!) but doesn't work (I get an access violation))
procedure TfrmMain.NextDBGrid61SortQuery(Sender: TObject; Index: Integer;
  SortKind: TNxSortKind; var Accept: Boolean);
var sFld : string;
begin
    sFld := (NextDBGrid61.Columns[Index] as TNxDBTextColumn6).DataBinding.FieldName;
    nxQuery1.Close;
    nxQuery1.SQL.Text := _changeSQLOrder(nxQuery1.SQL.Text,
            sFld +
            _sif(SortKind = skDescending, '', ' DESC'));
    nxQuery1.Open;
end;
 

Can SomeOne help me?

 

Thanks



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,757 posts
  • Gender:Male

Posted 06 December 2015 - 02:51 PM

Hi,

 

Can you please tell me where error occurs (also which AV message you receive).

 

If sFld var evaluated, and got value?

 

Thanks.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 andry

andry
  • Members
  • 6 posts

Posted 06 December 2015 - 07:31 PM

yes sFld get the right value.

I'm making a complete simple project to send you with source + exe + data.

My project use NexusDB that is available also as trial version (www.nexusdb.com).

In next days I'll try also the same situation with MyDac (https://www.devart.com/mydac/) to see if same erro occours. I'll tell you.



#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,757 posts
  • Gender:Male

Posted 06 December 2015 - 08:43 PM

Thanks Andry,

Pplease send me a small demo.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 andry

andry
  • Members
  • 6 posts

Posted 07 December 2015 - 01:48 AM

Here a small example compiled with delphi XE8 - 32bit

use: 

- Next Suite 6 (VCL), v6.0.8 (12.2015)

- NexusDB version 4.0014 (www.nexusdb.com) with embedded mode database

previous test I made with C/S mode database

 

 

Attached Files



#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,757 posts
  • Gender:Male

Posted 07 December 2015 - 05:02 AM

Thanks,

 

I will need 1-2 days to solve it.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,757 posts
  • Gender:Male

Posted 07 December 2015 - 05:37 AM

Hi,

 

I have found cause of problem. I will upload another release in Tuesday, please read History.txt to see what I have added.

 

Best regards


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,757 posts
  • Gender:Male

Posted 07 December 2015 - 09:36 PM

Hi Andry,

 

Please check for new update in about 30 minutes.

 

Here is a slightly updated SortQuery event:

 

procedure TForm1.NextDBGrid61SortQuery(Sender: TObject; Index: Integer;
  SortKind: TNxSortKind; var Accept: Boolean);
var
  sFld: string;
begin
  sFld := NextDBGrid61.DataBinding[Index].FieldName;
 
  if nxQuery1.Active then
  begin
    // added in v6.0.6.
    // Don't auto-delete, auto-created cols.
    NextDBGrid61.DeactivationOptions := [];
 
    nxQuery1.SQL.Text := _changeSQLOrder(nxQuery1.SQL.Text,
      sFld + _sif(SortKind = skDescending, '', ' DESC'));
 
    nxQuery1.Open;
  end
  else if nxTable1.Active then  // works only on indexed fields and only in ascending mode - how to control sort indicator on column header to force ascending mode????
  begin
    nxTable1.IndexFieldNames := sFld;
  end;
end;

boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#9 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,757 posts
  • Gender:Male

Posted 07 December 2015 - 09:37 PM

Please tell me if it works better now, and if you find new issues.

 

Also, please read History.txt file for 2 new handy properties.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#10 andry

andry
  • Members
  • 6 posts

Posted 08 December 2015 - 12:49 PM

Thanks for the fast solution.

Now works fine in query mode while in table mode there are an access violation error but I think that is a NexusDB compatibility problem.

I'll do some orher test with other database engine and then tell you.

Of course you are free, if you want, to get my actual and possible future examples (or part of them), modify and use them as you want.



#11 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,757 posts
  • Gender:Male

Posted 08 December 2015 - 02:34 PM

Hi,

 

Great! I will test it more in Table example. If you find any cause of this error, I will like to implement it.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users