BluePink BluePink
XHost
Oferim servicii de instalare, configurare si monitorizare servere linux (router, firewall, dns, web, email, baze de date, aplicatii, server de backup, domain controller, share de retea) de la 50 eur / instalare. Pentru detalii accesati site-ul BluePink.


SQLiteServer Documentation


General information
sqlite3_open_v2
sqlite3_close
sqlite3_prepare_v2
sqlite3_step
sqlite3_finalize
sqlite3_column_count
sqlite3_column_name
sqlite3_column_text
sqlite3_errcode
sqlite3_errmsg

General information

The default connection port is 400.

For testing place "test.sqlite" and "security.sqlite" in the same directory as "sqliteserver.exe"

For information on "secutity.sqlite" see security.pdf

Opening New Server Connection

int sqlite3_open_v2(
  const char *connection,   /* Server address and database filename (UTF-8) */
  sqlite3 **ppDb,         /* OUT: SQLite connection handle */
  int flags,              /* Flags */
  const char *zVfs        /* not used */
);

These routines open an SQLiteServer connection whose parameters are given by the connection argument. The connection argument is interpreted as UTF-8. A connection handle is usually returned in *ppDb, even if an error occurs. The only exception is that if SQLiteServer is unable to allocate memory to hold the sqlite3 object, a NULL will be written into *ppDb instead of a pointer to the sqlite3 object. If the connection and database are opened (and/or created) successfully, then SQLITE_OK is returned. Otherwise an error code is returned. The sqlite3_errmsg() routine can be used to obtain an English language description of the error.

The connection argument has this structure "username:password@host[:port]/filename".

The flags parameter can take one of the following three values:

SQLITE_OPEN_READONLY
The database is opened in read-only mode. If the database does not already exist, an error is returned.
SQLITE_OPEN_READWRITE
The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned.
SQLITE_OPEN_READWRIT |SQLITE_OPEN_CREATE
The database is opened for reading and writing, and is creates it if it does not already exist. This is the behavior that is always used for sqlite3_open_v2().

If the filename is ":memory:", then a private, temporary in-memory database is created for the connection. This in-memory database will vanish when the database connection is closed. Future versions of SQLite might make use of additional special filenames that begin with the ":" character. It is recommended that when a database filename actually does begin with a ":" character you should prefix the filename with a pathname such as "./" to avoid ambiguity.

If the filename is an empty string, then a private, temporary on-disk database will be created. This private database will be automatically deleted as soon as the database connection is closed.

Closing A Server Connection

int sqlite3_close(sqlite3 *);

This routine is the destructor for the sqlite3 object.

Applications should finalize all prepared statements associated with the sqlite3 object prior to attempting to close the object.

If sqlite3_close() is invoked while a transaction is open,the transaction is automatically rolled back.

Compiling An SQL Statement

int sqlite3_prepare_v2(
  sqlite3 *conn,            /* Connection handle */
  const char *zSql,       /* SQL statement, UTF-8 encoded */
  int nByte,              /* Maximum length of zSql in bytes. */
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
);

To execute an SQL query, it must first be compiled into a byte-code program using one of these routines.

The first argument, "conn", is a server connectionobtained from a prior call to sqlite3_open_v2().

The second argument, "zSql", is the statement to be compiled, encoded UTF-8.

If the nByte argument is less than zero, then zSql is read up to the first zero terminator. If nByte is non-negative, then it is the maximum number of bytes read from zSql. When nByte is non-negative, the zSql string ends at either the first '\000' character or the nByte-th byte, whichever comes first. If the caller knows that the supplied string is nul-terminated, then there is a small performance advantage to be gained by passing an nByte parameter that is equal to the number of bytes in the input string including the nul-terminator bytes.

*pzTail is made to point to the first byte past the end of the first SQL statement in zSql. These routines only compile the first statement in zSql, so *pzTail is left pointing to what remains uncompiled.

*ppStmt is left pointing to a compiled prepared statement that can be executed using sqlite3_step(). If there is an error, *ppStmt is set to NULL. If the input text contains no SQL (if the input is an empty string or a comment) then *ppStmt is set to NULL. The calling procedure is responsible for deleting the compiled SQL statement using sqlite3_finalize()after it has finished with it.

