Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / C#
Article

HyperNetDatabase

Rate me:
Please Sign up or sign in to vote.
4.11/5 (16 votes)
21 Mar 20044 min read 123.2K   819   36   44
HyperNetDatabase is a single process multithreading and blackout safe database

Sample Image - maximum width is 600 pixels

Sample Image - maximum width is 600 pixels

Introduction

This project was developed in order to help users that use databases like commercial ACCESS for small projects and then are subject to commercial laws. This is a simple solution for a database engine that can supply a good power to normal database tasks. This driver is free (GPL).

Using the code

Link the two DLLs HyperNetDatabase.DLL and NetFrmExts.DLL to your project and you'll be linked. Note use R2 Only, R1 is older and unstable.

To open a database and make a select:

C#
using HyperNetDatabase.R2;
...
Database db = new Database();
db.Open("file.hnd"); // creates or opens database
...
..
DataTable result = db.Select(
    new string[]{"SEQNAME"}, // fields as an array of strings
    "$Sequences", // Name of the table
    new object[,]{ {"SEQNAME","=",myseq} } 
  // pairs of filter conditions : ... WHERE SEQNAME=myseq AND ...
    );
..
db.Close();

 

Public Static Methods


DataRow2NameAndValueConverts a DataRow in a NameAndValue object with skipRows.

Public Instance Constructors


Database ConstructorDefault constructor

Public Instance Properties


FilenameFilename of the database
<IMG 
src="MlVlHyperNetDatabase/pubproperty.gif">Lock
Global lock, used to lock other thread to make concurrent queries. Example: Read and then insert.
<IMG 
src="MlVlHyperNetDatabase/pubproperty.gif">State
Connection state

Public Instance Methods

<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">AddField
Adds a field
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">AddFieldIfNotExist
Adds a field if it not exists
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">AddTable
Adds a table
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">AddTableIfNotExist
Adds a table if it not exists
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">Close
Closes a database
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">Delete
SQL DELETE query <example>Example:
C#
using HyperNetDatabase.R2;
...
Database db = new Database();
db.Open("file.hnd");
 // creates or opens database
...
string StockName = "peppers";
DataTable result = db.Delete("Stock",
new object[,]{ {"NAME","=",StockName} }
);
...

Is the same as: DELETE Stock WHERE NAME=@StockName

WHERE expression: Is an C# expresion for making a where as a filter.

  • new object[,]{ {"{FIELDNAME}",{operand},{parameter}},... } Is the same as "field operand parameter AND ..."
  • null Means the same as no where condition.

OperandEffect
=Equality
>Value of left field name is greater than right constant value variable
>=Value of left field name is greater or equal than right constant value variable
<Value of left field name is less than right constant value variable
<=Value of left field name is less or equal than right constant value variable
!=Value of left field name is different than right constant value variable

<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">DropTable
Removes a table
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">DropTableIfExists
Drops a table if the table exists
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">Dump
Dumps pages state
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">ExistsTable
Returns true if the table exists
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">FlushIndexes
Destroys in memory indexes. Do this if your were walking for many tables and you memory resources are low.
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">ForcedInsert
Overloaded. More known as Update or Insert (Sets values by a keyfield) Inserts if the condition does not match or updates if the condition matches.<example>
C#
db.ForcedInsert( "Stock", "NAME",
  "Peppers", "Qty", 0.5m );
Is the same as:
SQL
SELECT Count(*) FROM STOCK WHERE NAME="Peppers";
if count > 0 then
UPDATE STOCK SET Qty=0.5 WHERE NAME="Peppers";
else
INSERT INTO STOCK (NAME,Qty)
   VALUES ("Peppers",0.5);
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">ForcedSelect
Obtains a value and if it not exists obtains it's default value
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">GetTableNames
Gets all tables in this database
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">GetUserFields
Fields for users
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">Insert
Inserts data into a Table <example>Example:
C#
 using HyperNetDatabase.R2;
 ...
 Database db = new Database();
 db.Open("file.hnd");
  // creates or opens database
 ...
 string StockName = "peppers";
 DataTable result = db.Insert(
  "Stock", new object[,]
{ {"NAME",StockName}, {"QTY",0.5m} } );
 ...

