File: databases.page

package info (click to toggle)
gnome-devel-docs 40.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 79,188 kB
  • sloc: javascript: 2,514; xml: 2,407; ansic: 2,229; python: 1,854; makefile: 805; sh: 499; cpp: 131
file content (117 lines) | stat: -rw-r--r-- 5,341 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?xml version="1.0" encoding="utf-8"?>
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2003/XInclude" type="topic" id="databases" xml:lang="sv">

  <info>
    <link type="guide" xref="index#specific-how-tos"/>

    <credit type="author copyright">
      <name>Philip Withnall</name>
      <email its:translate="no">philip.withnall@collabora.co.uk</email>
      <years>2015</years>
    </credit>

    <include xmlns="http://www.w3.org/2001/XInclude" href="cc-by-sa-3-0.xml"/>

    <desc>Enkla beständiga objektlagringar</desc>
  
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
      <mal:name>Anders Jonsson</mal:name>
      <mal:email>anders.jonsson@norsjovallen.se</mal:email>
      <mal:years>2018</mal:years>
    </mal:credit>
  </info>

  <title>Databaser</title>

  <synopsis>
    <title>Sammanfattning</title>

    <list>
      <item><p>Använd databaser för lämpliga användningsområden: inte konfigurationsdata (använd GSettings). (<link xref="#when-to-use-databases"/>)</p></item>
      <item><p>Välj mellan GOM och GVDB beroende på om indexering krävs. (<link xref="#when-to-use-databases"/>)</p></item>
      <item><p>
        Consider your vacuuming policy before committing to using GOM.
        (<link xref="#when-to-use-databases"/>)
      </p></item>
      <item><p>Undvik SQL-injektionssårbarheter genom att använda förberedda satser. (<link xref="#sql-injection"/>)</p></item>
    </list>
  </synopsis>

  <section id="when-to-use-databases">
    <title>När databaser bör användas</title>

    <p>
      Configuration data should be stored in
      <link href="https://developer.gnome.org/gio/stable/GSettings.html">GSettings</link>.
      As a rule of thumb, if some data needs to be persistent and affects how an
      application behaves, it is configuration data. If it could potentially be
      subject to policies imposed by the system administrator (such as proxy or
      lockdown settings), it is configuration data. If it contains user created
      content, it is not configuration data, and should not be stored in
      GSettings.
    </p>

    <p>
      For such situations where user data is highly structured, storing it in a
      database is sensible. There are two main databases suggested for use
      within GNOME: GOM and GVDB. GOM is a wrapper around SQLite, and hence
      implements indexing of fields and SQL-style queries. GVDB is a much
      simpler object store, supporting fast serialization of a dictionary of
      objects to disk.
    </p>

    <p>GOM bör användas om du behöver avancerade funktioner, i synnerhet indexering. I annat fall bör GVDB användas.</p>

    <p>
      Before deciding to use GOM (and hence SQLite), you must consider a
      vacuuming policy for the database, and whether your use case will interact
      well with SQLite’s vacuuming system. Vacuuming is effectively SQLite’s
      term for defragmenting the database — if a database is not vacuumed
      appropriately, performance will degrade and the database size will
      increase indefinitely. Read
      <link href="http://blogs.gnome.org/jnelson/2015/01/06/sqlite-vacuum-and-auto_vacuum/">this
      article</link> on vacuuming for more information; please consider it
      before choosing to use GOM.
    </p>

    <p>
      GNOME has another database library: GNOME Data Access (GDA). This is
      targeted at abstracting access to various types of relational database,
      for use in a database utility program or office program, for example. It
      is not suitable for storing
      <link href="https://developer.gnome.org/gio/stable/GSettings.html">user
      settings</link>.
    </p>
  </section>

  <section id="gom">
    <title>Använda GOM</title>

    <p>Att tillhandahålla en GOM-handledning är utanför ändamålet för detta dokument, men en <link href="https://developer.gnome.org/gom/">referenshandbok finns tillgänglig</link>.</p>

    <section id="sql-injection">
      <title>SQL-injektion</title>

      <p>
        GOM does allow access to the lower level SQLite query APIs. When using
        them, queries <em style="strong">must</em> be constructed using
        SQLite’s <link href="https://www.sqlite.org/c3ref/stmt.html">prepared
        statement</link> and
        <link href="https://www.sqlite.org/c3ref/bind_blob.html">value
        binding</link> API, rather than by constructing SQL strings then passing
        them to SQLite to parse. Constructing strings makes
        <link href="https://en.wikipedia.org/wiki/SQL_injection">SQL
        injection</link> vulnerabilities very likely, which can give attackers
        access to arbitrary user data from the database.
      </p>
    </section>
  </section>

  <section id="gvdb">
    <title>Använda GVDB</title>

    <p>GVDB har ett enkelt API som speglar en konventiell hashtabell. För närvarande finns GVDB endast tillgängligt som ett kopiera-och-klistra-bibliotek; hämta den senaste versionen av koden från <link href="https://gitlab.gnome.org/GNOME/gvdb">GVDB:s git</link> och kopiera den till ditt projekt. Det är licensierat under LGPLv2.1+.</p>

    <p>En fullständig GVDB-handledning är utanför ändamålet för detta dokument.</p>
  </section>
</page>