コード例 #1
0
ファイル: FileSqlLoaderConnection.cs プロジェクト: npenin/uss
        internal override void ExecuteCommand(FileCommand command)
        {
            if (command.CommandText.StartsWith("-- TABLE"))
            {
                command.CommandText = command.CommandText.Substring("-- TABLE ".Length);
                StringReader sr = new StringReader(command.CommandText);
                string tableName = sr.ReadLine();
                command.CommandText = sr.ReadToEnd();
                sr.Close();
                FileConnection connection;
                if (!fileConnections.ContainsKey(tableName))
                {
                    connection = new FileConnection();
                    connection.ConnectionString = "filename=" + path + tableName + ".asc";
                    connection.Open();
                    connection.Dialect = Dialect;
                    fileConnections.Add(tableName, connection);
                }
                else
                    connection = fileConnections[tableName];
                connection.ExecuteCommand(command);
            }
            else if (command.CommandText.StartsWith("-- UPDATE"))
            {
                command.CommandText = command.CommandText.Substring("-- UPDATE ".Length);
                TextReader sr = new StringReader(command.CommandText);
                string tableName = sr.ReadLine();
                command.CommandText = sr.ReadToEnd();
                sr.Close();
                command.CommandText = TransformToSql(command);
                FileConnection connection;
                if (fileConnections.ContainsKey(tableName))
                {
                    connection = fileConnections[tableName];
                    connection.Close();
                    fileConnections.Remove(tableName);
                }
                FileStream fs = File.Open(path + tableName + ".asc", FileMode.Open);
                sr = new StreamReader(fs);
                string[] values = command.CommandText.Split('$');
                int position = 0;
                bool found = false;
                while (!found && !((StreamReader)sr).EndOfStream)
                {
                    string line = sr.ReadLine();
                    string[] lineValues = line.Split('$');
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(values[i]) && !string.IsNullOrEmpty(lineValues[i]) && values[i] == lineValues[i])
                        {
                            found = true;
                            for (int j = 0; j < values.Length; j++)
                            {
                                if (string.IsNullOrEmpty(values[j]))
                                    values[j] = lineValues[j];
                            }
                            break;
                        }
                    }
                    if (found)
                    {
                        string toEnd = sr.ReadToEnd();
                        fs.Seek(position, SeekOrigin.Begin);
                        StreamWriter sw = new StreamWriter(fs);
                        sw.WriteLine(string.Join("$", values) + "$");
                        sw.Write(toEnd);
                        sw.Close();
                    }
                    else
                        position += line.Length + StringWriter.Null.NewLine.Length;

                }
            }
            else
            {
                command.CommandText = command.CommandText.Substring("-- LOAD ".Length);
                TextReader sr = new StringReader(command.CommandText);
                string tableName = sr.ReadLine();
                command.CommandText = sr.ReadToEnd();
                sr.Close();
                base.Close();
                filename = path + tableName + ".ctl";
                base.Open();
                base.ExecuteCommand(command);
            }
        }
コード例 #2
0
ファイル: FileCommand.cs プロジェクト: npenin/uss
 public FileCommand(FileConnection connection)
     : this(connection, String.Empty)
 {
 }
コード例 #3
0
ファイル: FileCommand.cs プロジェクト: npenin/uss
 public FileCommand(FileConnection connection, string commandText)
 {
     this.connection = connection;
     this.commandText = commandText;
 }
コード例 #4
0
ファイル: FileTransaction.cs プロジェクト: npenin/uss
 public FileTransaction(FileConnection connection)
 {
     this.connection = connection;
 }