Is the same as: INSERT INTO Stock (NAME,QTY) VALUES (@StockName,0.5);

SET expression: Is an C# expresion for indicate a FIELD with its VALUE.new object[,]{ {"{FIELDNAME}",{parameter}},... } Is the same as "SET field = parameter, ..."<example>Example 1:

C#
new object[,]{ {"QTY",0.5m} }
<example>Example 2:
C#
new object[,]{ {"STRNAME","peppers"},
 {"QTY",0.5m} }
LogToFile (inherited from LogSupport)Saves a string in the log file
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">Open
Open
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">PreloadIndexes
Preloads indexes for table to make reads faster
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">Select
SQL Select query. <example>Example:
C#
using HyperNetDatabase.R2;
...
Database db = new Database();
db.Open("file.hnd"); // creates or opens database
...
string StockName = "peppers";
DataTable result = db.Select(null,"Stock",
new object[,]{ {"NAME","=",StockName} }
);
...
result = db.Select(new string[]{"NAME"},"Stock",
new object[,]{ {"NAME","=",StockName} }
);
...
Is the same as:
  • SELECT * FROM Stock WHERE NAME=@StockName
  • SELECT NAME FROM Stock WHERE NAME=@StockName
WHERE expression: Is an C# expresion for making a where as a filter.
  • new object[,]{ {"{FIELDNAME}", {operand},{parameter}},... } Is the same as "field operand parameter AND ..."
  • null Means the same as no where condition.

OperandEffect
=Equality
>Value of left field name is greater than right constant value variable
>=Value of left field name is greater or equal than right constant value variable
<Value of left field name is less than right constant value variable
<=Value of left field name is less or equal than right constant value variable
!=Value of left field name is different than right constant value variable

<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">seqCreate
Overloaded. Creates a sequence.
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">seqCurrentValue
Current sequence value
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">seqDrop
Sequence drop
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">seqExists
Sequence exists?
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">seqNextValue
Next sequence value (and autoincrement)
<IMG 
src="MlVlHyperNetDatabase/pubmethod.gif">Update
SQL UPDATE query <example>Example:
C#
using HyperNetDatabase.R2;
...
Database db = new Database();
db.Open("file.hnd"); // creates or opens database
...
string StockName = "peppers";
DataTable result = db.Update("Stock",
new object[,]{ {"NAME",StockName}, {"QTY",0.5m} },
new object[,]{ {"NAME","=","pepperoni"} }
);
...

Is the same as: UPDATE Stock SET NAME=@StockName, QTY=0.5 WHERE NAME=pepperoni

WHERE expression: Is an C# expresion for making a where as a filter.

  • new object[,]{ {"{FIELDNAME}",{operand},{parameter}},... } Is the same as "field operand parameter AND ..."
  • null Means the same as no where condition.

OperandEffect
=Equality
>Value of left field name is greater than right constant value variable
>=Value of left field name is greater or equal than right constant value variable
<Value of left field name is less than right constant value variable
<=Value of left field name is less or equal than right constant value variable
!=Value of left field name is different than right constant value variable

SET expression: Is an C# expresion for indicate a FIELD with its VALUE.

new object[,]{ {"{FIELDNAME}",{parameter}},... } is the same as "SET field = parameter, ..."

<example>Example 1:

C#
new object[,]{ {"QTY",0.5m} }
<example>Example 2:
C#
new object[,]{ {"STRNAME","peppers"},
 {"QTY",0.5m} }



Points of Interest

  • Support all SQL basic functions.
  • Additional features.
  • Protect from Blackouts
  • Multithreading-safe

History

