Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige ÜberarbeitungVorherige Überarbeitung | |||
| hilfe:administration:sqlite [2010/10/22 18:01] – [Download and Installation] alan | hilfe:administration:sqlite [2015/06/07 23:53] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== SQLite Plugin ====== | ||
| + | The sqlite plugin is a helper plugin for various other plugins. | ||
| + | |||
| + | **Important: | ||
| + | |||
| + | ===== Download and Installation ===== | ||
| + | |||
| + | Download and install the plugin using the [[doku> | ||
| + | |||
| + | * Unstable **development version** from the [[http:// | ||
| + | |||
| + | Refer to [[doku> | ||
| + | |||
| + | ===== Admin Interface ===== | ||
| + | |||
| + | {{ http:// | ||
| + | |||
| + | The plugin comes with a simple admin interface where you can run your own SQL queries against any of the available databases. | ||
| + | |||
| + | Available databases ('' | ||
| + | |||
| + | ===== Usage ===== | ||
| + | |||
| + | To use this helper plugin in your own plugins, load it and call the init() function to connect to the database. Make sure you check if the plugin was loaded correctly and if the init() function ran without error, before executing your own code. | ||
| + | |||
| + | <code php> | ||
| + | // load the helper plugin | ||
| + | $sqlite = plugin_load(' | ||
| + | if(!$sqlite){ | ||
| + | msg(' | ||
| + | return; | ||
| + | } | ||
| + | // initialize the database connection | ||
| + | if(!$sqlite-> | ||
| + | return; | ||
| + | } | ||
| + | // use the plugin | ||
| + | $res = $sqlite-> | ||
| + | $arr = res2arr($res); | ||
| + | print_r($arr); | ||
| + | </ | ||
| + | |||
| + | ==== Functions ==== | ||
| + | |||
| + | === init === | ||
| + | |||
| + | Initializes and opens the database. Needs to be called right after loading this helper plugin | ||
| + | |||
| + | * $dbname is the name of the database. | ||
| + | * $updatedir is a path where update SQL files are located (see below) | ||
| + | |||
| + | <code php> | ||
| + | | ||
| + | </ | ||
| + | |||
| + | === query === | ||
| + | |||
| + | Execute a query with the given parameters. | ||
| + | |||
| + | Takes care of escaping | ||
| + | |||
| + | * $sql - the statement | ||
| + | * arguments... | ||
| + | * Arguments can also be given as a single array | ||
| + | |||
| + | <code php> | ||
| + | $plugin-> | ||
| + | </ | ||
| + | |||
| + | === res2arr === | ||
| + | |||
| + | Returns a complete result set as array | ||
| + | |||
| + | * $res - a query result | ||
| + | |||
| + | <code php> | ||
| + | $plugin-> | ||
| + | </ | ||
| + | |||
| + | === res2row === | ||
| + | |||
| + | Return the wanted row from a given result set as associative array | ||
| + | |||
| + | * $res - the result from a query | ||
| + | * $numrow - number of results | ||
| + | |||
| + | <code php> | ||
| + | $plugin-> | ||
| + | </ | ||
| + | |||
| + | === quote and join === | ||
| + | |||
| + | Join the given values and quote them for SQL insertion | ||
| + | |||
| + | * $vals - values to join | ||
| + | * $sep - separator char | ||
| + | |||
| + | <code php> | ||
| + | $plugin-> | ||
| + | </ | ||
| + | |||
| + | === quote string === | ||
| + | |||
| + | Run [[phpfn> | ||
| + | |||
| + | <code php> | ||
| + | $plugin-> | ||
| + | </ | ||
| + | |||
| + | ==== DB Schema Setup/ | ||
| + | |||
| + | Your plugin will need to create a database schema and maybe fill it with some initial data. When you release new versions of your plugin you might need to update the schema. The sqlite plugin provides a simple mechanism to do so. | ||
| + | |||
| + | This is all handled within the '' | ||
| + | |||
| + | The number of the most recent version has to be stored in a file called '' | ||
| + | |||
| + | The update mechanism will wrap the execution of each update in a transaction, | ||
| + | |||
| + | The sqlite plugin keeps track of the version a database is in currently using a table called '' | ||
| + | |||
| + | ==== SQL Extensions ==== | ||
| + | |||
| + | The plugin provides a few additional features over the standard SQLite 2 syntax. | ||
| + | |||
| + | === ALTER TABLE === | ||
| + | |||
| + | The plugin supports a simplified '' | ||
| + | |||
| + | <code bnf> | ||
| + | ALTER TABLE tbl_name alter_specification [, alter_specification] ... | ||
| + | |||
| + | alter_specification: | ||
| + | ADD column_definition | ||
| + | | DROP column_definition | ||
| + | | CHANGE old_col_name column_definition | ||
| + | |||
| + | column_definition: | ||
| + | same as for create table statements | ||
| + | </ | ||
| + | |||
| + | Examples: | ||
| + | |||
| + | <code sql> | ||
| + | ALTER TABLE employees ADD first_name, ADD last_name | ||
| + | ALTER TABLE invoices ADD note text, CHANGE idate invoice_date DATETIME | ||
| + | ALTER TABLE foo DROP bar, ADD bar2 INTEGER | ||
| + | </ | ||
| + | |||
| + | === GROUP_CONCAT === | ||
| + | |||
| + | The GROUP_CONCAT function is a copy of the same function as defined in MySQL. FIXME add more info. | ||