Example #1
0
        //---------------------------------------------------------------------
        public override Dictionary<int, List<DataInfo>> getTableData(string sqlite_query)
        {
            SQLiteQuery qr = new SQLiteQuery(mSQLiteDB, sqlite_query);
            Dictionary<int, List<DataInfo>> map_table_data = new Dictionary<int, List<DataInfo>>();

            while (qr.Step())
            {
                string[] data_names = qr.Names;
                List<DataInfo> list_data = new List<DataInfo>();
                int id = -1;
                foreach (var i in data_names)
                {
                    bool is_null = qr.IsNULL(i);
                    if (is_null)
                    {
                        continue;
                    }

                    int field_type = qr.GetFieldType(i);
                    DataInfo data_info = new DataInfo();
                    data_info.data_type = field_type;
                    data_info.data_name = i;
                    object data_value = "";
                    switch (field_type)
                    {
                        case 1:// SQLITE_INTEGER
                            {
                                data_value = qr.GetInteger(i);
                            }
                            break;
                        case 2:// SQLITE_FLOAT
                            {
                                data_value = qr.GetDouble(i);
                            }
                            break;
                        case 3:// SQLITE_TEXT
                            {
                                data_value = qr.GetString(i);
                            }
                            break;
                    }
                    data_info.data_value = data_value;
                    list_data.Add(data_info);
                    if (i.Equals("Id"))
                    {
                        id = (int)data_value;
                    }
                }

                map_table_data[id] = list_data;
            }

            return map_table_data;
        }
Example #2
0
    //---------------------------------------------------------------------
    public override Dictionary<int, List<DataInfo>> getTableData(string sqlite_query)
    {
        Dictionary<int, List<DataInfo>> map_table_data = new Dictionary<int, List<DataInfo>>();
        IntPtr stmHandle = Prepare(sqlite_query);
        int columnCount = sqlite3_column_count(stmHandle);
        while (sqlite3_step(stmHandle) == SQLITE_ROW)
        {
            List<DataInfo> list_data = new List<DataInfo>();
            int id = -1;
            for (int i = 0; i < columnCount; i++)
            {
                int data_type = sqlite3_column_type(stmHandle, i);
                string name = Marshal.PtrToStringAnsi(sqlite3_column_name(stmHandle, i));

                DataInfo data_info = new DataInfo();
                data_info.data_type = data_type;
                data_info.data_name = name;
                object data_value = "";
                switch (data_type)
                {
                    case 1:// SQLITE_INTEGER
                        {                            
                            data_value = sqlite3_column_int(stmHandle, i);
                        }
                        break;
                    case 2:// SQLITE_FLOAT
                        {                            
                            data_value = sqlite3_column_double(stmHandle, i);
                        }
                        break;
                    case 3:// SQLITE_TEXT
                        {                            
                            data_value = Marshal.PtrToStringAnsi(sqlite3_column_text(stmHandle, i));
                        }
                        break;
                }                
                data_info.data_value = data_value;
                list_data.Add(data_info);

                if (name.Equals("Id"))
                {
                    id = (int)data_value;
                }
            }
            map_table_data[id] = list_data;
        }
        return map_table_data;
    }