On success, SQLITE_OKis returned, otherwise an error code is returned.

  1. If the database schema changes, instead of returning SQLITE_SCHEMAas it always used to do, sqlite3_step() will automatically recompile the SQL statement and try to run it again. If the schema has changed in a way that makes the statement no longer valid,sqlite3_step() will still return SQLITE_SCHEMA.
  2. When an error occurs, sqlite3_step()will return one of the detailed error codes or extended error codes.

Evaluate An SQL Statement

int sqlite3_step(sqlite3_stmt*);

After a prepared statement has been prepared, this function must be called one or more times to evaluate the statement.

If the SQL statement being executed returns any data, then SQLITE_ROW is returned each time a new row of data is ready for processing by the caller. The values may be accessed using the column access functions.sqlite3_step() is called again to retrieve the next row of data.

SQLITE_DONE means that the statement has finished executing successfully. sqlite3_step() should not be called again on this virtual machine without first calling sqlite3_reset() to reset the virtual machine back to its initial state.

SQLITE_ERROR means that a run-time error (such as a constraint violation) has occurred. sqlite3_step() should not be called again on the VM. More information may be found by calling sqlite3_errmsg().

SQLITE_MISUSE means that the this routine was called inappropriately. Perhaps it was called on prepared statement that has already been finalized or on one that had previously returned SQLITE_ERROR or SQLITE_DONE. Or it could be the case that the same database connection is being used by two or more threads at the same moment in time.

Destroy A Prepared Statement Object

int sqlite3_finalize(sqlite3_stmt *pStmt);

The sqlite3_finalize() function is called to delete a prepared statement. If the statement was executed successfully or not executed at all, then SQLITE_OK is returned. If execution of the statement failed then an error code or extended error code is returned.

This routine can be called at any point during the execution of the prepared statement. If the virtual machine has not completed execution when this routine is called, that is like encountering an error or an interrupt. Incomplete updates may be rolled back and transactions canceled, depending on the circumstances, and the error code returned will be SQLITE_ABORT.

Number Of Columns In A Result Set

int sqlite3_column_count(sqlite3_stmt *pStmt);

Return the number of columns in the result set returned by the prepared statement. This routine returns 0 if pStmt is an SQL statement that does not return data (for example an UPDATE).

Column Names In A Result Set

const char *sqlite3_column_name(sqlite3_stmt*, int N);

These routines return the name assigned to a particular column in the result set of a SELECT statement. The sqlite3_column_name() interface returns a pointer to a zero-terminated UTF-8 string. The first parameter is the prepared statement that implements the SELECT statement. The second parameter is the column number. The leftmost column is number 0.

The returned string pointer is valid until either the prepared statement is destroyed by sqlite3_finalize() or until the next call to sqlite3_column_name() or sqlite3_column_name16() on the same column.

If sqlite3_malloc() fails during the processing of either routine then a NULL pointer is returned.

The name of a result column is the value of the "AS" clause for that column, if there is an AS clause. If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next.

Result Values From A Query

const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);

These routine return information about a single column of the current result row of a query. In the first argument is a pointer to the prepared statement that is being evaluated (the sqlite3_stmt* that was returned from sqlite3_prepare_v2()) and the second argument is the index of the column for which information should be returned. The leftmost column of the result set has the index 0.

If the SQL statement does not currently point to a valid row, or if the column index is out of range, the result is undefined. These routine may only be called when the most recent call to sqlite3_step() has returned SQLITE_ROW and neither sqlite3_reset() nor sqlite3_finalize() have been called subsequently. If any of these routines are called after sqlite3_reset() or sqlite3_finalize() or after sqlite3_step() has returned something other than SQLITE_ROW, the results are undefined. If sqlite3_step() or sqlite3_reset() or sqlite3_finalize() are called from a different thread while any of these routine are pending, then the results are undefined.

Strings returned by sqlite3_column_text(), even empty strings, are always zero terminated.

Error Codes And Messages

int sqlite3_errcode(sqlite3 *db);
const char *sqlite3_errmsg(sqlite3*);

The sqlite3_errcode() interface returns the numeric result code or extended result code for the most recent failed sqlite3_* API call associated with a database connection. If a prior API call failed but the most recent API call succeeded, the return value from sqlite3_errcode() is undefined.

The sqlite3_errmsg() return English-language text that describes the error, as UTF-8. Memory to hold the error message string is managed internally. The application does not need to worry about freeing the result. However, the error string might be overwritten or deallocated by subsequent calls to other SQLite interface functions.

If an interface fails with SQLITE_MISUSE, that means the interface was invoked incorrectly by the application. In that case, the error code and message may or may not be set.