SemWeb : SemWeb.Stores Namespace
SQLStore Class

A store that holds statements in an SQL database.

public abstract class SQLStore : SemWeb.ModifiableSource, SemWeb.QueryableSource, SemWeb.StaticSource, IDisposable


Remarks

This class is abstract and is inherited by classes for particular database backends. Backends are provided for MySQL and SQLite in separate assemblies. Rather than referencing those assemblies and using their constructors to create stores for those databases, it is easier to use SemWeb.Store.CreateForInput(string) or SemWeb.Store.CreateForOutput(string). Both methods return SQLStores that can be used for both reading and writing.

The SQLStore uses three tables, one containing the statement triples (actually quadruples with meta information) using numeric identifiers for each resource, one mapping entity identifiers to URIs, and the last mapping literal identifiers to string/language/datatype triples. The CREATE statements for the tables, which are automatically executed by the SQLStore when needed, are:

SQL Example
CREATE TABLE TABLEPREFIX_statements (subject int UNSIGNED NOT NULL,
       predicate int UNSIGNED NOT NULL, objecttype int NOT NULL, object int UNSIGNED NOT NULL,
       meta int UNSIGNED NOT NULL);

CREATE TABLE TABLEPREFIX_entities (id INT NOT NULL, value BLOB NOT NULL,
      PRIMARY KEY(id));

CREATE TABLE TABLEPREFIX_literals (id INT NOT NULL, value BLOB NOT NULL,
      language TEXT, datatype TEXT, PRIMARY KEY(id));

Indexes are created on the subject, predicate, and object/objecttype columns in the statements table, and on the value columns in the entities and literals table. Because MySQL before version 4.1.2 supported text indexes of length up to 255 bytes, URIs in the SQLStore are limited to this length.

Each resource stored in the tables is given an ID starting at 1 which is used as the value of the subject, predicate, object, and meta columns when the entity appears in a statement. The value 0 is used for statements with no meta information. When the object of a statement is an entity, objecttype is 0 and object contains the ID of the entity. When the object of a statement is a literal, objecttype is 1 and the object column contains the value of the id column in the literals table for the literal value. Literals in the literals table can be referenced by more than one statement.

Anonymous entities (blank nodes) are simply those entities mentioned in the statements table that have no entry giving their URI in the entities table.

Note:

While it is safe to use many SQLStores to read from the same store, it is not safe to use multiple SQLStores to write to the same store concurrently.

Inheritors must implement SemWeb.Stores.SQLStore.RunCommand(string), SemWeb.Stores.SQLStore.RunReader(string), and SemWeb.Stores.SQLStore.RunScalar(string).

Members

See Also: Inherited members from object.

Protected Constructors

The protected constructor used by inherited classes.

Properties

Distinct [read-only]
bool . To be added.
StatementCount [read-only]
int . To be added.

Protected Properties

HasUniqueStatementsConstraint [read-only]
abstract
bool . To be added.
InsertIgnoreCommand [read-only]
abstract
string . To be added.
MaximumUriLength [read-only]
int . To be added.
SupportsInsertCombined [read-only]
abstract
bool . Implemented by inheritors to indicate whether the backend supports inserting mutliple rows at once in a single INSERT command.
SupportsSubquery [read-only]
abstract
bool . To be added.
SupportsViews [read-only]
bool . To be added.
TableName [read-only]
string . Gets the table prefix passed to the constructor.

Methods

Protected Methods

BeginTransaction ()
CreateEntityPrefixTest (string, string, System.Text.StringBuilder) : bool
To be added.
CreateIndexes ()
Creates the indexes on the tables.
abstract CreateLikeTest (string, string, int, System.Text.StringBuilder)
To be added.
abstract CreateNullTest (string, System.Text.StringBuilder)
To be added.
CreateTable ()
Creates the tables needed by the SQLStore.
EndTransaction ()
EscapedAppend (System.Text.StringBuilder, string)
To be added.
EscapedAppend (System.Text.StringBuilder, string, bool, bool)
To be added.
GetQuoteChar () : char
Implemented by inheritors to provide the character used to surround strings in a SQL query.
abstract RunCommand (string)
Executes an SQL statement without a return value.
abstract RunReader (string) : System.Data.IDataReader
Executes an SQL statement that returns a table.
abstract RunScalar (string) : object
Executes an SQL statement that returns a scalar value.

Member Details

RunCommand Method

protected abstract void RunCommand (string sql)

Executes an SQL statement without a return value.

Parameters

sql
The SQL statement to execute.

Remarks

Inheritors must implemented this method.

RunScalar Method

protected abstract object RunScalar (string sql)

Executes an SQL statement that returns a scalar value.

Parameters

sql
The SQL statement to run that returns a number of text value.

Returns

The numeric or text value.

Remarks

Inheritors must implement this method.

RunReader Method

protected abstract System.Data.IDataReader RunReader (string sql)

Executes an SQL statement that returns a table.

Parameters

sql
The SQL statement to run.

Returns

An IDataReader containing the result of the tabular query.

Remarks

Inheritors must implement this method.

CreateTable Method

protected virtual void CreateTable ()

Creates the tables needed by the SQLStore.

Remarks

Inheritors may override this method to change the way tables are created by the SQLStore.

CreateIndexes Method

protected virtual void CreateIndexes ()

Creates the indexes on the tables.

Remarks

Inheritors may override this method to change the way indexes are created on the tables used by the SQLStore.

BeginTransaction Method

protected virtual void BeginTransaction ()

Called at the start of SemWeb.Store.Import(SemWeb.RdfReader).

Remarks

Inheritors may override this method to put a lock on the tables or begin a transaction to speed up the process of adding many statements into the tables. The default implementation does nothing.

EndTransaction Method

protected virtual void EndTransaction ()

Called at the end of SemWeb.Store.Import(SemWeb.RdfReader).

Remarks

Inheritors may override this method to end a lock or transaction started in SemWeb.Stores.SQLStore.BeginTransaction().

TableName Property

protected string TableName { get; }

Gets the table prefix passed to the constructor.

Value

The table prefix passed to the constructor.

Remarks

This property is protected and read-only.

SQLStore Constructor

protected SQLStore (string table)

The protected constructor used by inherited classes.

Parameters

table
The prefix name of the tables used by this store.

Remarks

The two tables used by this store will be table_statements and table_literals.

EscapedAppend Method

protected void EscapedAppend (System.Text.StringBuilder b, string str)

To be added.

Parameters

b
To be added.
str
To be added.

Remarks

To be added.

SupportsInsertCombined Property

protected abstract bool SupportsInsertCombined { get; }

Implemented by inheritors to indicate whether the backend supports inserting mutliple rows at once in a single INSERT command.

Value

If true, the more efficient multiple-row INSERT syntax is used, e.g.: INSERT INTO table VALUES (row1a, row1b), (row2a, row2b), .... ;

Remarks

None.

GetQuoteChar Method

protected virtual char GetQuoteChar ()

Implemented by inheritors to provide the character used to surround strings in a SQL query.

Returns

The string quotation character, usually an apostrophe or double-quote.

Remarks

The default implementation returns a double-quote.

GetStoreGuid Method

public string GetStoreGuid ()

To be added.

Returns

To be added.

Remarks

To be added.

CreateNullTest Method

protected abstract void CreateNullTest (string column, System.Text.StringBuilder command)

To be added.

Parameters

column
To be added.
command
To be added.

Remarks

To be added.

SupportsSubquery Property

protected abstract bool SupportsSubquery { get; }

To be added.

Value

To be added.

Remarks

To be added.

HasUniqueStatementsConstraint Property

protected abstract bool HasUniqueStatementsConstraint { get; }

To be added.

Value

To be added.

Remarks

To be added.

InsertIgnoreCommand Property

protected abstract string InsertIgnoreCommand { get; }

To be added.

Value

To be added.

Remarks

To be added.

CreateEntityPrefixTest Method

protected virtual bool CreateEntityPrefixTest (string column, string prefix, System.Text.StringBuilder command)

