Ejemplo n.º 1
0
        //---------------------------------------------------------------------
        public override List <TbDataInfo> getTableData(string sqlite_query)
        {
            SQLiteQuery       qr = new SQLiteQuery(mSQLiteDB, sqlite_query);
            List <TbDataInfo> list_table_data = new List <TbDataInfo>();

            while (qr.Step())
            {
                TbDataInfo      tbdata_info = new TbDataInfo();
                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;
                    }
                }

                tbdata_info.Id           = id;
                tbdata_info.ListDataInfo = list_data;
                list_table_data.Add(tbdata_info);
            }

            return(list_table_data);
        }
Ejemplo n.º 2
0
        //---------------------------------------------------------------------
        public override List <TbDataInfo> getTableData(string sqlite_query)
        {
            List <TbDataInfo> list_table_data = new List <TbDataInfo>();
            IntPtr            stmHandle       = Prepare(sqlite_query);
            int columnCount = sqlite3_column_count(stmHandle);

            while (sqlite3_step(stmHandle) == SQLITE_ROW)
            {
                TbDataInfo      tbdata_info = new TbDataInfo();
                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;
                    }
                }
                tbdata_info.Id           = id;
                tbdata_info.ListDataInfo = list_data;
                list_table_data.Add(tbdata_info);
            }

            return(list_table_data);
        }
Ejemplo n.º 3
0
        //---------------------------------------------------------------------
        void _loadTable(string table_name)
        {
            string str_query_select = string.Format("SELECT * FROM {0};", table_name);

            try
            {
                List <TbDataInfo> list_data = Sqlite.getTableData(str_query_select);
                if (list_data.Count <= 0)
                {
                    return;
                }

                EbTableBuffer table = new EbTableBuffer(table_name);

                foreach (var i in list_data)
                {
                    //int data_id = i.Key;
                    //table.WriteInt(data_id);
                    TbDataInfo      d_info         = i;
                    List <DataInfo> list_data_info = d_info.ListDataInfo;
                    foreach (var data_info in list_data_info)
                    {
                        object data_value = data_info.data_value;
                        //string data_name = data_info.data_name;

                        switch (data_info.data_type)
                        {
                        case 1:
                            table.WriteInt((int)data_value);
                            break;

                        case 2:
                            table.WriteFloat((float)(double)data_value);
                            break;

                        case 3:
                            table.WriteString((string)data_value);
                            break;
                        }
                    }
                }

                table.WriteEnd();

                mMapTable[table.TableName] = table;
            }
            catch (Exception e)
            {
                EbLog.Error(str_query_select + "_______" + e.ToString());
            }
        }