public SQLiteConnectionStringBuilder()
 {
     _DataSource = String.Empty;
     _NewDatabase = false;
     _Encoding = Encoding.UTF8;
     _CacheSize = 2000;
     _Synchronous = SynchronousMode.Normal;
     _DateTimeFormat = DateTimeFormat.ISO8601;
 }
 public SQLiteConnectionStringBuilder()
 {
     _DataSource     = String.Empty;
     _NewDatabase    = false;
     _Encoding       = Encoding.UTF8;
     _CacheSize      = 2000;
     _Synchronous    = SynchronousMode.Normal;
     _DateTimeFormat = DateTimeFormat.ISO8601;
 }
        private void Parse(string connectionString)
        {
            String helpMessage =
                "Valid parameters:\n" +
                "Data Source=<database file>  (required)\n" +
                "NewDatabase=True|False  (default: False)\n" +
                "Encoding=UTF8|UTF16  (default: UTF8)\n" +
                "Cache Size=<N>  (default: 2000)\n" +
                "Synchronous=Full|Normal|Off  (default: Normal)\n" +
                "DateTimeFormat=ISO8601|Ticks|CurrentCulture  (default: ISO8601)\n";

            // Parse connection string
            String[] parameters = connectionString.Split(";".ToCharArray());

            if (parameters.Length == 0) throw new SQLiteException(helpMessage);

            for (int i = 0; i < parameters.Length; i++)
            {
                String parameter = parameters[i].Trim();
                if (parameter.Length == 0) continue;

                int index = parameter.IndexOf('=');
                if (index < 0) throw new SQLiteException(helpMessage);

                String paramName = parameter.Substring(0, index).Trim();
                String paramValue = parameter.Substring(index + 1).Trim();

                if (paramName.Equals("Data Source"))_DataSource = paramValue;
                else if (paramName.Equals("NewDatabase")) _NewDatabase = paramValue.ToUpper().Equals("TRUE");
                else if (paramName.Equals("Encoding"))
                {
                    switch (paramValue.ToUpper())
                    {
                        case "UTF8":
                            _Encoding = Encoding.UTF8;
                            break;
                        case "UTF16":
                            _Encoding = Encoding.Unicode;
                            break;
                        default:
                            throw new SQLiteException(string.Format("Unknown encoding specified: {0}", paramValue));
                    }
                }
                else if (paramName.Equals("Synchronous"))
                {
                    switch (paramValue.ToUpper())
                    {
                        case "FULL":
                            _Synchronous = SynchronousMode.Full;
                            break;
                        case "NORMAL":
                            _Synchronous = SynchronousMode.Normal;
                            break;
                        case "OFF":
                            _Synchronous = SynchronousMode.Off;
                            break;
                        default:
                            throw new SQLiteException(string.Format("Unknown synchronisation mode specified: {0}", paramValue));
                    }
                }
                else if (paramName.Equals("Cache Size"))
                {
                    try
                    {
                        _CacheSize = Convert.ToInt32(paramValue);
                    }
                    catch
                    {
                        throw new SQLiteException(string.Format("Invalid cache size specified: {0}", paramValue));
                    }
                }
                else if (paramName.Equals("DateTimeFormat"))
                {
                    switch (paramValue.ToUpper())
                    {
                        case "ISO8601":
                            _DateTimeFormat = DateTimeFormat.ISO8601;
                            break;
                        case "TICKS":
                            _DateTimeFormat = DateTimeFormat.Ticks;
                            break;
                        case "CURRENTCULTURE":
                            _DateTimeFormat = DateTimeFormat.CurrentCulture;
                            break;
                        default:
                            throw new SQLiteException(string.Format("Unknown DateTimeFormat specified: {0}", paramValue));
                    }
                }
                else
                {
                    throw new SQLiteException(string.Format("Unknown parameter specified: {0}.\r\n{1}", paramName, helpMessage));
                }
            }
        }
        private void Parse(string connectionString)
        {
            String helpMessage =
                "Valid parameters:\n" +
                "Data Source=<database file>  (required)\n" +
                "NewDatabase=True|False  (default: False)\n" +
                "Encoding=UTF8|UTF16  (default: UTF8)\n" +
                "Cache Size=<N>  (default: 2000)\n" +
                "Synchronous=Full|Normal|Off  (default: Normal)\n" +
                "DateTimeFormat=ISO8601|Ticks|CurrentCulture  (default: ISO8601)\n";

            // Parse connection string
            String[] parameters = connectionString.Split(";".ToCharArray());

            if (parameters.Length == 0)
            {
                throw new SQLiteException(helpMessage);
            }

            for (int i = 0; i < parameters.Length; i++)
            {
                String parameter = parameters[i].Trim();
                if (parameter.Length == 0)
                {
                    continue;
                }

                int index = parameter.IndexOf('=');
                if (index < 0)
                {
                    throw new SQLiteException(helpMessage);
                }

                String paramName  = parameter.Substring(0, index).Trim();
                String paramValue = parameter.Substring(index + 1).Trim();

                if (paramName.Equals("Data Source"))
                {
                    _DataSource = paramValue;
                }
                else if (paramName.Equals("NewDatabase"))
                {
                    _NewDatabase = paramValue.ToUpper().Equals("TRUE");
                }
                else if (paramName.Equals("Encoding"))
                {
                    switch (paramValue.ToUpper())
                    {
                    case "UTF8":
                        _Encoding = Encoding.UTF8;
                        break;

                    case "UTF16":
                        _Encoding = Encoding.Unicode;
                        break;

                    default:
                        throw new SQLiteException(string.Format("Unknown encoding specified: {0}", paramValue));
                    }
                }
                else if (paramName.Equals("Synchronous"))
                {
                    switch (paramValue.ToUpper())
                    {
                    case "FULL":
                        _Synchronous = SynchronousMode.Full;
                        break;

                    case "NORMAL":
                        _Synchronous = SynchronousMode.Normal;
                        break;

                    case "OFF":
                        _Synchronous = SynchronousMode.Off;
                        break;

                    default:
                        throw new SQLiteException(string.Format("Unknown synchronisation mode specified: {0}", paramValue));
                    }
                }
                else if (paramName.Equals("Cache Size"))
                {
                    try
                    {
                        _CacheSize = Convert.ToInt32(paramValue);
                    }
                    catch
                    {
                        throw new SQLiteException(string.Format("Invalid cache size specified: {0}", paramValue));
                    }
                }
                else if (paramName.Equals("DateTimeFormat"))
                {
                    switch (paramValue.ToUpper())
                    {
                    case "ISO8601":
                        _DateTimeFormat = DateTimeFormat.ISO8601;
                        break;

                    case "TICKS":
                        _DateTimeFormat = DateTimeFormat.Ticks;
                        break;

                    case "CURRENTCULTURE":
                        _DateTimeFormat = DateTimeFormat.CurrentCulture;
                        break;

                    default:
                        throw new SQLiteException(string.Format("Unknown DateTimeFormat specified: {0}", paramValue));
                    }
                }
                else
                {
                    throw new SQLiteException(string.Format("Unknown parameter specified: {0}.\r\n{1}", paramName, helpMessage));
                }
            }
        }