To be added.

Parameters

column
To be added.
prefix
To be added.
command
To be added.

Returns

To be added.

Remarks

To be added.

CreateLikeTest Method

protected abstract void CreateLikeTest (string column, string prefix, int method, System.Text.StringBuilder command)

To be added.

Parameters

column
To be added.
prefix
To be added.
method
To be added.
command
To be added.

Remarks

To be added.

EscapedAppend Method

protected virtual void EscapedAppend (System.Text.StringBuilder b, string str, bool quotes, bool forLike)

To be added.

Parameters

b
To be added.
str
To be added.
quotes
To be added.
forLike
To be added.

Remarks

To be added.

Add Method

public void Add (SemWeb.Statement statement)

To be added.

Parameters

statement
To be added.

Remarks

To be added.

Clear Method

public void Clear ()

To be added.

Remarks

To be added.

Close Method

public virtual void Close ()

To be added.

Remarks

To be added.

Contains Method

public bool Contains (SemWeb.Resource resource)

To be added.

Parameters

resource
To be added.

Returns

To be added.

Remarks

To be added.

Contains Method

public bool Contains (SemWeb.Statement template)

To be added.

Parameters

template
To be added.

Returns

To be added.

Remarks

To be added.

Distinct Property

public bool Distinct { get; }

To be added.

Value

To be added.

Remarks

To be added.

GetBNodeFromPersistentId Method

public SemWeb.BNode GetBNodeFromPersistentId (string persistentId)

To be added.

Parameters

persistentId
To be added.

Returns

To be added.

Remarks

To be added.

GetEntities Method

public SemWeb.Entity[] GetEntities ()

To be added.

Returns

To be added.

Remarks

To be added.

GetMetas Method

public SemWeb.Entity[] GetMetas ()

To be added.

Returns

To be added.

Remarks

To be added.

GetPersistentBNodeId Method

public string GetPersistentBNodeId (SemWeb.BNode node)

To be added.

Parameters

node
To be added.

Returns

To be added.

Remarks

To be added.

GetPredicates Method

public SemWeb.Entity[] GetPredicates ()

To be added.

Returns

To be added.

Remarks

To be added.

Import Method

public void Import (SemWeb.StatementSource source)

To be added.

Parameters

source
To be added.

Remarks

To be added.

MetaQuery Method

To be added.

Parameters

graph
To be added.
options
To be added.

Returns

To be added.

Remarks

To be added.

Query Method

To be added.

Parameters

graph
To be added.
options
To be added.
sink
To be added.

Remarks

To be added.

Remove Method

public void Remove (SemWeb.Statement template)

To be added.

Parameters

template
To be added.

Remarks

To be added.

RemoveAll Method

public void RemoveAll (SemWeb.Statement[] templates)

To be added.

Parameters

templates
To be added.

Remarks

To be added.

Replace Method

public void Replace (SemWeb.Entity a, SemWeb.Entity b)

To be added.

Parameters

a
To be added.
b
To be added.

Remarks

To be added.

Replace Method

public void Replace (SemWeb.Statement find, SemWeb.Statement replacement)

To be added.

Parameters

find
To be added.
replacement
To be added.

Remarks

To be added.

Select Method

public void Select (SemWeb.SelectFilter filter, SemWeb.StatementSink result)

To be added.

Parameters

filter
To be added.
result
To be added.

Remarks

To be added.

Select Method

public void Select (SemWeb.Statement template, SemWeb.StatementSink result)

To be added.

Parameters

template
To be added.
result
To be added.

Remarks

To be added.

Select Method

public void Select (SemWeb.StatementSink result)

To be added.

Parameters

result
To be added.

Remarks

To be added.

StatementCount Property

public int StatementCount { get; }

To be added.

Value

To be added.

Remarks

To be added.

SupportsViews Property

protected virtual bool SupportsViews { get; }

To be added.

Value

To be added.

Remarks

To be added.

MaximumUriLength Property

protected virtual int MaximumUriLength { get; }

To be added.

Value

To be added.

Remarks

To be added.