Exemple #1
0
        public NSMutableDictionary GetConfigSettings()
        {
            NSMutableDictionary returnDictionary = new NSMutableDictionary();

            IntPtr statement = IntPtr.Zero;

            statement = SQLite3.Prepare2(_database, SQL_GET_SETTINGS);
            int detailedLogOn = -100;

            if (statement == IntPtr.Zero)
            {
                return(null);
            }

            var result = SQLite3.Step(statement);

            if (result == SQLite3.Result.Row)
            {
                IntPtr serverHostPtr = SQLite3.ColumnText(statement, 0);
                string serverHost    = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(serverHostPtr);
                int    port          = SQLite3.ColumnInt(statement, 1);
                int    priority      = SQLite3.ColumnInt(statement, 2);
                IntPtr configPtr     = SQLite3.ColumnText(statement, 3);
                string config        = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(configPtr);
                int    copyPasteOn   = SQLite3.ColumnInt(statement, 4);
                detailedLogOn = SQLite3.ColumnInt(statement, 5);
                IntPtr userEmailPtr = SQLite3.ColumnText(statement, 6);
                string userEmail    = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(userEmailPtr);

                if (!String.IsNullOrWhiteSpace(serverHost))
                {
                    GDAppServer firstServer = new GDAppServer(serverHost, new NSNumber(port), new NSNumber(priority));
                    returnDictionary.Add(GDiOS.GDAppConfigKeyServers, firstServer);
                }
                if (!String.IsNullOrWhiteSpace(config))
                {
                    returnDictionary.Add(GDiOS.GDAppConfigKeyConfig, new NSString(config));
                }
                returnDictionary.Add(GDiOS.GDAppConfigKeyCopyPasteOn, new NSNumber(copyPasteOn));
                if (detailedLogOn != -100)
                {
                    returnDictionary.Add(GDiOS.GDAppConfigKeyDetailedLogsOn, new NSNumber(detailedLogOn));
                }
                if (!string.IsNullOrWhiteSpace(userEmail))
                {
                    returnDictionary.Add(GDiOS.GDAppConfigKeyUserId, new NSString(userEmail));
                }
            }

            SQLite3.Finalize(statement);
            return(returnDictionary);
        }
