Exemplo n.º 1
0
        /// <summary>
        /// Dumps data schema to specified writer
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="writer"></param>
        public static void DumpDataSchema(DbConnection connection, StreamWriter writer)
        {
            string key = "debug_key";

            if (writer != null)
            {
                Debug.Listeners.Add(new TextWriterTraceListener(writer.BaseStream, key));
            }

            DbUtilities.DumpDataSchema(connection);

            if (writer != null)
            {
                Debug.Listeners.Remove(key);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tests connection to the selected database
        /// </summary>
        public static bool TestConnection(string dbName, bool silentMode)
        {
            IDataProvider provider = DbUtilities.GetDataProvider(dbName);

            if (provider == null)
            {
                return(false);
            }

            bool         result = false;
            DbConnection conn   = provider.CreateConnection(dbName);

            try
            {
                conn.Open();
                Application.DoEvents();

                if (conn.State == ConnectionState.Open)
                {
                    if (!silentMode)
                    {
                        MessageBox.Show("Connection is successful.", "MapWinGIS",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    result = true;
                }
                else
                {
                    if (!silentMode)
                    {
                        MessageBox.Show("Connection failed.", "MapWinGIS",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            finally
            {
                conn.Close();
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a table based upon fileds of specified shapefile
        /// </summary>
        public bool CreateTable(MapWinGIS.Shapefile sf, string tableName)
        {
            this.CheckConnection();

            DbCommand command = m_connection.CreateCommand();

            string sql = " ([Geometry] " + m_provider.GetBinaryTypeName() + ", ";

            int count = sf.NumFields;

            for (int i = 0; i < count; i++)
            {
                MapWinGIS.Field field = sf.get_Field(i);
                string          s     = "[" + field.Name + "] ";
                switch (field.Type)
                {
                case MapWinGIS.FieldType.DOUBLE_FIELD:
                    s += m_provider.GetDoubleTypeName();
                    break;

                case MapWinGIS.FieldType.INTEGER_FIELD:
                    s += m_provider.GetIntergerTypeName();
                    break;

                case MapWinGIS.FieldType.STRING_FIELD:
                    bool   fixedLength = true;
                    string name        = m_provider.GetStringTypeName(out fixedLength);
                    s += fixedLength ? name + "(" + field.Width.ToString() + ")" : name;
                    break;

                default:
                    continue;
                }
                sql += s;
                sql += i < count - 1 ? ", " : ")";
            }

            command.CommandText = "CREATE TABLE [" + tableName + "]" + sql;
            command.ExecuteNonQuery();
            return(DbUtilities.TableExists(m_connection, tableName));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Refresh tables list in the selected database
        /// </summary>
        private void RefreshTables()
        {
            this.listView1.Items.Clear();

            IDataProvider provider = DbUtilities.GetDataProvider(this.txtFilename.Text);

            if (provider != null)
            {
                DbConnection connection = provider.CreateConnection(this.txtFilename.Text);
                connection.Open();
                try
                {
                    List <TableInfo> list = DbUtilities.GetTableList(connection);
                    foreach (TableInfo tbl in list)
                    {
                        this.listView1.Items.Add(tbl.Name);
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Tests database connection
 /// </summary>
 private void btnTest_Click(object sender, EventArgs e)
 {
     DbUtilities.TestConnection(this.txtFilename.Text, false);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Returns the list of tables which hold geometry
 /// </summary>
 /// <returns>List of table names</returns>
 public List <string> GetSpatialTables()
 {
     this.CheckConnection();
     return(DbUtilities.GetTablesByField(m_connection, "Geometry", "blob"));
 }