Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sqlite resource #6

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions THIRDPARTY.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
godot-sqlite

MIT License

Copyright (c) 2019-2024 Piet Bronders & Jeroen De Geeter

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 5 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ def configure(env):

def get_doc_classes():
return [
"SQLite",
"SQLiteAccess",
"SQLiteQuery",
"SQLiteQueryResult",
"SQLiteDatabase",
"SQLiteColumnSchema",
"SQLite",
]


Expand Down
49 changes: 8 additions & 41 deletions doc_classes/SQLite.xml
Original file line number Diff line number Diff line change
@@ -1,49 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="SQLite" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<class name="SQLite" inherits="Node" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Wrapper class for SQLite databases.
Node containing a [SQLiteDatabase] resource.
</brief_description>
<description>
A wrapper class that lets you perform SQL statements on an SQLite database file.
For queries that involve arbitrary user input, you should use methods that end in [code]*_with_args[/code], as these protect against SQL injection.
Node containing a [SQLiteDatabase] resource.
</description>
<tutorials>
</tutorials>
<methods>
<method name="close">
<return type="void" />
<description>
Closes the database handle.
</description>
</method>
<method name="create_query">
<return type="SQLiteQuery" />
<param index="0" name="statement" type="String" />
<description>
</description>
</method>
<method name="open">
<return type="bool" />
<param index="0" name="path" type="String" />
<description>
Opens the database file at the given path. Returns [code]true[/code] if the database was successfully opened, [code]false[/code] otherwise.
If the path starts with "res://", it will use [method open_buffered] implicitly.
</description>
</method>
<method name="open_buffered">
<return type="bool" />
<param index="0" name="path" type="String" />
<param index="1" name="buffers" type="PackedByteArray" />
<param index="2" name="size" type="int" />
<description>
Opens a temporary database with the data in [code]buffer[/code]. Used for opening databases stored in res:// or compressed databases. Returns [code]true[/code] if the database was opened successfully.
Can be written to, but the changes are NOT saved!
</description>
</method>
<method name="open_in_memory">
<return type="bool" />
<description>
</description>
</method>
</methods>
<members>
<member name="database" type="SQLiteDatabase" setter="set_database" getter="get_database">
Database resource. In order to create an in memory database, call [method SQLiteDatabase.create]
</member>
</members>
</class>
71 changes: 71 additions & 0 deletions doc_classes/SQLiteAccess.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="SQLiteAccess" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Wrapper class for SQLite databases.
</brief_description>
<description>
A wrapper class that lets you perform SQL statements on an SQLite database file.
For queries that involve arbitrary user input, you should use methods that end in [code]*_with_args[/code], as these protect against SQL injection.
</description>
<tutorials>
</tutorials>
<methods>
<method name="backup">
<return type="bool" />
<param index="0" name="path" type="String" />
<description>
Creates a backup of the database at the given path.
</description>
</method>
<method name="close">
<return type="bool" />
<description>
Closes the database handle.
</description>
</method>
<method name="create_query">
<return type="SQLiteQuery" />
<param index="0" name="statement" type="String" />
<param index="1" name="arguments" type="Array" default="[]" />
<description>
Creates a new query object.
</description>
</method>
<method name="get_last_error_code" qualifiers="const">
<return type="int" />
<description>
Gets the last error code.
</description>
</method>
<method name="get_last_error_message" qualifiers="const">
<return type="String" />
<description>
Gets the last error message.
</description>
</method>
<method name="open">
<return type="bool" />
<param index="0" name="database" type="String" />
<description>
Opens the database file at the given path. Returns [code]true[/code] if the database was successfully opened, [code]false[/code] otherwise.
If the path starts with "res://", it will use [method open_buffered] implicitly.
</description>
</method>
<method name="open_buffered">
<return type="bool" />
<param index="0" name="path" type="String" />
<param index="1" name="buffers" type="PackedByteArray" />
<param index="2" name="size" type="int" />
<description>
Opens a temporary database with the data in [code]buffer[/code]. Used for opening databases stored in res:// or compressed databases. Returns [code]true[/code] if the database was opened successfully.
Can be written to, but the changes are NOT saved!
</description>
</method>
<method name="open_in_memory">
<return type="bool" />
<description>
Opens an in-memory database.
</description>
</method>
</methods>
</class>
39 changes: 39 additions & 0 deletions doc_classes/SQLiteColumnSchema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="SQLiteColumnSchema" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="create" qualifiers="static">
<return type="SQLiteColumnSchema" />
<param index="0" name="name" type="String" />
<param index="1" name="type" type="int" enum="Variant.Type" default="4" />
<param index="2" name="default_value" type="Variant" default="null" />
<param index="3" name="primary_key" type="bool" default="false" />
<param index="4" name="auto_increment" type="bool" default="false" />
<param index="5" name="not_null" type="bool" default="false" />
<param index="6" name="unique" type="bool" default="false" />
<description>
</description>
</method>
</methods>
<members>
<member name="auto_increment" type="bool" setter="set_auto_increment" getter="is_auto_increment" default="false">
</member>
<member name="default_value" type="Variant" setter="set_default_value" getter="get_default_value" default="null">
</member>
<member name="name" type="String" setter="set_name" getter="get_name" default="&quot;&quot;">
</member>
<member name="not_null" type="bool" setter="set_not_null" getter="is_not_null" default="false">
</member>
<member name="primary_key" type="bool" setter="set_primary_key" getter="is_primary_key" default="false">
</member>
<member name="type" type="int" setter="set_type" getter="get_type" enum="Variant.Type" default="0">
</member>
<member name="unique" type="bool" setter="set_unique" getter="is_unique" default="false">
</member>
</members>
</class>
100 changes: 100 additions & 0 deletions doc_classes/SQLiteDatabase.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="SQLiteDatabase" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A SQLite database resource. Can be either in-memory or load a database from a file.
</brief_description>
<description>
A SQLite database resource.
</description>
<tutorials>
</tutorials>
<methods>
<method name="create_query">
<return type="SQLiteQuery" />
<param index="0" name="query" type="String" />
<param index="1" name="arguments" type="Array" />
<description>
Creates a new query object.
</description>
</method>
<method name="create_table">
<return type="SQLiteQuery" />
<param index="0" name="table_name" type="String" />
<param index="1" name="columns" type="SQLiteColumnSchema[]" />
<description>
Creates a new table.
</description>
</method>
<method name="delete_rows">
<return type="SQLiteQuery" />
<param index="0" name="table_name" type="String" />
<param index="1" name="condition" type="String" default="&quot;&quot;" />
<description>
Deletes rows from a table.
</description>
</method>
<method name="drop_table">
<return type="SQLiteQuery" />
<param index="0" name="table_name" type="String" />
<description>
Drops a table.
</description>
</method>
<method name="execute_query">
<return type="SQLiteQueryResult" />
<param index="0" name="query" type="String" />
<param index="1" name="arguments" type="Array" />
<description>
Create and execute a query directly.
</description>
</method>
<method name="get_columns" qualifiers="const">
<return type="SQLiteColumnSchema[]" />
<param index="0" name="table_name" type="String" />
<description>
Returns the columns of a table.
</description>
</method>
<method name="get_sqlite">
<return type="SQLiteAccess" />
<description>
Returns the underlying [SQLite] object.
</description>
</method>
<method name="insert_row">
<return type="SQLiteQuery" />
<param index="0" name="table_name" type="String" />
<param index="1" name="value" type="Dictionary" />
<description>
Inserts a row into a table.
</description>
</method>
<method name="insert_rows">
<return type="SQLiteQuery" />
<param index="0" name="table_name" type="String" />
<param index="1" name="values" type="Dictionary[]" />
<description>
Inserts multiple rows into a table.
</description>
</method>
<method name="select_rows">
<return type="SQLiteQuery" />
<param index="0" name="table_name" type="String" />
<param index="1" name="condition" type="String" default="&quot;&quot;" />
<description>
Selects rows from a table.
</description>
</method>
<method name="set_data">
<return type="void" />
<param index="0" name="data" type="PackedByteArray" />
<description>
Sets the data of the database.
</description>
</method>
</methods>
<members>
<member name="tables" type="Dictionary" setter="" getter="get_tables" default="{}">
</member>
</members>
</class>
16 changes: 12 additions & 4 deletions doc_classes/SQLiteQuery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
</tutorials>
<methods>
<method name="batch_execute">
<return type="Variant" />
<param index="0" name="rows" type="Array" />
<return type="SQLiteQueryResult[]" />
<param index="0" name="rows" type="Array[]" />
<description>
Executes a batch of SQL queries. The queries are provided as an array of strings. Returns the result of the last query in the batch.
</description>
</method>
<method name="execute">
<return type="Variant" />
<return type="SQLiteQueryResult" />
<param index="0" name="arguments" type="Array" default="[]" />
<description>
Executes a single SQL query. The query is provided as a string. If the query requires arguments, they can be provided as an array. Returns the result of the query.
</description>
</method>
<method name="get_columns">
<return type="Array" />
<return type="SQLiteColumnSchema[]" />
<description>
Returns an array of column names from the last executed query.
</description>
Expand All @@ -36,4 +36,12 @@
</description>
</method>
</methods>
<members>
<member name="arguments" type="Array" setter="set_arguments" getter="get_arguments" default="[]">
Arguments for the query.
</member>
<member name="query" type="String" setter="" getter="get_query" default="&quot;&quot;">
The query executed.
</member>
</members>
</class>
28 changes: 28 additions & 0 deletions doc_classes/SQLiteQueryResult.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="SQLiteQueryResult" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A result from a [SQLiteQuery] run.
</brief_description>
<description>
A result from a [SQLiteQuery] run.
</description>
<tutorials>
</tutorials>
<members>
<member name="arguments" type="Array" setter="" getter="get_arguments" default="[]">
The arguments of the query.
</member>
<member name="error" type="String" setter="" getter="get_error" default="&quot;&quot;">
Present if there is an error.
</member>
<member name="error_code" type="int" setter="" getter="get_error_code" default="0">
Present if there is an error.
</member>
<member name="query" type="String" setter="" getter="get_query" default="&quot;&quot;">
The query that was run.
</member>
<member name="result" type="Array[]" setter="" getter="get_result" default="[]">
The result of the query.
</member>
</members>
</class>
7 changes: 7 additions & 0 deletions icons/NodeSQLite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading