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

Basic support for prepared statements in postgres, sqlite3 and mysql. #99

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Commits on May 31, 2018

  1. Basic support for prepared statements on sqlite3.

    With this modification we can enjoy the security benefits of having
    prepared-statement-alike additional parameters.  To do this, the
    additional parameters should be passed after the statement in the
    execute method.
    
    This means that a new prepared statement will be created on each
    execute call, so don't expect big a performance increase.
    
    Maybe in a distant future a LRU cache of prepared statements could be
    added.
    fcr-- committed May 31, 2018
    Configuration menu
    Copy the full SHA
    d810625 View commit details
    Browse the repository at this point in the history
  2. Basic input parameters support for PostgreSQL

    As in SQLite3, we now support prepared-statements-alike passing of
    optional parameters by using the PQexecParams function, and since adding
    support for binary types is not an easy task, any argument is converted
    to a string before being sent and converted back to the expected type by
    PostgreSQL... in any case this is better than nothing.
    
    You may want to use a cast ``::type'' if it's not inferred. Example:
    
    > db = require'luasql.postgres'.postgres():connect('')
    > assert(db:execute('create table t(a int)'))
    > assert(db:execute('insert into t values($1)', 17))
    > res = assert(db:execute('select $1+$2::int, a from t where a>$1', 3, 4))
    > =res:fetch()
    7	17
    fcr-- committed May 31, 2018
    Configuration menu
    Copy the full SHA
    65b6faa View commit details
    Browse the repository at this point in the history

Commits on Nov 22, 2018

  1. Configuration menu
    Copy the full SHA
    a63e68e View commit details
    Browse the repository at this point in the history
  2. Bind string values as text.

      Since sqlite3_bind_text is binary safe, binding as text can be done
      without worries.
    fcr-- committed Nov 22, 2018
    Configuration menu
    Copy the full SHA
    7928968 View commit details
    Browse the repository at this point in the history

Commits on Nov 23, 2018

  1. Refactor for mysql_stmt API.

      This eliminates the need for escaping parameters, since now they
      can be specified as additional arguments to execute.
    fcr-- committed Nov 23, 2018
    Configuration menu
    Copy the full SHA
    e970d8f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2baecd2 View commit details
    Browse the repository at this point in the history
  3. Add a generic conn:execute(sql, ...) function.

      This function can be used by all the drivers simplifying
      the logic, requiring only to implement conn:prepare(sql)
      and stmt:execute(...).
    fcr-- committed Nov 23, 2018
    Configuration menu
    Copy the full SHA
    6fea651 View commit details
    Browse the repository at this point in the history