ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* context and sqlite
@ 2018-10-06 18:01 Jörg Hofmann
  2018-10-06 19:02 ` luigi scarso
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jörg Hofmann @ 2018-10-06 18:01 UTC (permalink / raw)
  To: ntg-context

I've been trying to connect ConTeXt to sqlite for almost a week
but I have repeatedly failed. Neither the
"internal" variant according to the documentation, nor the attempt on
luasql
have worked. Above all, the Google request showed me that
not alone with this problem - how reassuring. ;-)

At the moment, concentrate I am accessing via swiglib and think my
problem lies here (from my log file):

sql> start loading method 'sqlite'
swiglib> unknown: 'swiglib.sqlite.core'
swiglib> unknown: 'swiglib.helpers.core'

Obviously, the appropriate modules are not found, but where
Can I get them and where do they belong? And maybe
also someone a working code example for me.
I'm working with Texlive 2017 on XUBUNTU 16.04.

Best regards
Jörg Hofmann
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: context and sqlite
  2018-10-06 18:01 context and sqlite Jörg Hofmann
@ 2018-10-06 19:02 ` luigi scarso
  2018-10-06 20:07   ` luigi scarso
  2018-10-06 20:01 ` Hans Hagen
  2018-10-07  7:35 ` context and sqlite - here is the code Jörg Hofmann
  2 siblings, 1 reply; 8+ messages in thread
From: luigi scarso @ 2018-10-06 19:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 894 bytes --]

On Sat, Oct 6, 2018 at 8:01 PM Jörg Hofmann <webmaster@jho-home.de> wrote:

> I've been trying to connect ConTeXt to sqlite for almost a week
> but I have repeatedly failed. Neither the
> "internal" variant according to the documentation, nor the attempt on
> luasql
> have worked. Above all, the Google request showed me that
> not alone with this problem - how reassuring. ;-)
>
> At the moment, concentrate I am accessing via swiglib and think my
> problem lies here (from my log file):
>
> sql> start loading method 'sqlite'
> swiglib> unknown: 'swiglib.sqlite.core'
> swiglib> unknown: 'swiglib.helpers.core'
>
> Obviously, the appropriate modules are not found, but where
> Can I get them and where do they belong? And maybe
> also someone a working code example for me.
> I'm working with Texlive 2017 on XUBUNTU 16.04.
>

hm I will look into asap.

-- 
luigi

[-- Attachment #1.2: Type: text/html, Size: 1343 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: context and sqlite
  2018-10-06 18:01 context and sqlite Jörg Hofmann
  2018-10-06 19:02 ` luigi scarso
@ 2018-10-06 20:01 ` Hans Hagen
  2018-10-07  7:35 ` context and sqlite - here is the code Jörg Hofmann
  2 siblings, 0 replies; 8+ messages in thread
From: Hans Hagen @ 2018-10-06 20:01 UTC (permalink / raw)
  To: Jörg Hofmann,
	ntg-context@ntg.nl >> mailing list for ConTeXt users

On 10/6/2018 8:01 PM, Jörg Hofmann wrote:
> I've been trying to connect ConTeXt to sqlite for almost a week
> but I have repeatedly failed. Neither the
> "internal" variant according to the documentation, nor the attempt on
> luasql
> have worked. Above all, the Google request showed me that
> not alone with this problem - how reassuring. ;-)
> 
> At the moment, concentrate I am accessing via swiglib and think my
> problem lies here (from my log file):
> 
> sql> start loading method 'sqlite'
> swiglib> unknown: 'swiglib.sqlite.core'
> swiglib> unknown: 'swiglib.helpers.core'
> 
> Obviously, the appropriate modules are not found, but where
> Can I get them and where do they belong? And maybe
> also someone a working code example for me.
> I'm working with Texlive 2017 on XUBUNTU 16.04.
did you read the sql manual in the distribution ... it should work okay 
(no need for special lua module, all in the distribution)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: context and sqlite
  2018-10-06 19:02 ` luigi scarso
@ 2018-10-06 20:07   ` luigi scarso
  0 siblings, 0 replies; 8+ messages in thread
From: luigi scarso @ 2018-10-06 20:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1313 bytes --]

On Sat, Oct 6, 2018 at 9:02 PM luigi scarso <luigi.scarso@gmail.com> wrote:

>
>
> On Sat, Oct 6, 2018 at 8:01 PM Jörg Hofmann <webmaster@jho-home.de> wrote:
>
>> I've been trying to connect ConTeXt to sqlite for almost a week
>> but I have repeatedly failed. Neither the
>> "internal" variant according to the documentation, nor the attempt on
>> luasql
>> have worked. Above all, the Google request showed me that
>> not alone with this problem - how reassuring. ;-)
>>
>> At the moment, concentrate I am accessing via swiglib and think my
>> problem lies here (from my log file):
>>
>> sql> start loading method 'sqlite'
>> swiglib> unknown: 'swiglib.sqlite.core'
>> swiglib> unknown: 'swiglib.helpers.core'
>>
>> Obviously, the appropriate modules are not found, but where
>> Can I get them and where do they belong? And maybe
>> also someone a working code example for me.
>> I'm working with Texlive 2017 on XUBUNTU 16.04.
>>
>
> hm I will look into asap.
>
> The relevant docs are
tex/texmf-context/doc/context/documents/general/manuals/swiglib-mkiv.pdf
tex/texmf-context/doc/context/documents/general/manuals/sql-mkiv.pdf