RELEASE VERSION 2.0.0 NOTES - 2004-03-17

Features:

  • First stable version
  • Support all SQL basic functions.
  • Additional features.
  • Protect from Blackouts
  • Multithreading-safe

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Spain Spain
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralseqCreate Pin
Robse17-Apr-06 4:48
Robse17-Apr-06 4:48 
GeneralGood work but too much memory used Pin
adamsmin28-Aug-04 15:44
adamsmin28-Aug-04 15:44 
GeneralRe: Good work but too much memory used Pin
M L Viñas Livschitz30-Aug-04 22:51
M L Viñas Livschitz30-Aug-04 22:51 
GeneralStrings &gt; 50KByte Pin
Kampf-Keks15-Aug-04 14:14
sussKampf-Keks15-Aug-04 14:14 
GeneralRe: Strings &gt; 50KByte Pin
M L Viñas Livschitz30-Aug-04 22:51
M L Viñas Livschitz30-Aug-04 22:51 
GeneralConsult SharpHSQL Pin
ylong18-Apr-04 6:13
ylong18-Apr-04 6:13 
GeneralRe: Consult SharpHSQL Pin
M L Viñas Livschitz18-Apr-04 6:22
M L Viñas Livschitz18-Apr-04 6:22 
GeneralProtect from Blackouts Pin
Rick Crone30-Mar-04 9:04
Rick Crone30-Mar-04 9:04 
GeneralRe: Protect from Blackouts Pin
M L Viñas Livschitz30-Mar-04 22:49
M L Viñas Livschitz30-Mar-04 22:49 
GeneralRe: Protect from Blackouts Pin
Rick Crone31-Mar-04 3:13
Rick Crone31-Mar-04 3:13 
GeneralRe: Protect from Blackouts Pin
M L Viñas Livschitz31-Mar-04 5:54
M L Viñas Livschitz31-Mar-04 5:54 
GeneralNo test database in source.. Pin
Stewart.Rogers30-Mar-04 2:51
Stewart.Rogers30-Mar-04 2:51 
GeneralRe: No test database in source.. Pin
M L Viñas Livschitz30-Mar-04 3:03
M L Viñas Livschitz30-Mar-04 3:03 
GeneralDatabase Pin
Alex_124-Mar-04 17:36
Alex_124-Mar-04 17:36 
GeneralRe: Database Pin
M L Viñas Livschitz25-Mar-04 6:22
M L Viñas Livschitz25-Mar-04 6:22 
QuestionID fields? Pin
csmba24-Mar-04 7:36
csmba24-Mar-04 7:36 
AnswerRe: ID fields? Pin
M L Viñas Livschitz24-Mar-04 8:46
M L Viñas Livschitz24-Mar-04 8:46 
GeneralRe: ID fields? Pin
csmba24-Mar-04 8:51
csmba24-Mar-04 8:51 
10x for the reference. I will look into that.
how about the second question?
GeneralRe: ID fields? Pin
M L Viñas Livschitz25-Mar-04 6:20
M L Viñas Livschitz25-Mar-04 6:20 
QuestionParser? Pin
Jeff Varszegi18-Mar-04 18:11
professionalJeff Varszegi18-Mar-04 18:11 
AnswerRe: Parser? Pin
M L Viñas Livschitz19-Mar-04 3:32
M L Viñas Livschitz19-Mar-04 3:32 
GeneralRe: Parser? Pin
Stewart.Rogers30-Mar-04 2:40
Stewart.Rogers30-Mar-04 2:40 
GeneralRe: Parser? Pin
M L Viñas Livschitz30-Mar-04 3:13
M L Viñas Livschitz30-Mar-04 3:13 
GeneralNo source Pin
Jeff Circeo18-Mar-04 13:35
Jeff Circeo18-Mar-04 13:35 
GeneralRe: No source Pin
M L Viñas Livschitz19-Mar-04 3:33
M L Viñas Livschitz19-Mar-04 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.