Example #1
0
 internal void SetDependancies(List <string> tables)
 {
     if (_createTableSql.ToLower().Contains("references "))
     {
         _dependancies = QueryExpress.GetDependancies(_createTableSql, tables);
     }
 }
Example #2
0
        void Export_GetConditionString(SQLiteDataReader rdr, StringBuilder sb)
        {
            bool isFirst = true;

            for (int i = 0; i < rdr.FieldCount; i++)
            {
                string colName = rdr.GetName(i);

                var col = Columns[colName];

                if (col.IsPrimaryKey)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        sb.Append(" AND ");
                    }

                    sb.Append("`");
                    sb.Append(colName);
                    sb.Append("`=");
                    sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
                }
            }
        }
Example #3
0
        public SQLiteTrigger(SQLiteCommand cmd, string triggerName)
        {
            _name = triggerName;

            _createTriggerSQL = QueryExpress.ExecuteScalarStr(cmd, string.Format("SELECT sql FROM sqlite_master WHERE type = 'trigger' AND name = '{0}';", triggerName), 0);

            _createTriggerSQL = _createTriggerSQL.Replace("\r\n", "^~~~~~~~~~~~~~~^").
                                Replace("\n", "^~~~~~~~~~~~~~~^").Replace("\r", "^~~~~~~~~~~~~~~^").
                                Replace("^~~~~~~~~~~~~~~^", " ");
        }
        public SQLiteSequenceList(SQLiteCommand cmd)
        {
            _sqlShowSequence = "SELECT name, seq FROM sqlite_sequence;";

            DataTable dt = QueryExpress.GetTable(cmd, _sqlShowSequence);

            foreach (DataRow dr in dt.Rows)
            {
                _lst.Add(new SQLiteSequence(dr[0] + "", (Int64)dr[1]));
            }
        }
Example #5
0
        internal SQLiteIndexList(SQLiteCommand cmd)
        {
            _sqlShowIndexes = "SELECT name, sql, tbl_name FROM sqlite_master WHERE type = 'index' AND sql <> '';";

            DataTable dt = QueryExpress.GetTable(cmd, _sqlShowIndexes);

            foreach (DataRow dr in dt.Rows)
            {
                _lst.Add(new SQLiteIndex(dr[0] + "", dr[1] + "", dr[2] + ""));
            }
        }
Example #6
0
        public SQLiteTable(SQLiteCommand cmd, string name)
        {
            _name = name;
            string sql = string.Format("SELECT sql FROM sqlite_master WHERE type='table' AND tbl_name='{0}';", name);

            _createTableSql = QueryExpress.ExecuteScalarStr(cmd, sql, 0).Replace(Environment.NewLine, "^~~~~~~^").
                              Replace("\r", "^~~~~~~^").Replace("\n", "^~~~~~~^").Replace("^~~~~~~^", " ").
                              Replace("CREATE TABLE ", "CREATE TABLE IF NOT EXISTS ") + ";";
            _lst = new SQLiteColumnList(cmd, name);
            GetInsertStatementHeaders();
        }
Example #7
0
        public SQLiteViewList(SQLiteCommand cmd, List <string> tables)
        {
            _sqlShowViewList = "SELECT name FROM sqlite_master WHERE type='view';";
            DataTable dt = QueryExpress.GetTable(cmd, _sqlShowViewList);

            foreach (DataRow dr in dt.Rows)
            {
                _lst.Add(new SQLiteView(cmd, dr[0] + ""));
            }

            SetDependancies(tables);
        }
Example #8
0
        public SQLiteView(SQLiteCommand cmd, string viewName)
        {
            _name = viewName;

            string sqlShowCreate = string.Format("SELECT sql FROM sqlite_master WHERE type = 'view' AND name = '{0}';", viewName);

            var dtView = QueryExpress.GetTable(cmd, sqlShowCreate);

            _createViewSQL = dtView.Rows[0][0] + ";";

            _createViewSQL = _createViewSQL.Replace("\r\n", "^~~~~~~~~~~~~~~^").
                             Replace("\n", "^~~~~~~~~~~~~~~^").Replace("\r", "^~~~~~~~~~~~~~~^").
                             Replace("^~~~~~~~~~~~~~~^", " ");
        }
        public SQLiteTableList(SQLiteCommand cmd)
        {
            _sqlShowFullTables = "SELECT tbl_name FROM sqlite_master WHERE type='table';";
            DataTable dtTableList = QueryExpress.GetTable(cmd, _sqlShowFullTables);

            foreach (DataRow dr in dtTableList.Rows)
            {
                if (dr[0] + "" != "sqlite_sequence")
                {
                    _lst.Add(new SQLiteTable(cmd, dr[0] + ""));
                }
            }

            SetDependancies();
        }
        public SQLiteColumnList(SQLiteCommand cmd, string tableName)
        {
            _tableName = tableName;
            DataTable dtDataType = QueryExpress.GetTable(cmd, string.Format("SELECT * FROM  `{0}` where 1 = 2;", tableName));

            _sqlShowFullColumns = string.Format("PRAGMA table_info(`{0}`);", tableName);
            DataTable dtColInfo = QueryExpress.GetTable(cmd, _sqlShowFullColumns);

            for (int i = 0; i < dtDataType.Columns.Count; i++)
            {
                _lst.Add(new SQLiteColumn(
                             dtDataType.Columns[i].ColumnName,
                             dtDataType.Columns[i].DataType,
                             dtColInfo.Rows[i]["type"] + "",
                             ((Int64)dtColInfo.Rows[i]["notnull"] < 1),
                             dtColInfo.Rows[i]["dflt_value"] + "",
                             ((Int64)dtColInfo.Rows[i]["pk"] > 0)));
            }
        }
