|
Packit |
1470ea |
|
|
Packit |
1470ea |
<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="el">
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<link type="guide" xref="index#specific-how-tos"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Philip Withnall</name>
|
|
Packit |
1470ea |
<email its:translate="no">philip.withnall@collabora.co.uk</email>
|
|
Packit |
1470ea |
<years>2015</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<include xmlns="http://www.w3.org/2001/XInclude" href="cc-by-sa-3-0.xml"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Simple persistent object stores</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Ελληνική μεταφραστική ομάδα GNOME</mal:name>
|
|
Packit |
1470ea |
<mal:email>team@gnome.gr</mal:email>
|
|
Packit |
1470ea |
<mal:years>2016</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Θάνος Τρυφωνίδης</mal:name>
|
|
Packit |
1470ea |
<mal:email>tomtryf@gnome.org</mal:email>
|
|
Packit |
1470ea |
<mal:years>2016</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Βάσεις δεδομένων</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<synopsis>
|
|
Packit |
1470ea |
<title>Σύνοψη</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>
|
|
Packit |
1470ea |
Use databases for appropriate use cases: not configuration data (use
|
|
Packit |
1470ea |
GSettings). (<link xref="#when-to-use-databases"/>)
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
<item>
|
|
Packit |
1470ea |
Choose between GOM and GVDB based on whether indexing is required.
|
|
Packit |
1470ea |
(<link xref="#when-to-use-databases"/>)
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
<item>
|
|
Packit |
1470ea |
Consider your vacuuming policy before committing to using GOM.
|
|
Packit |
1470ea |
(<link xref="#when-to-use-databases"/>)
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
<item>
|
|
Packit |
1470ea |
Avoid SQL injection vulnerabilities by using prepared statements.
|
|
Packit |
1470ea |
(<link xref="#sql-injection"/>)
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</synopsis>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="when-to-use-databases">
|
|
Packit |
1470ea |
<title>Πότε να χρησιμοποιήσετε βάσεις δεδομένων</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Configuration data should be stored in
|
|
Packit |
1470ea |
<link href="https://developer.gnome.org/gio/stable/GSettings.html">GSettings</link>.
|
|
Packit |
1470ea |
As a rule of thumb, if some data needs to be persistent and affects how an
|
|
Packit |
1470ea |
application behaves, it is configuration data. If it could potentially be
|
|
Packit |
1470ea |
subject to policies imposed by the system administrator (such as proxy or
|
|
Packit |
1470ea |
lockdown settings), it is configuration data. If it contains user created
|
|
Packit |
1470ea |
content, it is not configuration data, and should not be stored in
|
|
Packit |
1470ea |
GSettings.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
For such situations where user data is highly structured, storing it in a
|
|
Packit |
1470ea |
database is sensible. There are two main databases suggested for use
|
|
Packit |
1470ea |
within GNOME: GOM and GVDB. GOM is a wrapper around SQLite, and hence
|
|
Packit |
1470ea |
implements indexing of fields and SQL-style queries. GVDB is a much
|
|
Packit |
1470ea |
simpler object store, supporting fast serialization of a dictionary of
|
|
Packit |
1470ea |
objects to disk.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GOM should be used if you need advanced features, especially indexing.
|
|
Packit |
1470ea |
GVDB should be used otherwise.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Before deciding to use GOM (and hence SQLite), you must consider a
|
|
Packit |
1470ea |
vacuuming policy for the database, and whether your use case will interact
|
|
Packit |
1470ea |
well with SQLite’s vacuuming system. Vacuuming is effectively SQLite’s
|
|
Packit |
1470ea |
term for defragmenting the database — if a database is not vacuumed
|
|
Packit |
1470ea |
appropriately, performance will degrade and the database size will
|
|
Packit |
1470ea |
increase indefinitely. Read
|
|
Packit |
1470ea |
<link href="http://blogs.gnome.org/jnelson/2015/01/06/sqlite-vacuum-and-auto_vacuum/">this
|
|
Packit |
1470ea |
article</link> on vacuuming for more information; please consider it
|
|
Packit |
1470ea |
before choosing to use GOM.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GNOME has another database library: GNOME Data Access (GDA). This is
|
|
Packit |
1470ea |
targeted at abstracting access to various types of relational database,
|
|
Packit |
1470ea |
for use in a database utility program or office program, for example. It
|
|
Packit |
1470ea |
is not suitable for storing
|
|
Packit |
1470ea |
<link href="https://developer.gnome.org/gio/stable/GSettings.html">user
|
|
Packit |
1470ea |
settings</link>.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="gom">
|
|
Packit |
1470ea |
<title>Χρήση του GOM</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Providing a GOM tutorial is beyond the scope of this document, but a
|
|
Packit |
1470ea |
<link href="https://developer.gnome.org/gom/">reference manual is
|
|
Packit |
1470ea |
available</link>.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="sql-injection">
|
|
Packit |
1470ea |
<title>SQL Injection</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GOM does allow access to the lower level SQLite query APIs. When using
|
|
Packit |
1470ea |
them, queries must be constructed using
|
|
Packit |
1470ea |
SQLite’s <link href="https://www.sqlite.org/c3ref/stmt.html">prepared
|
|
Packit |
1470ea |
statement</link> and
|
|
Packit |
1470ea |
<link href="https://www.sqlite.org/c3ref/bind_blob.html">value
|
|
Packit |
1470ea |
binding</link> API, rather than by constructing SQL strings then passing
|
|
Packit |
1470ea |
them to SQLite to parse. Constructing strings makes
|
|
Packit |
1470ea |
<link href="http://en.wikipedia.org/wiki/SQL_injection">SQL
|
|
Packit |
1470ea |
injection</link> vulnerabilities very likely, which can give attackers
|
|
Packit |
1470ea |
access to arbitrary user data from the database.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="gvdb">
|
|
Packit |
1470ea |
<title>Χρήση του GVDB</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GVDB has a simple API which mirrors a conventional hash table. Presently,
|
|
Packit |
1470ea |
GVDB is only available as a copy-and-paste library; fetch the most recent
|
|
Packit |
1470ea |
copy of the code from
|
|
Packit |
1470ea |
<link href="https://git.gnome.org/browse/gvdb">GVDB git</link> and copy
|
|
Packit |
1470ea |
it into your project. It is licenced under LGPLv2.1+.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
A full GVDB tutorial is beyond the scope of this document.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|