Пример #1
0
        public List <RowWithName> SelectQueryWithColumnName(string sql)
        {
            if (!configured)
            {
                throw new Exception();
            }
            connection.Open();
            List <RowWithName> list = new List <RowWithName>();

            using (SQLiteCommand cmd = new SQLiteCommand(sql, connection))
            {
                Console.WriteLine("spoustim query");
                using (SQLiteDataReader reader = cmd.ExecuteReader())
                {
                    Console.WriteLine(reader.FieldCount);
                    while (reader.Read())
                    {
                        RowWithName row = new RowWithName();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            row.hodnoty.Add(reader.GetOriginalName(i), reader[i].ToString());
                        }
                        list.Add(row);
                    }
                }
            }
            connection.Close();
            return(list);
        }
        }                         // method

        private void WriteObjects(SQLiteDataReader reader, Newtonsoft.Json.JsonWriter wr, bool includeThids)
        {
            string value;

            for (int col = 0; col < reader.FieldCount; col++)
            {
                // include thid as fieldvalue in output?
                if (col == 0 && !includeThids)
                {
                    continue;
                }
                value = reader[col].ToString();
                // time and date fields have no original name
                if (string.IsNullOrEmpty(reader.GetOriginalName(col)))
                {
                    value = GetShortDateOrTime(value);
                }
                wr.WritePropertyName(reader.GetName(col));
                wr.WriteValue(value);
            }
        }
        }                                 // method

        private void WriteNodes(SQLiteDataReader dr, System.Xml.XmlWriter writer, bool includeThids)
        {
            string value;

            for (int col = 0; col < dr.FieldCount; col++)
            {
                if (col == 0 && !includeThids)
                {
                    continue;
                }                                            // skip first row
                value = dr[col].ToString();
                // time and date fields have no original name
                // it is an ugly trick, but let's use that to our advantage
                if (string.IsNullOrEmpty(dr.GetOriginalName(col))) // either a time or a date
                {
                    value = GetDateTimeString(value);
                }
                // we currently do not match up the datatypes in the DataTable with th returned values from SQLite
                writer.WriteStartElement(null, XmlConvert.EncodeLocalName(dr.GetName(col)), null);
                writer.WriteString(value); // WriteString will escape most (all?) invalid chars
                writer.WriteEndElement();
            } // for
        }