Example #11
0
        string Export_GetValueString(SQLiteDataReader rdr)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < rdr.FieldCount; i++)
            {
                if (sb.Length == 0)
                {
                    sb.AppendFormat("(");
                }
                else
                {
                    sb.AppendFormat(",");
                }

                sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, Columns[rdr.GetName(i)]));
            }

            sb.AppendFormat(")");

            return(sb.ToString());
        }
Example #12
0
 internal void SetDependancies(List <string> tables, List <string> views)
 {
     _tableDependancies = QueryExpress.GetDependancies(_createViewSQL, tables);
     _viewDependancies  = QueryExpress.GetDependancies(_createViewSQL, views);
 }
Example #13
0
        internal void SetTotalRows(SQLiteCommand cmd)
        {
            string sql = string.Format("SELECT COUNT(*) FROM `{0}`;", _name);

            _totalRows = (int)QueryExpress.ExecuteScalarLong(cmd, sql);
        }
Example #14
0
        public static string ConvertToSqlFormat(SQLiteDataReader rdr, int colIndex, bool wrapStringWithSingleQuote, bool escapeStringSequence, SQLiteColumn col)
        {
            object ob = rdr[colIndex];

            StringBuilder sb = new StringBuilder();

            if (ob == null || ob is System.DBNull)
            {
                sb.AppendFormat("NULL");
            }
            else if (ob is System.String)
            {
                string str = (string)ob;

                if (escapeStringSequence)
                {
                    str = QueryExpress.EscapeStringSequence(str);
                }

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }

                sb.Append(str);

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }
            }
            else if (ob is System.Boolean)
            {
                sb.AppendFormat(Convert.ToInt32(ob).ToString());
            }
            else if (ob is System.Byte[])
            {
                if (((byte[])ob).Length == 0)
                {
                    return("NULL");
                }
                else
                {
                    if (wrapStringWithSingleQuote)
                    {
                        sb.AppendFormat("X'");
                    }
                    sb.AppendFormat(CryptoExpress.ConvertByteArrayToHexString((byte[])ob));
                    if (wrapStringWithSingleQuote)
                    {
                        sb.AppendFormat("'");
                    }
                }
            }
            else if (ob is short)
            {
                sb.AppendFormat(((short)ob).ToString(_numberFormatInfo));
            }
            else if (ob is int)
            {
                sb.AppendFormat(((int)ob).ToString(_numberFormatInfo));
            }
            else if (ob is long)
            {
                sb.AppendFormat(((long)ob).ToString(_numberFormatInfo));
            }
            else if (ob is ushort)
            {
                sb.AppendFormat(((ushort)ob).ToString(_numberFormatInfo));
            }
            else if (ob is uint)
            {
                sb.AppendFormat(((uint)ob).ToString(_numberFormatInfo));
            }
            else if (ob is ulong)
            {
                sb.AppendFormat(((ulong)ob).ToString(_numberFormatInfo));
            }
            else if (ob is double)
            {
                sb.AppendFormat(((double)ob).ToString(_numberFormatInfo));
            }
            else if (ob is decimal)
            {
                sb.AppendFormat(((decimal)ob).ToString(_numberFormatInfo));
            }
            else if (ob is float)
            {
                sb.AppendFormat(((float)ob).ToString(_numberFormatInfo));
            }
            else if (ob is byte)
            {
                sb.AppendFormat(((byte)ob).ToString(_numberFormatInfo));
            }
            else if (ob is sbyte)
            {
                sb.AppendFormat(((sbyte)ob).ToString(_numberFormatInfo));
            }
            else if (ob is TimeSpan)
            {
                TimeSpan ts = (TimeSpan)ob;

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }

                sb.AppendFormat(ts.Hours.ToString().PadLeft(2, '0'));
                sb.AppendFormat(":");
                sb.AppendFormat(ts.Minutes.ToString().PadLeft(2, '0'));
                sb.AppendFormat(":");
                sb.AppendFormat(ts.Seconds.ToString().PadLeft(2, '0'));

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }
            }
            else if (ob is System.DateTime)
            {
                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }

                sb.AppendFormat(((DateTime)ob).ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }
            }
            else if (ob is System.Guid)
            {
                if (col.SQLiteDataType == "blob")
                {
                    if (wrapStringWithSingleQuote)
                    {
                        sb.AppendFormat("X'");
                    }

                    sb.Append(CryptoExpress.ConvertByteArrayToHexString(((Guid)ob).ToByteArray()));
                }
                else
                {
                    if (wrapStringWithSingleQuote)
                    {
                        sb.AppendFormat("'");
                    }

                    sb.Append(ob);
                }
                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }
            }
            else
            {
                throw new Exception("Unhandled data type. Current processing data type: " + ob.GetType().ToString() + ". Please report this bug with this message to the development team.");
            }
            return(sb.ToString());
        }