Exemple #2
0
        public IEnumerator <IDictionary <String, Object> > ExecuteSelectQuery(DatabaseDescriptor databaseDescriptor, EntityDescriptor entityDescriptor, String query)
        {
            #if XAMARIN
            SQLitePCL.sqlite3_stmt statement = SQLite3.Prepare2(sqliteDatabase.Handle, query);
            #elif WINDOWS
            List <SQLiteQueryRow> statement = null;
            #endif

            try
            {
                #if XAMARIN
                statement = SQLite3.Prepare2(sqliteDatabase.Handle, query);
                #elif WINDOWS
                statement = sqliteDatabase.Query2(query);
                #endif
            }
            catch (System.Exception exception)
            {
                if (sqliteDatabase.IsInTransaction)
                {
                    sqliteDatabase.Rollback();
                }

                Log.Log.Error(typeof(Database).FullName, "ExecuteSelectQuery", "Exception caught while executing the select query, QUERY: " + query);
                throw new DatabaseException(typeof(Database).FullName, "ExecuteSelectQuery", exception.Message);
            }

            List <Dictionary <String, Object> > tuples = new List <Dictionary <String, Object> >();

            #if XAMARIN
            SQLite3.Result result;
            while ((result = SQLite3.Step(statement)) == SQLite3.Result.Row)
            {
                IDictionary <String, Object> tuple = new Dictionary <String, Object>();

                String stmtResult = result.ToString();

                //string[] names = SQLite3.ColType.GetNames ();
                //string[] values = SQLite3.ColType.GetValues ();
                int columnsCount = SQLite3.ColumnCount(statement);
                for (int i = 0; i < columnsCount; i++)
                {
                    String          columnName  = SQLite3.ColumnName(statement, i);
                    SQLite3.ColType columnType  = SQLite3.ColumnType(statement, i);
                    Object          columnValue = SQLite3.ColumnText(statement, i);

                    bool isString = false;
                    bool isLong   = false;
                    bool isFloat  = false;
                    bool isBlob   = false;

                    if (columnType == SQLite3.ColType.Text)
                    {
                        isString = true;
                    }
                    else if (columnType == SQLite3.ColType.Integer)
                    {
                        isLong = true;
                    }
                    else if (columnType == SQLite3.ColType.Float)
                    {
                        isFloat = true;
                    }
                    else if (columnType == SQLite3.ColType.Blob)
                    {
                        isBlob = true;
                    }
                    else if (columnType == SQLite3.ColType.Null)
                    {
                    }


                    if (isString)
                    {
                        if (entityDescriptor != null)
                        {
                            EntityDescriptor.Attribute attribute = entityDescriptor.GetAttributeBasedOnColumnName(columnName);

                            if (attribute != null)
                            {
                                if (attribute.GetType().Equals(IDataTypeHandler.CSHARP_STRING_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, (String)columnValue);
                                }
                                else if (attribute.GetType().Equals(IDataTypeHandler.CSHARP_BOOLEAN_PRIMITIVE_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, columnValue.Equals(Boolean.TrueString.ToString()) ? true : false);
                                }
                                else if (attribute.GetType().Equals(IDataTypeHandler.CSHARP_BOOLEAN_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, columnValue.Equals(Boolean.TrueString.ToString()) ? Boolean.TrueString : Boolean.FalseString);
                                }
                                else if (attribute.GetType().Equals(IDataTypeHandler.JAVASCRIPT_STRING_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, (String)columnValue);
                                }
                            }
                            else
                            {
                                tuple.Add(columnName, columnValue);
                            }
                        }
                        else
                        {
                            tuple.Add(columnName, columnValue);
                        }
                    }
                    else if (isLong)
                    {
                        if (entityDescriptor != null)
                        {
                            EntityDescriptor.Attribute attribute = entityDescriptor.GetAttributeBasedOnColumnName(columnName);

                            if (attribute != null)
                            {
                                if (attribute.GetType().Equals(IDataTypeHandler.JAVASCRIPT_NUMBER_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, columnValue);
                                }
                            }
                            else
                            {
                                tuple.Add(columnName, columnValue);
                            }
                        }
                        else
                        {
                            tuple.Add(columnName, columnValue);
                        }
                    }
                    else if (isFloat)
                    {
                        if (entityDescriptor != null)
                        {
                            EntityDescriptor.Attribute attribute = entityDescriptor.GetAttributeBasedOnColumnName(columnName);

                            if (attribute != null)
                            {
                                if (attribute.GetType().Equals(IDataTypeHandler.JAVASCRIPT_NUMBER_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, columnValue);
                                }
                            }
                            else
                            {
                                tuple.Add(columnName, columnValue);
                            }
                        }
                        else
                        {
                            tuple.Add(columnName, columnValue);
                        }

                        tuple.Add(columnName, columnValue);
                    }
                    else if (isBlob)
                    {
                        tuple.Add(columnName, columnValue);
                    }
                }

                tuples.Add((Dictionary <String, Object>)tuple);
            }

            SQLite3.Finalize(statement);

            return(tuples.GetEnumerator());
            #elif WINDOWS
            foreach (SQLiteQueryRow cursor in statement)
            {
                IDictionary <String, Object> tuple = new Dictionary <String, Object>();

                List <SQLiteQueryColumn> columns = cursor.column;
                if (columns == null || columns.Count <= 0)
                {
                    continue;
                }

                foreach (SQLiteQueryColumn column in columns)
                {
                    String columnName  = column.Key;
                    Object columnValue = column.Value;


                    bool isString = false;
                    bool isLong   = false;
                    bool isFloat  = false;
                    bool isBlob   = false;

                    if (columnValue != null)
                    {
                        if (columnValue.GetType().FullName.Equals(typeof(String).FullName, StringComparison.OrdinalIgnoreCase))
                        {
                            isString = true;
                        }
                        else if (columnValue.GetType().FullName.Equals(typeof(long).FullName, StringComparison.OrdinalIgnoreCase))
                        {
                            isLong = true;
                        }
                        else if (columnValue.GetType().FullName.Equals(typeof(float).FullName, StringComparison.OrdinalIgnoreCase))
                        {
                            isFloat = true;
                        }
                        else if (columnValue.GetType().FullName.Equals(typeof(byte).FullName, StringComparison.OrdinalIgnoreCase))
                        {
                            isBlob = true;
                        }
                    }
                    else
                    {
                        isString = true;
                    }


                    if (isString)
                    {
                        if (entityDescriptor != null)
                        {
                            EntityDescriptor.Attribute attribute = entityDescriptor.GetAttributeBasedOnColumnName(columnName);

                            if (attribute != null)
                            {
                                if (attribute.GetType().Equals(IDataTypeHandler.CSHARP_STRING_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, (String)columnValue);
                                }
                                else if (attribute.GetType().Equals(IDataTypeHandler.CSHARP_BOOLEAN_PRIMITIVE_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, columnValue.Equals(Boolean.TrueString.ToString()) ? true : false);
                                }
                                else if (attribute.GetType().Equals(IDataTypeHandler.CSHARP_BOOLEAN_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, columnValue.Equals(Boolean.TrueString.ToString()) ? Boolean.TrueString : Boolean.FalseString);
                                }
                                else if (attribute.GetType().Equals(IDataTypeHandler.JAVASCRIPT_STRING_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, (String)columnValue);
                                }
                            }
                            else
                            {
                                tuple.Add(columnName, columnValue);
                            }
                        }
                        else
                        {
                            tuple.Add(columnName, columnValue);
                        }
                    }
                    else if (isLong)
                    {
                        if (entityDescriptor != null)
                        {
                            EntityDescriptor.Attribute attribute = entityDescriptor.GetAttributeBasedOnColumnName(columnName);

                            if (attribute != null)
                            {
                                if (attribute.GetType().Equals(IDataTypeHandler.JAVASCRIPT_NUMBER_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, columnValue);
                                }
                            }
                            else
                            {
                                tuple.Add(columnName, columnValue);
                            }
                        }
                        else
                        {
                            tuple.Add(columnName, columnValue);
                        }
                    }
                    else if (isFloat)
                    {
                        if (entityDescriptor != null)
                        {
                            EntityDescriptor.Attribute attribute = entityDescriptor.GetAttributeBasedOnColumnName(columnName);

                            if (attribute != null)
                            {
                                if (attribute.GetType().Equals(IDataTypeHandler.JAVASCRIPT_NUMBER_DATA_TYPE, StringComparison.OrdinalIgnoreCase))
                                {
                                    tuple.Add(columnName, columnValue);
                                }
                            }
                            else
                            {
                                tuple.Add(columnName, columnValue);
                            }
                        }
                        else
                        {
                            tuple.Add(columnName, columnValue);
                        }

                        tuple.Add(columnName, columnValue);
                    }
                    else if (isBlob)
                    {
                        tuple.Add(columnName, columnValue);
                    }
                }

                tuples.Add((Dictionary <String, Object>)tuple);
            }


            return(tuples.GetEnumerator());
            #endif
        }