/// <summary> /// Connect to database, but without synchronization /// </summary> /// <returns>True if opened</returns> internal bool ConnectWithoutSync() { #if EVAL if (license == null) { license = LicenseManager.Validate(typeof(VistaDBDatabase), this); } #endif if (databaseId > 0) { return(VistaDBAPI.ivdb_SelectDb(databaseId)); } try { databaseId = VistaDBAPI.ivdb_OpenDatabase(databaseName, "", exclusive, readOnly, (uint)parameters, password, (uint)cypher, false); clusterSize = VistaDBAPI.ivdb_GetClusterLength(); } catch (VistaDBException e) { if (!e.Critical) { databaseId = (int)(e.Result); } throw; } return(databaseId > 0); }
/// <summary> /// Open a V-SQL query. Open is used with SELECT statements only. /// </summary> public override void Open() { //Open SQL Query //Set rowsAffected //Fill 'columns' (meta data structure) if (this.queryID == 0) { return; } lock (syncRoot) { this.rowsAffected = 0; VistaDBAPI.ivsql_SetSQL(this.queryID, this.commandText); VistaDBAPI.ivsql_Open(this.queryID, ref this.rowsAffected); InternalInitFieldDefs(); this.recordCount = VistaDBAPI.ivsql_RecCount(this.queryID); this.opened = true; this.startTraversing = true; } }
/// <summary> /// Open a V-SQL query. Open is used with SELECT statements only. /// </summary> public void Open() { //Open SQL Query //Set rowsAffected //Fill 'columns' (meta data structure) if (queryID <= 0) { return; } int rowsaffected = 0; lock (syncRoot) { VistaDBAPI.ivsql_SetSQL(queryID, commandText); sqlID = VistaDBAPI.ivsql_Open(queryID, ref rowsaffected); InternalInitFieldDefs(); recordCount = VistaDBAPI.ivsql_RecCount(queryID); rowsAffected = rowsaffected; opened = true; } }
/// <summary> /// Pack database with option 'save file permission' /// </summary> /// <param name="oldPassword">Old password</param> /// <param name="oldCypher">Old cypher</param> /// <param name="newPassword">New password</param> /// <param name="newCypher">New cypher</param> /// <param name="newCaseSensitive">New case sensitive option</param> /// <param name="newLocale">New locale</param> /// <param name="MarkFullEncryption">Mark full encryption option</param> /// <param name="SaveFilePermission">Save file permission option</param> /// <returns>True for success</returns> public bool PackDatabase(string oldPassword, CypherType oldCypher, string newPassword, CypherType newCypher, bool newCaseSensitive, int newLocale, bool MarkFullEncryption, bool SaveFilePermission) { bool needOpen, res; lock (SyncRoot) { if (databaseId > 0) { needOpen = true; CloseWithoutSync(); } else { needOpen = false; } res = VistaDBAPI.ivdb_PackDatabase(databaseName, oldPassword, (uint)oldCypher, newPassword, (uint)newCypher, newCaseSensitive, newLocale, MarkFullEncryption, SaveFilePermission); password = newPassword; cypher = newCypher; if (needOpen) { ConnectWithoutSync(); } return(res); } }
/// <summary> /// Begin a transaction. Transactions may be nested. /// </summary> public bool BeginTransaction() { bool res; res = VistaDBAPI.ivsql_BeginTransaction(connectionID); return(res); }
/// <summary> /// Commit an active transaction. Transactions may be nested. /// </summary> public bool CommitTransaction() { bool res; res = VistaDBAPI.ivsql_CommitTransaction(connectionID); return(res); }
/// <summary> /// Commit an active transaction. Transactions may be nested. /// </summary> public override bool CommitTransaction() { bool res; res = VistaDBAPI.ivsql_CommitTransaction(this.connectionID); return(res); }
public override void CreateQuery() { if (this.queryID != 0) { return; } this.queryID = VistaDBAPI.ivsql_CreateQuery(((VistaDBLocalConnection)parent).ConnectionID); }
/// <summary> /// Set a V-SQL parameter value to NULL. /// </summary> public void SetParamNull(string pName, VistaDBType type) { if (queryID <= 0) { return; } VistaDBAPI.ivsql_SetParamNull(queryID, pName, (short)type); }
internal void CreateQuery() { if (queryID > 0) { return; } queryID = VistaDBAPI.ivsql_CreateQuery(parent.ConnectionID); }
/// <summary> /// Set a V-SQL parameter value to NULL. /// </summary> public override void SetParamNull(string pName, VistaDBType type) { if (this.queryID == 0) { return; } VistaDBAPI.ivsql_SetParamNull(queryID, pName, (short)type); }
/// <summary> /// Open a database connection to a VistaDB database. /// </summary> /// <returns></returns> public void OpenDatabaseConnection() { if (opened) { return; } bool success = false; CypherType _cypher; string _password; lock (syncRoot) { try { if (cypher == CypherType.None) { _cypher = CypherType.Blowfish; _password = ""; } else { _cypher = cypher; _password = password; } success = VistaDBAPI.ivsql_OpenDatabaseConnection(connectionID, dataSource, exclusive, readOnly, _cypher, _password, false); } catch (VistaDBException e) { if (!e.Critical) { for (int i = 0; i < queries.Length; i++) { queries[i].CreateQuery(); } opened = true; } throw; } if (!success) { throw new VistaDBException(VistaDBErrorCodes.SQLDatabaseCouldNotBeFound); } for (int i = 0; i < queries.Length; i++) { queries[i].CreateQuery(); } opened = true; } }
internal void FreeQuery() { if (queryID <= 0) { return; } VistaDBAPI.ivsql_FreeQuery(queryID); queryID = 0; }
/// <summary> /// Enumerate columns info /// </summary> /// <param name="tableName">Table name</param> /// <returns>Columns info list</returns> public VDBColumnInfo[] EnumColumns(string tableName) { int position; int columnsCount; VDBColumnInfo[] columns; if (!FindTable(tableName)) { return(null); } position = this.position; try { FindColumnSection(); GetInteger(); columnsCount = GetInteger(); columns = new VDBColumnInfo[columnsCount]; for (int i = 0; i < columnsCount; i++) { columns[i].Name = GetString(); columns[i].Caption = GetString(); columns[i].DataType = VistaDBAPI.NetDataType(GetChar().ToString()); columns[i].Width = GetInteger(); columns[i].Decimals = GetInteger(); columns[i].DefValue = GetString(); columns[i].Identity = GetBool(); columns[i].IncStep = GetDouble(); columns[i].UseDefValInUpdate = GetBool(); columns[i].AllowNull = GetBool(); columns[i].Description = GetString(); columns[i].ReadOnly = GetBool(); columns[i].Compressed = GetBool(); columns[i].Encrypted = GetBool(); columns[i].Hidden = GetBool(); columns[i].PrimaryKey = GetBool(); columns[i].Indexed = GetBool(); columns[i].Unicode = GetBool(); columns[i].FTS = GetBool(); } } finally { this.position = position; } return(columns); }
////////////////////////////////////////////////////////// ///////////////Navigation functions/////////////////////// ////////////////////////////////////////////////////////// /// <summary> /// Go to the first row in the dataset. /// </summary> /// <returns>False if current position doesn't change</returns> public override bool First() { if (this.queryID == 0) { return(false); } //Call SQL API function to move to the first position VistaDBAPI.ivsql_First(this.queryID); return(true); }
/// <summary> /// Go to the last row in the dataset. /// </summary> /// <returns>False if current position doesn't change</returns> public bool Last() { if (queryID <= 0) { return(false); } //Call SQL API function to move to the last position VistaDBAPI.ivsql_Last(queryID); return(true); }
/// <summary> /// Export data from tables (in list) to xml-file /// </summary> /// <param name="cpXmlFileName">Xml-file name</param> /// <param name="OnlySchema">If true, then exports only schema else schema and data</param> /// <returns>Return true if success else false</returns> public bool ExportData(string cpXmlFileName, bool OnlySchema) { if (databaseId <= 0) { return(false); } lock (SyncRoot) { VistaDBAPI.ivdb_SelectDb(databaseId); return(VistaDBAPI.ivdb_ExportData(cpXmlFileName, OnlySchema)); } }
/// <summary> /// Flush database data buffers to disk /// </summary> public void FlushFileBuffers() { if (databaseId <= 0) { return; } lock (SyncRoot) { VistaDBAPI.ivdb_SelectDb(databaseId); VistaDBAPI.ivdb_FlushFileBuffers(); } }
/// <summary> /// Check table existence /// </summary> /// <param name="tableName">Table name</param> /// <returns>Return true, if table exist, else false</returns> public bool IsTableExist(string tableName) { if (databaseId <= 0) { return(false); } lock (SyncRoot) { VistaDBAPI.ivdb_SelectDb(databaseId); return(VistaDBAPI.ivdb_IsTableExist(tableName)); } }
/// <summary> /// Go to the next row in dataset /// </summary> /// <returns>False if current position doesn't change</returns> public bool Next() { if (queryID <= 0) { return(false); } //Call SQL API function to move to the next position // VistaDBAPI.ivsql_MoveBy(queryID, 1); VistaDBAPI.ivsql_Next(queryID); return(true); }
/// <summary> /// Saves in-memory table into /// </summary> /// <param name="databaseName">Database name</param> /// <returns></returns> public bool SaveToFile(string databaseName) { if (this.databaseId <= 0 || this.parameters != VDBDatabaseParam.InMemory) { return(false); } lock (this.SyncRoot) { VistaDBAPI.ivdb_SelectDb(this.databaseId); return(VistaDBAPI.ivdb_SaveToDatabase(databaseName)); } }
/// <summary> /// Rollback transaction /// </summary> /// <param name="AllLevels">True for rollback all levels</param> public void RollbackTransaction(bool AllLevels) { if (databaseId <= 0) { return; } lock (SyncRoot) { VistaDBAPI.ivdb_SelectDb(databaseId); VistaDBAPI.ivdb_RollbackTransaction(AllLevels); } }
/////////////////////////////////////////////////////////////////////// ////////////////////////////////METHODS//////////////////////////////// /////////////////////////////////////////////////////////////////////// /// <summary> /// Activates space recycling mechanism /// </summary> public void ActivateRecycling() { if (databaseId <= 0) { return; } lock (SyncRoot) { VistaDBAPI.ivdb_SelectDb(databaseId); VistaDBAPI.ivdb_ActivateRecycling(); } }
public bool GetCaseSensitive() { if (databaseId <= 0) { return(false); } lock (SyncRoot) { VistaDBAPI.ivdb_SelectDb(databaseId); return(VistaDBAPI.ivdb_GetCaseSensitive()); } }
/// <summary> /// Returns True if the V-SQL parameter value is NULL. /// </summary> public bool ParamIsNull(string pName) { bool res; if (queryID <= 0) { return(false); } res = VistaDBAPI.ivsql_ParamIsNull(queryID, pName); return(res); }
// public bool IsNull(string columnName) /// <summary> /// Return True if a column value is NULL at the given position in the table schema. The first column is 1. /// </summary> public bool IsNull(int columnNumber) { bool res; if (queryID <= 0) { return(false); } res = VistaDBAPI.ivsql_IsNull(queryID, columnNumber + 1); return(res); }
/// <summary> /// Constructor. /// </summary> public VistaDBSQL() { dataSource = ""; dataBase = ""; cypher = CypherType.None; password = ""; exclusive = false; readOnly = false; opened = false; queries = new VistaDBSQLQuery[0]; connectionID = VistaDBAPI.ivsql_CreateDatabaseConnection(); }
/// <summary> /// Import schema and data to current database /// </summary> /// <param name="cpXmlFileName">Xml-file name</param> /// <returns>Return true if success else false</returns> public bool ImportSchemaAndData(string cpXmlFileName) { if (databaseId <= 0) { return(false); } lock (SyncRoot) { VistaDBAPI.ivdb_SelectDb(databaseId); return(VistaDBAPI.ivdb_ImportSchemaAndData(cpXmlFileName)); } }
/// <summary> /// Go to previous row in the dataset /// </summary> /// <returns>False if current position doesn't change</returns> public bool Prior() { if (queryID <= 0) { return(false); } //Call SQL API function to move to the previous position // VistaDBAPI.ivsql_MoveBy(queryID, -1); VistaDBAPI.ivsql_Prior(queryID); return(false); }
public VistaDBLocalConnection(VistaDBDatabase db) : this() { if (!VistaDBAPI.ivsql_AssignDatabaseConnection(this.connectionID, db.DatabaseId, null, true, false, 0, null, db.CaseSensitive)) { throw new VistaDBException(VistaDBErrorCodes.DatabaseNotOpened); } db.FreeDatabase(); this.cultureID = db.Locale; this.caseSensitivity = db.CaseSensitive; this.opened = true; }