/// <summary> /// Run non execute query, like create database and drop database /// </summary> /// <param name="textfileLocation"> /// The textfile location. /// </param> /// <param name="theForm"> /// The form. /// </param> /// <returns> /// The number of errors /// </returns> private static int RunNonExecuteQuery(string textfileLocation, Form1 theForm) { var numErrors = 0; // Read testfile: string connectionString; List <string> queryList; if (!ReadTextfile(textfileLocation, out connectionString, out queryList)) { throw new Exception("Cannot read text file"); } // Connect to data source: var ds = new OgrDatasource { GlobalCallback = theForm }; if (!ds.Open(connectionString)) { throw new Exception("Failed to open datasource: " + ds.GdalLastErrorMsg); } // Get queries: foreach (var query in queryList) { string errorMsg; if (ds.ExecuteSQL(query, out errorMsg)) { theForm.Progress("Executed query: " + query); continue; } if (ds.GdalLastErrorMsg.Contains("cannot run inside a transaction block")) { errorMsg += " You're probably using a too old version of GDAL v2, please update."; } theForm.WriteError(string.Format("Error executing query [{0}]: {1}", query, errorMsg)); numErrors++; } // Close database connection: ds.Close(); return(numErrors); }
/// <summary> /// Test setting PostGIS privileges. /// </summary> /// <param name="textfileLocation"> /// The textfile location. /// </param> /// <param name="theForm"> /// The form. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> internal static bool RunPostGisPostGisPrivileges(string textfileLocation, Form1 theForm) { var numErrors = 0; theForm.Progress( "-----------------------The setting of the grants and privileges has started." + Environment.NewLine); // Read testfile: string connectionString; List <string> queryList; if (!ReadTextfile(textfileLocation, out connectionString, out queryList)) { throw new Exception("Cannot read text file"); } // Connect to data source: var ds = new OgrDatasource { GlobalCallback = theForm }; if (!ds.Open(connectionString)) { throw new Exception("Failed to open datasource: " + ds.GdalLastErrorMsg); } // Get every first and second line: foreach (var query in queryList) { string errorMsg; if (!ds.ExecuteSQL(query, out errorMsg)) { theForm.WriteError(string.Format("Error executing query [{0}]: {1}", query, errorMsg)); numErrors++; } } // Close database connection: ds.Close(); theForm.Progress( string.Format("The setting of the grants and privileges test has finished, with {0} errors", numErrors)); return(numErrors == 0); }
private static bool TestExecuteSQL() { var ds = new OgrDatasource(); if (!ds.Open(CONNECTION_STRING)) { Debug.Print("Failed to establish connection: " + ds.GdalLastErrorMsg); } else { string errorMsg; bool result = ds.ExecuteSQL("DELETE FROM tableName WHERE gid > 100", out errorMsg); if (!result) { Debug.Print("Error on running SQL: " + errorMsg); } else { Debug.Print("SQL was executed successfully."); } ds.Close(); } return(true); }
public bool ExecuteSql(string sql, out string errorMessage) { return(_datasource.ExecuteSQL(sql, out errorMessage)); }