Example #1
0
        /// <summary>
        /// Create new database
        /// </summary>
        /// <param name="iCultureId">Culture ID for database</param>
        /// <param name="bOpenAfterCreation">If true then database opens after creation</param>
        /// <param name="bCaseSensitivity">Sets case-sensitivity flag for character data in run-time searching and filtering operations. Used as respective flag in primary and FTS indexes</param>
        /// <returns>return true for success</returns>
        public bool CreateDatabase(int iCultureId, bool bOpenAfterCreation, bool bCaseSensitivity)
        {
            bool res;
            int  tmp;

            if (bOpenAfterCreation && databaseId > 0)
            {
                throw new VistaDBException(VistaDBErrorCodes.DatabaseMustBeClosedBeforeCreate);
            }

            lock (SyncRoot)
            {
                VistaDBAPI.ivdb_SetClusterLength(clusterSize);
                //Parameters bExclusive and bReadOnly are not used by Engine
                tmp = VistaDBAPI.ivdb_CreateDatabase(databaseName, "", true, false, (uint)iCultureId, (uint)parameters,
                                                     password, (uint)cypher, bCaseSensitivity);
                VistaDBAPI.ivdb_SetClusterLength(1);

                if (tmp > 0)
                {
                    if (parameters != VDBDatabaseParam.InMemory)
                    {
                        VistaDBAPI.ivdb_CloseDatabase();

                        if (bOpenAfterCreation)
                        {
                            res = ConnectWithoutSync();
                        }
                        else
                        {
                            res = true;
                        }
                    }
                    else
                    {
                        databaseId = tmp;
                        res        = true;
                    }
                }
                else
                {
                    res = false;
                }

                return(res);
            }
        }
        public VistaDBLocalConnection(int cultureID, bool caseSensitive) : this()
        {
            int dbID = VistaDBAPI.ivdb_CreateDatabase(null, null, false, false, (uint)cultureID,
                                                      (uint)VDBDatabaseParam.InMemory, null, 0, caseSensitive);

            try
            {
                if (!VistaDBAPI.ivsql_AssignDatabaseConnection(this.connectionID, dbID, null, true, false, 0, null, caseSensitive))
                {
                    throw new VistaDBException(VistaDBErrorCodes.DatabaseNotOpened);
                }

                this.cultureID       = cultureID;
                this.caseSensitivity = caseSensitivity;
                this.opened          = true;
            }
            catch
            {
                VistaDBAPI.ivdb_SelectDb(dbID);
                VistaDBAPI.ivdb_CloseDatabase();
                throw;
            }
        }