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

Extension Loading #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Extension Loading #200

wants to merge 1 commit into from

Conversation

ugursoy
Copy link

@ugursoy ugursoy commented Jan 31, 2025

SQLite presents an SQL function "load_extension()" for extension loading, but it is disabled by default for security.

These commits include two methods to achieve extension loading:

  • enable_load_extension: sets a flag that enables both C-API and SQL function (NOT recommended by SQLite documentation, see Security Warning section). But this is the only way for SQL function to work AFAIK.

  • load_extension: provides an interface for C-API. It enables C-API only and disables it afterwards.

Both methods basically call the corresponding sqlite3 functions with the given parameters, nothing fancy. Necessary explanations are also added into the documentation about how to use them.

@2shady4u 2shady4u added the enhancement New feature or request label Feb 1, 2025
Copy link
Owner

@2shady4u 2shady4u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @ugursoy

Seems like the static checks pipeline fails 😢 Should be easy fix! 😄

Also:

  • Would it be possible to squash your commits?
  • Would it be possible to add the documentation to the README.md as well?

src/gdsqlite.cpp Outdated
@@ -1,4 +1,5 @@
#include "gdsqlite.h"
#include "godot_cpp/variant/utility_functions.hpp"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include is already defined in the header file... not necessary to include it a second time 😄


int rc;

char *zErrMsg = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have the sqlite3_free() this memory if it gets assigned.
image
(I think I don't always do this in the rest of the code btw 😖 )

<method name="enable_load_extension">
<return type="int" />
<description>
Extension loading is disabled by default for security reasons. There are two ways to load an extension: C-API and SQL function. This method turns on both options.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a link to the SQLite documentation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

<method name="load_extension">
<return type="int" />
<description>
Loads the extension in the given path. Does not require [method SQLite.enable_load_extension], as it only enables C-API during the call and disables it right after, utilizing the recommended extension loading method declared by the SQLite documentation.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you say that this "load_extension" does not require "enable_load_extension", but in the "enable_load_extension"-description you say that "load_extension" can only be used after enabling extension loading with this method? Which is it? 🥲

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry for the headache :/ . My first commits are using the wrong (well not wrong but not recommended) method, thus I wrote their description in that way (still is true for that implementation though). But then I realized that the recommended way does not require it, so I changed the implementation and documentation. Latest commits should be the correct description/implementation.

I will squash the commits to clear the confusion.

Copy link
Author

@ugursoy ugursoy Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I've re-read that and I think I misunderstood what you meant.

In the doc, I say "SQL function load_extension() can only be used after enabling extension loading with this method."
This is the SQL function that you call in a query such as:
"""SELECT load_extension('extension.dll', 'sqlite3_extension_init');"""
and not the load_extension method in the Godot. If the user wants to use the query function, 'enable_load_extension' must be called prior since it is the only way to enable it.

On the other hand, Godot load_extension does not require it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an example use case for "enable_load_extension", should clarify the purpose of the function

image

@ugursoy ugursoy force-pushed the master branch 3 times, most recently from f675553 to 4c04e22 Compare February 1, 2025 15:35
@ugursoy
Copy link
Author

ugursoy commented Feb 1, 2025

Hello @ugursoy

Seems like the static checks pipeline fails 😢 Should be easy fix! 😄

Also:

* Would it be possible to squash your commits?

* Would it be possible to add the documentation to the `README.md` as well?

Hey there, fixed them.

@ugursoy ugursoy force-pushed the master branch 4 times, most recently from 201f88a to b58b354 Compare February 1, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants