Esempio n. 1
0
        static void Main(string[] args)
        {
            // Get the Northwind OrderDetails data.
            var orderDetails = GetDataTable("OrderDetails");

            // Convert the DataTable to an XmlToCursor formatted xml string.
            // ToXmlToCursorFormattedXml is an DataTable extension method in the VfpClient namespace.
            var xml = orderDetails.ToXmlToCursorFormattedXml();

            using (var connection = new VfpConnection(ConfigurationManager.ConnectionStrings["FreeTables"].ConnectionString)) {
                connection.Open();

                // Create cursor using XmlToCursor with the DataTable xml.
                using (var command = connection.CreateCommand()) {
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "XmlToCursor";
                    command.Parameters.Add(new VfpParameter("xml", xml));
                    command.Parameters.Add(new VfpParameter("cursor", "curXmlTemp"));
                    command.ExecuteNonQuery();
                }

                // Use the cursor to insert records into the destination table.
                using (var command = connection.CreateCommand()) {
                    command.CommandText = "INSERT INTO 'OrderDetailsArchive' SELECT * FROM curXmlTemp";
                    command.ExecuteNonQuery();
                }

                connection.Close();
            }
        }
Esempio n. 2
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                using (var connection = new VfpConnection(txtDataPath.Text)) {
                    connection.Open();
                    connection.Close();
                }
            }
            catch (Exception) {
                MessageBox.Show("Invalid connection string.", Title, MessageBoxButton.OK, MessageBoxImage.Error);

                e.Handled = true;
            }

            if (e.Handled)
            {
                return;
            }

            _connectionInfo.DynamicSchemaOptions.NoPluralization  = !Pluralization.IsChecked.Value;
            _connectionInfo.DynamicSchemaOptions.NoCapitalization = !Capitalize.IsChecked.Value;

            var singularizeElement = _connectionInfo.DriverData.Element("Singularize");

            if (singularizeElement == null)
            {
                _connectionInfo.DriverData.Add(new XElement("Singularize", Singularize.IsChecked.Value));
            }
            else
            {
                singularizeElement.Value = Singularize.IsChecked.Value.ToString();
            }

            DialogResult = true;
        }
Esempio n. 3
0
        private void DoConnected(Action action)
        {
            if (action == null)
            {
                return;
            }

            var closeConnection = false;

            if (_connection.State == ConnectionState.Closed)
            {
                _connection.Open();
                closeConnection = true;
            }

            try {
                action();
            }
            finally {
                if (closeConnection)
                {
                    _connection.Close();
                }
            }
        }
Esempio n. 4
0
        public void PackTest()
        {
            var dbc     = CreateTempDbc();
            var builder = new VfpConnectionStringBuilder(dbc);

            builder.Deleted = false;

            using (var connection = new VfpConnection(builder.ConnectionString)) {
                connection.Open();

                using (var command = connection.CreateCommand()) {
                    command.CommandText = "select count(*) from temp";

                    Assert.AreEqual(13, Convert.ToInt32(command.ExecuteScalar()));

                    command.CommandText = "delete from temp where upper(allt(TableName)) == 'CUSTOMERS'";
                    command.ExecuteNonQuery();

                    command.CommandText = "select count(*) from temp";

                    Assert.AreEqual(13, Convert.ToInt32(command.ExecuteScalar()));

                    connection.Pack("temp");

                    command.CommandText = "select count(*) from temp";

                    Assert.AreEqual(12, Convert.ToInt32(command.ExecuteScalar()));
                }

                connection.Close();
            }
        }
Esempio n. 5
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                using (var connection = new VfpConnection(txtDataPath.Text)) {
                    connection.Open();
                    connection.Close();
                }
            }
            catch (Exception) {
                MessageBox.Show("Invalid connection string.", Title, MessageBoxButton.OK, MessageBoxImage.Error);

                e.Handled = true;
            }

            if (e.Handled) {
                return;
            }

            _connectionInfo.DynamicSchemaOptions.NoPluralization = !Pluralization.IsChecked.Value;
            _connectionInfo.DynamicSchemaOptions.NoCapitalization = !Capitalize.IsChecked.Value;

            var singularizeElement = _connectionInfo.DriverData.Element("Singularize");

            if (singularizeElement == null) {
                _connectionInfo.DriverData.Add(new XElement("Singularize", Singularize.IsChecked.Value));
            }
            else {
                singularizeElement.Value = Singularize.IsChecked.Value.ToString();
            }

            DialogResult = true;
        }
Esempio n. 6
0
        public VfpConnection CreateConnection()
        {
            var connection = new VfpConnection(this.GetConnectionString());

            connection.Open();

            return(connection);
        }
Esempio n. 7
0
        protected override VfpConnection GetConnection()
        {
            var connectionString = Path.Combine(GetTestDeploymentDir(TestContext), "FreeTables");
            var connection       = new VfpConnection(connectionString);

            connection.Open();

            return(connection);
        }
Esempio n. 8
0
        public IEnumerable <string> GetTableNames()
        {
            using (var connection = new VfpConnection(ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString)) {
                connection.Open();

                var tableNames = connection.GetSchema(VfpConnection.SchemaNames.Tables)
                                 .AsEnumerable()
                                 .Select(x => x.Field <string>(VfpConnection.SchemaColumnNames.Table.TableName))
                                 .OrderBy(x => x)
                                 .ToArray();

                connection.Close();

                return(tableNames);
            }
        }
Esempio n. 9
0
        private static void Main(string[] args)
        {
            using (var connection = new VfpConnection(ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString)) {
                connection.Open();

                var tables = connection.GetSchema(VfpConnection.SchemaNames.Tables);
                var fields = connection.GetSchema(VfpConnection.SchemaNames.TableFields);

                connection.Close();

                var dbc        = GetNewDbcFullPath();
                var dbcCreator = new DataTableDbcCreator(dbc);

                dbcCreator.Add(tables);
                dbcCreator.Add(fields);
            }
        }
Esempio n. 10
0
        protected virtual VfpConnection GetConnection(string connectionString = null, bool keepClosed = false)
        {
            var northwind  = Path.Combine(TestContext.TestDeploymentDir, "northwind.dbc");
            var connection = new VfpConnection(connectionString ?? "Data Source=" + northwind);

            if (!keepClosed)
            {
                connection.Open();
            }

            if (!Debugger.IsAttached)
            {
                connection.CommandExecuting = details => TestContext.WriteLine(details.ToTraceString() + Environment.NewLine);
                connection.CommandFailed    = details => TestContext.WriteLine(details.ToTraceString() + Environment.NewLine);
                connection.CommandFinished  = details => TestContext.WriteLine(details.ToTraceString() + Environment.NewLine);
            }

            return(connection);
        }
Esempio n. 11
0
        public void ZapTest()
        {
            var dbc = CreateTempDbc();

            using (var connection = new VfpConnection(dbc)) {
                connection.Open();

                using (var command = connection.CreateCommand()) {
                    command.CommandText = "select count(*) from temp";

                    Assert.AreNotEqual(0, Convert.ToInt32(command.ExecuteScalar()));

                    connection.Zap("temp");

                    Assert.AreEqual(0, Convert.ToInt32(command.ExecuteScalar()));
                }

                connection.Close();
            }
        }