Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:04:30+00:00 2026-06-12T02:04:30+00:00

I am trying to create a Sqlite3 database with luasql. After I require luasql.sqlite3,

  • 0

I am trying to create a Sqlite3 database with luasql. After I require luasql.sqlite3, how do I create the database on a file?

Also, I can’t seem to find the manual for luasql. Is it available anywhere?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:04:31+00:00Added an answer on June 12, 2026 at 2:04 am

    SQLLite will create the db automatically if it does not exist.

    Here is a set of Sample functions for using it in Lua (ignore the fh functions they are just internal to the program I use).

        require 'luasql.sqlite3'
        function opendb(dbname)
        -- Check for Settings Database and create if needed
        local db = fhGetPluginDataFileName()
        local dbenv = assert (luasql.sqlite3())
        -- connect to data source, if the file does not exist it will be created
        dbcon = assert (dbenv:connect(db))
        -- check table for page list
        checkTable(dbcon,'pagelist',
        [[CREATE TABLE pagelist(filename varchar(500), md5hash varchar(32),UNIQUE (filename))
        ]])
        -- create table for settings
        checkTable(dbcon,'settings',
        [[CREATE TABLE settings(key varchar(20), directory varchar(500), 
                   host varchar(500), folder varchar(50), userid varchar(50), password varchar(50), UNIQUE (key))
        ]])
        return dbenv,dbcon
    end
    function checkTable(dbcon,table,createString)
        local sql = string.format([[SELECT count(name) as count FROM sqlite_master WHERE type='table' AND name='%s']],table)
        local cur = assert(dbcon:execute(sql))
        local rowcount = cur:fetch (row, "a")
        cur:close()
        if tonumber(rowcount) == 0 then
            -- Table not found create it
            res,err = assert(dbcon:execute(createString))
        end
    end
    function closedb(dbenv,dbcon)
        dbcon:close()
        dbenv:close()
    end
    function loadSettings(dbcon)
        local sql = [[SELECT * FROM settings]]
        local cur,err = assert(dbcon:execute(sql))
        local row = cur:fetch({},'a')
        cur:close()
        if row then
            return row
        else
            -- return default values
            return {
                directory = fhGetContextInfo('CI_PROJECT_PUBLIC_FOLDER')..'\\FH Website',
                host = 'websitehost',
                folder = '/',
                userid = 'user',
                password = 'password',
                new = 'yes'
            }
        end
    end
    function saveSettings(dbcon,settings)
        -- Check for Settings
        if settings.new == 'yes' then
            -- Create
            sql = string.format([[insert into settings (directory, host, folder, userid, password) Values('%s','%s','%s','%s','%s')]],settings.directory,settings.host,settings.folder,settings.userid,settings.password)
        else
            -- Update
            sql = string.format([[update settings set directory = '%s', host = '%s',folder = '%s',userid = '%s', password = '%s']],settings.directory,settings.host,settings.folder,settings.userid,settings.password)
        end
        local res = assert(dbcon:execute(sql))
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an SQLite3 database file through Objective-C at run time. I
I am trying to create a database in c++ using sqlite3 lib.. I am
I am trying to create entities out of a SQLite database. SQLite doesnt have
I am trying to create an application which requires a two table SQLite database
I have been trying for almost a week now to create an SQLite database
I am trying to create a login screen for an iphone application using sqlite3
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I'm trying to create a database in my first Django project (called meu_blog). I've
I am basically trying to create a new database and enter the database values
I'm running into issues trying to run a CREATE TABLE statement for sqlite3 on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.