The old svn site is gone , the new one is
https://serveur-svn.lri.fr/svn/modhel/swiglib
(see http://www.luatex.org/download.html)


-- 
luigi

[-- Attachment #1.2: Type: text/html, Size: 2295 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: context and sqlite - here is the code
  2018-10-06 18:01 context and sqlite Jörg Hofmann
  2018-10-06 19:02 ` luigi scarso
  2018-10-06 20:01 ` Hans Hagen
@ 2018-10-07  7:35 ` Jörg Hofmann
  2018-10-07 12:51   ` luigi scarso
  2018-10-07 14:06   ` Hans Hagen
  2 siblings, 2 replies; 8+ messages in thread
From: Jörg Hofmann @ 2018-10-07  7:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 1559 bytes --]

Hallo Hans,
hallo Luigi,

Am Samstag, den 06.10.2018, 20:01 +0200 schrieb Jörg Hofmann:
> I've been trying to connect ConTeXt to sqlite for almost a week
> but I have repeatedly failed. Neither the
> "internal" variant according to the documentation, nor the attempt on
> luasql
> have worked. Above all, the Google request showed me that
> not alone with this problem - how reassuring. ;-)
> 
> At the moment, concentrate I am accessing via swiglib and think my
> problem lies here (from my log file):
> 
> sql> start loading method 'sqlite'
> swiglib> unknown: 'swiglib.sqlite.core'
> swiglib> unknown: 'swiglib.helpers.core'
> 
> Obviously, the appropriate modules are not found, but where
> Can I get them and where do they belong? And maybe
> also someone a working code example for me.
> I'm working with Texlive 2017 on XUBUNTU 16.04.
> 
> Best regards
> Jörg Hofmann
> _____________________________________________________________________
> ______________
> If your question is of interest to others as well, please add an
> entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/nt
> g-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> _____________________________________________________________________
> ______________

Many thanks for your help. I have read both manuals but may not
understand it correctly. That's why I send my file and the log file.

Best regards
Jörg

[-- Attachment #2: lua-test.log --]
[-- Type: text/x-log, Size: 5293 bytes --]

open source     > level 1, order 1, name '/usr/local/texlive/2017/texmf-dist/tex/context/base/mkiv/cont-yes.mkiv'
system          > 
system          > ConTeXt  ver: 2017.05.15 21:48 MKIV beta  fmt: 2017.11.1  int: english/english
system          > 
system          > 'cont-new.mkiv' loaded
open source     > level 2, order 2, name '/usr/local/texlive/2017/texmf-dist/tex/context/base/mkiv/cont-new.mkiv'
close source    > level 2, order 2, name '/usr/local/texlive/2017/texmf-dist/tex/context/base/mkiv/cont-new.mkiv'
system          > files > jobname 'lua-test', input './lua-test', result 'lua-test'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > level 2, order 3, name '/home/jorg/Dokumente/Projekte/ConTeXt - Test/lua-test.tex'
fonts           > preloading latin modern fonts (second stage)
fonts           > 'fallback modern-designsize rm 12pt' is loaded
sql             > start loading method 'sqlite'
swiglib         > unknown: 'swiglib.sqlite.core'
swiglib         > unknown: 'swiglib.helpers.core'

lua error       > lua error on line 64 in file /home/jorg/Dokumente/Projekte/ConTeXt - Test/lua-test.tex:

...texmf-dist/tex/context/base/mkiv/util-sql-imp-sqlite.lua:36: attempt to index local 'sqlite' (a boolean value)
stack traceback:
	...texmf-dist/tex/context/base/mkiv/util-sql-imp-sqlite.lua:36: in main chunk
	[C]: in function 'requiem'
	...live/2017/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: in function <...live/2017/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:165>
	(...tail calls...)
	...xlive/2017/texmf-dist/tex/context/base/mkiv/util-sql.lua:114: in function '__index'
	...xlive/2017/texmf-dist/tex/context/base/mkiv/util-sql.lua:288: in function 'execute'
	[ctxlua]:38: in main chunk

42     
43     -- ***************************************************************************************************************
44     -- ** 1) intern mit swiglib 
45     -- ***************************************************************************************************************
46     
47     require("util-sql")
48     utilities.sql.setmethod("sqlite")
49     
50     local presets = {
51        database = db,
52 >>     }
53     
54     local data, keys = utilities.sql.execute {
55        presets = presets,
56        template = abfrage,
57        }
58     
59     context(data[titel])
60     context.crlf()
61     context(data[sachverhalt])
62     context.crlf()


? 

lua error       > lua error on line 64 in file /home/jorg/Dokumente/Projekte/ConTeXt - Test/lua-test.tex:

...texmf-dist/tex/context/base/mkiv/util-sql-imp-sqlite.lua:36: attempt to index local 'sqlite' (a boolean value)
stack traceback:
	...texmf-dist/tex/context/base/mkiv/util-sql-imp-sqlite.lua:36: in main chunk
	[C]: in function 'requiem'
	...live/2017/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: in function <...live/2017/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:165>
	(...tail calls...)
	...xlive/2017/texmf-dist/tex/context/base/mkiv/util-sql.lua:114: in function '__index'
	...xlive/2017/texmf-dist/tex/context/base/mkiv/util-sql.lua:288: in function 'execute'
	[ctxlua]:38: in main chunk

42     
43     -- ***************************************************************************************************************
44     -- ** 1) intern mit swiglib 
45     -- ***************************************************************************************************************
46     
47     require("util-sql")
48     utilities.sql.setmethod("sqlite")
49     
50     local presets = {
51        database = db,
52 >>     }
53     
54     local data, keys = utilities.sql.execute {
55        presets = presets,
56        template = abfrage,
57        }
58     
59     context(data[titel])
60     context.crlf()
61     context(data[sachverhalt])
62     context.crlf()


? 

lua error       > lua error on line 64 in file /home/jorg/Dokumente/Projekte/ConTeXt - Test/lua-test.tex:

...texmf-dist/tex/context/base/mkiv/util-sql-imp-sqlite.lua:36: attempt to index local 'sqlite' (a boolean value)
stack traceback:
	...texmf-dist/tex/context/base/mkiv/util-sql-imp-sqlite.lua:36: in main chunk
	[C]: in function 'requiem'
	...live/2017/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: in function <...live/2017/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:165>
	(...tail calls...)
	...xlive/2017/texmf-dist/tex/context/base/mkiv/util-sql.lua:114: in function '__index'
	...xlive/2017/texmf-dist/tex/context/base/mkiv/util-sql.lua:288: in function 'execute'
	[ctxlua]:38: in main chunk

42     
43     -- ***************************************************************************************************************
44     -- ** 1) intern mit swiglib 
45     -- ***************************************************************************************************************
46     
47     require("util-sql")
48     utilities.sql.setmethod("sqlite")
49     
50     local presets = {
51        database = db,
52 >>     }
53     
54     local data, keys = utilities.sql.execute {
55        presets = presets,
56        template = abfrage,
57        }
58     
59     context(data[titel])
60     context.crlf()
61     context(data[sachverhalt])
62     context.crlf()

End of file on the terminal!



[-- Attachment #3: lua-test.tex --]
[-- Type: text/x-tex, Size: 1358 bytes --]

\setuppapersize[A4]

\setuplayout[
   %leftmargin=90mm,
   backspace=10mm,
   width=100mm,
   %rightmargin=35mm
   ]
%
%
%\definelayout[ErsteSeiten][
%   leftmargin=100mm,
%   rightmargin=20mm
%   ]
   
\starttext
\startluacode

-- local a=3
-- local b=5
-- local c = a + b
-- context("Hallo Josh")
-- context.crlf()
-- context("a= %s und b= %s. a + b = %s.",a, b, c)

-- ***************************************************************************************************************
-- ** Abfragen mit SQL  
-- ***************************************************************************************************************

local abfrage = [[
   SELECT
      `titel`, `sachverhalt`, `auftraege`
   FROM
      `aufgabe`
   WHERE `id` = '1';
   ]]


local db = "aufgaben.sqlite"



-- ***************************************************************************************************************
-- ** 1) intern mit swiglib 
-- ***************************************************************************************************************

require("util-sql")
utilities.sql.setmethod("sqlite")

local presets = {
   database = db,
   }

local data, keys = utilities.sql.execute {
   presets = presets,
   template = abfrage,
   }

context(data[titel])
context.crlf()
context(data[sachverhalt])
context.crlf()
context(data[auftraege])
\stopluacode
\stoptext

[-- Attachment #4: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: context and sqlite - here is the code
  2018-10-07  7:35 ` context and sqlite - here is the code Jörg Hofmann
@ 2018-10-07 12:51   ` luigi scarso
  2018-10-07 14:06   ` Hans Hagen
  1 sibling, 0 replies; 8+ messages in thread
From: luigi scarso @ 2018-10-07 12:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1139 bytes --]

On Sun, Oct 7, 2018 at 9:35 AM Jörg Hofmann <webmaster@jho-home.de> wrote:

> Hallo Hans,
> hallo Luigi,
>
> Am Samstag, den 06.10.2018, 20:01 +0200 schrieb Jörg Hofmann:
> > I've been trying to connect ConTeXt to sqlite for almost a week
> > but I have repeatedly failed. Neither the
> > "internal" variant according to the documentation, nor the attempt on
> > luasql
> > have worked. Above all, the Google request showed me that
> > not alone with this problem - how reassuring. ;-)
> >
> > At the moment, concentrate I am accessing via swiglib and think my
> > problem lies here (from my log file):
> >
> > sql> start loading method 'sqlite'
> > swiglib> unknown: 'swiglib.sqlite.core'
> > swiglib> unknown: 'swiglib.helpers.core'
>
>
hm,  sqlite uses luaffi, not swiglib.

Put libsqlite3.so  in the same folder of your example, and rename it
as sqlite3.so

Then put in your example
\setuppapersize[A4]
\enabletrackers[resolvers.ffilib]
\enabletrackers[sql.trace]
\enabletrackers[sql.queries]

I think that at least you should see something like
found: '/<some_paths_here>/sqlite3.so'

-- 
luigi

[-- Attachment #1.2: Type: text/html, Size: 1839 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: context and sqlite - here is the code
  2018-10-07  7:35 ` context and sqlite - here is the code Jörg Hofmann
  2018-10-07 12:51   ` luigi scarso
@ 2018-10-07 14:06   ` Hans Hagen
  2018-10-13  6:39     ` context and sqlite - it works ;-) Jörg Hofmann
  1 sibling, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2018-10-07 14:06 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Jörg Hofmann

[-- Attachment #1: Type: text/plain, Size: 2692 bytes --]

On 10/7/2018 9:35 AM, Jörg Hofmann wrote:
> Hallo Hans,
> hallo Luigi,
> 
> Am Samstag, den 06.10.2018, 20:01 +0200 schrieb Jörg Hofmann:
>> I've been trying to connect ConTeXt to sqlite for almost a week
>> but I have repeatedly failed. Neither the
>> "internal" variant according to the documentation, nor the attempt on
>> luasql
>> have worked. Above all, the Google request showed me that
>> not alone with this problem - how reassuring. ;-)
>>
>> At the moment, concentrate I am accessing via swiglib and think my
>> problem lies here (from my log file):
>>
>> sql> start loading method 'sqlite'
>> swiglib> unknown: 'swiglib.sqlite.core'
>> swiglib> unknown: 'swiglib.helpers.core'
>>
>> Obviously, the appropriate modules are not found, but where
>> Can I get them and where do they belong? And maybe
>> also someone a working code example for me.
>> I'm working with Texlive 2017 on XUBUNTU 16.04.
>
> Many thanks for your help. I have read both manuals but may not
> understand it correctly. That's why I send my file and the log file.
the latest versions of context use ffi for mysql and sqlite interfacing 
so you just need the libraries

if you add \enabletrackers[*ffi*] to your file you get something

ffilib          > requiring library 'sqlite3' with version 'any'
ffilib          > tds path 1: .
ffilib          > tds path 2: 
c:/data/develop/tex-context/tex/texmf-win64/bin/lib/context/lua//
ffilib          > tds path 3: 
c:/data/develop/tex-context/tex/texmf-win64/bin/lib/luatex/lua//
ffilib          > tds path 4: 
c:/data/develop/tex-context/tex/texmf-win64/bin/lib//lua//
ffilib          > attemp 1, engine 'luatex'
ffilib          > checking tds lib paths strictly
ffilib          > checking with version: 'sqlite3.dll'
ffilib          > found: 
'c:/data/develop/tex-context/tex/texmf-win64/bin/lib/luatex/lua/copies/sqlite/sqlite3.dll'
ffilib          > stored library: 'sqlite3'
sql             > loading method 'sqlite' done

anyway, best keep your libe in the tex tree because otherwise you get 
some random one that is found on your system

attached a better example file (hard to test without a database here so 
need to make one ... next time proviode a real mwe)

in util-sql-imp-sqlite.lua remove a pragma line so we get:

local f_preamble = formatters[ [[
ATTACH `%s` AS `%s` ;
PRAGMA `%s`.synchronous = normal ;
]] ]



-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

