aboutsummarylogtreecommitdiffstats
path: root/url_constr.pas
blob: 27977205e028fd662dcff05e6b357284d219ed47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{ Construct URLs by page id}
unit url_constr;

{$mode ObjFPC}{$H+}

interface

uses
       SysUtils, SQLite3Conn, SQLDB;
     { Создает адреса ссылок c учетом иерархии }
     function getTreeUrl(ContentID: String;
        fileNameExt : String;
       var   konnect: TSQLite3Connection;
       var tranzact: TSQLTransaction ) : String;

implementation



function getTreeUrl(ContentID: String;
    fileNameExt : String;
   var   konnect: TSQLite3Connection;
   var tranzact: TSQLTransaction ) : String;

var

  sqlQuery: TSQLQuery;
begin
  // Initialize the connection and transaction objects
  sqlQuery := TSQLQuery.Create(nil);

  try
    sqlQuery.Database := konnect;
    sqlQuery.Transaction := tranzact;
    sqlQuery.SQL.Text := 'SELECT section.tree || "/" || content.section || "/" || content.id  AS url ' +
                         'FROM content ' +
                         'JOIN section ' +
                         'ON content.section = section.id ' +
                         'WHERE content.id = :ID';

    sqlQuery.ParamByName('ID').AsString := ContentID;
    // Execute the query
      sqlQuery.Open;

     Result :=  sqlQuery.FieldByName('url').AsString  + fileNameExt;

  finally
      // Free the objects
    sqlQuery.Free;
  end;
end;


end.