Class Session
Class that manages a session.
Every session is provided by an External provider, otherwise it will use a basic one provided by the server lxapi.Connection.#ctor(System.String)
Once a session is ended, every object related to it as Tables, Indexes, Scans, Table tuples, etc. become invalid and shouldn't be used anymore
Use flush() to flush the data to the server or abort abort() to clean the data from client
This class provides also tables, indexex and sequences creation but this is mainly for testing purposes. Use SQL inteface or the Console to take advantage of Leanxcale's full capabilities. Check "www.leanxcale.com/> for more information
session = new Session();
Table table = new Table(session, tablename);
int jimbirthday = (int)(new DateTimeOffset(new DateTime(2010, 12, 12)).ToUnixTimeSeconds() / 86400);
object[] jimrow = { 0, null, "Jim", "Doe", "No comments",
"Mulholland Drive", null, null, jimbirthday, 50, 3.26, null };
table.insert(jimrow);
// With Builder
TupleBuilder builder = table.tupleBuilder();
int johnbirthday = (int)(new DateTimeOffset(new DateTime(1975, 1, 1)).ToUnixTimeSeconds() / 86400);
object[] johnrow = { 1, "123456789A", "John", "Doe", "No comments",
"Mulholland Drive", "555333695", "johndoe@nowhere.no", johnbirthday, 70, 1.79, null };
builder.add(johnrow);
table.insert(builder.build(table));
// end::insert[]
// tag::insertWSeq[]
session.createSequence("seq", 100, 2, 10);// start at 2, increment by 10
ulong next_value = session.seqNextValue("seq");
Console.WriteLine("Next value: {0}", next_value);
// reuse builder
builder.add(0, next_value).add(1, "912345678B").add(2, "Jane");
int janebirthday = (int)(new DateTimeOffset(new DateTime(1972, 10, 7)).ToUnixTimeSeconds() / 86400);
builder.add(6, "0034698765432").add(7, "janedoe@lx.com").add(8, janebirthday)
.add(9, 75).add(10, 1.79);
table.upsert(builder.build(table));
session.end();</code></pre>
Inheritance
Implements
Inherited Members
Namespace: lxapi
Assembly: lxapi.dll
Syntax
public class Session : IDisposable
Fields
connection
Connection which the session belongs to.
Declaration
public readonly Connection connection
Field Value
Type | Description |
---|---|
Connection |
tid
Session id
Declaration
protected ulong tid
Field Value
Type | Description |
---|---|
System.UInt64 |
Methods
abort()
Abort the current batch
Declaration
public void abort()
createIndex(String, String, Int32, UInt16[], Int32)
Create an Index for a table
Declaration
public void createIndex(string tname, string iname, int nkey, ushort[] idx, int flags = 0)
Parameters
Type | Name | Description |
---|---|---|
System.String | tname | table name the index belongs to |
System.String | iname | index name |
System.Int32 | nkey | number of columns to be indexed |
System.UInt16[] | idx | table columns to include in the index |
System.Int32 | flags | Index type bitmask. 0x1000 -> unique index; 0x2000 -> global index |
Examples
// Non unique
ushort[] phoneposition = { 5 };
session.createIndex(tablename, "phoneidx", 1, phoneposition, 0);
//Unique
ushort[] dniposition = { 1 };
session.createIndex(tablename, "dniidx", 1, dniposition, 0);
createSequence(String, Int32, Int32, Int32)
Create a new sequence. A sequence is a named series of value intervals (each one called a stripe). The stripe length is given by clen (client interval length). The server is permitted to assign nbuf stripes before updating the sequence value at disk (upon restarts, nbuf values might be discarded). To get a shared counter (counting +1 each time), use defaults. Values returned are multipled by step (defaults to 1) and added to min (defaults to 0).
Declaration
public void createSequence(string name, int nbuf, int min, int step)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | |
System.Int32 | nbuf | |
System.Int32 | min | |
System.Int32 | step |
createTable(String, String, String[])
Create a table according to Kivi format string.
A format string uses one character per field, showing its type, perhaps followed with options enclosed in '[]'. Known user field types are defined by these symbols and the character shown can be used to define them in a user format string.
type char spec
Tbool b int8_t (boolean)
Tbyte c int8_t
Tshort h int16_t
Tenum e int16_t (static name enumeration)
Tint i int32_t
Ttime t int32_t (total nb of seconds)
Tdate y int32_t (days since epoch)
Tfloat f float
Tstr s string field
Tdec r decimals (and big integers)
Tjson j JSON text
Tmem m raw bytes
Tlong l int64_t
Tts w int64_t, (time stamp in microseconds since epoch)
Tdouble d double
Field options can be written together (within '[]') or separated by commas or a space:
! adds the following text up to the end of the options as a user spec for the field. Its meaning is up to the user. Must be the last option.
B use the field for bloom filtering in the table.
b ask for a blob field. Valid only for string, memory, and JSON fields. Data may be placed in external storage, or not. See also x.
c flags the field as desired for column formats.
D flags the field as gone; implementation might actually remove the data for the field, or not. Tuples still carry the field, perhaps as a null value, for consistency.
d flags the field as a delta field for adding values. Delta decimals require a number.number option too.
dm flags the field as a delta field for min value.
dM flags the field as a delta field for max value.
e flags the (string) field as enumerable at run time (dictionary)
i flags the (string) field as case insensitive
k flags the field as a key field. The position in the key (counting from 0) should follow right after the option (no spaces). If no position is given, the first unused one is used.
ks flags the field as a key field that is a split-point field. The position in the key (counting from 0) should follow right after the option (no spaces). Split fields must be at the end of
the key.
h flags the field as hashed one to compute the value of a hash field. It must be a key field.
H flags the field as a hash field computed from hashed fields. It must be a key field.
l shows that a string field uses the locale with the name that follows from the flag up to the end of the options or the start of the user spec option. Thus, it must be the last option but
for the user spec. For timestamp fields, this flag shows that the user wants the local time.
n flags the field as non-null
u flags the (string) field as always upper case. But see the note below.
x ask for a blob field with external storage. Valid only for string, memory, and JSON fields. Like b, but data will always be placed in external storage.
=number
field corresponds to the given field number in previous formats in kv order. But see metachgfmt(3) for further details.
number a number sets the maximum size desired for a string or memory field, or the number of decimal positions for decimals. The first character not a digit terminates this option.
number.number
A number with a decimal sets the maximum number of digits for a decimal and the desired number of decimal positions. This is to be used for delta decimal fields, in most other cases deci
mals may shrink and grow in size without much trouble.
Declaration
public void createTable(string tname, string ufmt, string[] fnames)
Parameters
Type | Name | Description |
---|---|---|
System.String | tname | table name |
System.String | ufmt | Kivi Table format |
System.String[] | fnames | field names |
deleteIndex(String, String)
Drop an index
Declaration
public void deleteIndex(string tname, string iname)
Parameters
Type | Name | Description |
---|---|---|
System.String | tname | table name the index belongs to |
System.String | iname | index name |
deleteSequence(String)
Drop a sequence
Declaration
public void deleteSequence(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | sequence name |
deleteTable(String)
Drop a table
Declaration
public void deleteTable(string tname)
Parameters
Type | Name | Description |
---|---|---|
System.String | tname | table name to be deleted |
Dispose()
Dispose
Declaration
public void Dispose()
Dispose(Boolean)
End(end()) and release the session.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
end()
End a session. The session become stale and should be destroyed
Declaration
public void end()
Finalize()
End(end()) and destroy the session.
Declaration
protected void Finalize()
flush()
A call to kvflush send the changes made to the server.
Declaration
public void flush()
getTid()
Get session id
Declaration
public ulong getTid()
Returns
Type | Description |
---|---|
System.UInt64 | session id |
seqNextValue(String)
Get next value for a sequence
Declaration
public ulong seqNextValue(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | sequence name |
Returns
Type | Description |
---|---|
System.UInt64 | sequence value |
setEnumField(String, Int32, String[])
Set the enum values for a table column
Declaration
public void setEnumField(string tname, int fno, string[] names)
Parameters
Type | Name | Description |
---|---|---|
System.String | tname | table name |
System.Int32 | fno | column position |
System.String[] | names | enum values |
table(String)
Retrieve table for session
Declaration
public Table table(string tname)
Parameters
Type | Name | Description |
---|---|---|
System.String | tname | table name |
Returns
Type | Description |
---|---|
Table | table instance |