[-- Attachment #2: lua-test.tex --]
[-- Type: text/plain, Size: 2763 bytes --]

\starttext

\enabletrackers[*ffi*]

\startluacode
require("util-sql")

local sql = utilities.sql

sql.setmethod("sqlite")

document.sqlpresets = {
    database = "aufgaben",
    id       = "aufgaben",
}

local template = [[
    CREATE TABLE IF NOT EXISTS `aufgaben` (
        `id`          INTEGER PRIMARY KEY AUTOINCREMENT,
        `titel`       BLOB NOT NULL,
        `sachverhalt` BLOB NOT NULL,
        `auftraege`   BLOB NOT NULL
    ) ;
]]

function document.createdatabase()

    return utilities.sql.execute {
        presets   = document.sqlpresets,
        template  = template,
    }

end

local template = [[
    INSERT INTO `aufgaben` (
        `titel`,
        `sachverhalt`,
        `auftraege`
    ) VALUES (
        '%titel%',
        '%sachverhalt%',
        '%auftraege%'
    ) ;
]]

function document.addtodatabase(t)

    return utilities.sql.execute {
        presets   = document.sqlpresets,
        template  = template,
        variables = {
            titel       = t.titel,
            sachverhalt = t.sachverhalt,
            auftraege   = t.auftraege,
        },
    }

end

local template_id = [[
    SELECT
        *
    FROM
        `aufgaben`
    WHERE
        `id` = '%id%' ;
]]

document.sqlconverter = sql.makeconverter {
    { name = "id",          type = "number" },
    { name = "titel",       type = "string" },
    { name = "sachverhalt", type = "string" },
    { name = "auftraege",   type = "string" },
}

function document.getfromdatabase(t)

    if t.id then

        return utilities.sql.execute {
            presets   = document.sqlpresets,
            template  = template_id,
            variables = { id = t.id },
         -- converter = document.sqlconverter,
        }

    end

end

\stopluacode

\startluacode

document.createdatabase()

local tufte = io.loaddata(resolvers.findfile("tufte.tex"))
local ward  = io.loaddata(resolvers.findfile("ward.tex"))
local knuth = io.loaddata(resolvers.findfile("knuth.tex"))

document.addtodatabase { titel = "aufgabe 1", sachverhalt = "one",   auftraege = tufte }
document.addtodatabase { titel = "aufgabe 2", sachverhalt = "two",   auftraege = ward }
document.addtodatabase { titel = "aufgabe 3", sachverhalt = "three", auftraege = knuth }

function document.showrecord(n)

    local result = document.getfromdatabase { id = n }

    for i=1,#result do
        local r = result[i]
        if r.titel then
            context.title(r.titel)
            context.subject(r.sachverhalt)
            context.par()
            context("text: ")
            context.viafile(r.auftraege)
            context.page()
        end
    end

end
\stopluacode

\startluacode
    document.showrecord(1)
    document.showrecord(2)
    document.showrecord(3)
\stopluacode

\stoptext


[-- Attachment #3: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: context and sqlite - it works ;-)
  2018-10-07 14:06   ` Hans Hagen
@ 2018-10-13  6:39     ` Jörg Hofmann
  0 siblings, 0 replies; 8+ messages in thread
From: Jörg Hofmann @ 2018-10-13  6:39 UTC (permalink / raw)
  To: Hans Hagen, mailing list for ConTeXt users

Hallo Hans,
hallo Luigi,

thank you for your help. After I've re-installed ConTeXt, everything
works fine.

Have a nice weekend
Jörg


Am Sonntag, den 07.10.2018, 16:06 +0200 schrieb Hans Hagen:
> anyway, best keep your libe in the tex tree because otherwise you
> get 
> some random one that is found on your system
> 
> attached a better example file (hard to test without a database here
> so 
> need to make one ... next time proviode a real mwe)
> 
> in util-sql-imp-sqlite.lua remove a pragma line so we get:
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-10-13  6:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-06 18:01 context and sqlite Jörg Hofmann
2018-10-06 19:02 ` luigi scarso
2018-10-06 20:07   ` luigi scarso
2018-10-06 20:01 ` Hans Hagen
2018-10-07  7:35 ` context and sqlite - here is the code Jörg Hofmann
2018-10-07 12:51   ` luigi scarso
2018-10-07 14:06   ` Hans Hagen
2018-10-13  6:39     ` context and sqlite - it works ;-) Jörg Hofmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).