/// <summary> /// Auxiliary method for threading. /// Gets the fix points from the SQLite database. /// </summary> void GetPointsFromSQLiteDatabase() { UnityEngine.Debug.Log("This is the SQL DB path: " + fulldbPath); dbConnection = new SqliteConnection("URI=file:" + fulldbPath + "; Version=3;"); try { dbConnection.Open(); } catch (InvalidOperationException e) { UnityEngine.Debug.LogWarning("An exception has been catched and ignored. This is just a workaround for now, not 100% reliable! (by Miguel R. C.)\n Exception message:" + e.Message); } UnityEngine.Debug.Log("Database with fix points ready to use"); VVisQueryRequest request = new VVisQueryRequest("pointRequest", "select * from points order by no", ""); SqliteCommand query = new SqliteCommand(request.query, dbConnection); Stopwatch diagnosticTime = new Stopwatch(); diagnosticTime.Start(); try { UnityEngine.Debug.Log("Running query..."); points.Clear(); SqliteDataReader reader = query.ExecuteReader(); while (reader.Read()) { UnityEngine.Debug.Log(String.Format("{0}, {1}, {2}", reader["lat"], reader["long"], reader["count"])); Vector3 v = new Vector3( float.Parse(reader["lat"].ToString()), float.Parse(reader["long"].ToString()), int.Parse(reader["count"].ToString())); points.Add(v); } pointsReadyToBeDrawn = true; } catch (System.Exception e) { UnityEngine.Debug.LogWarning("The query could not be completed: " + e.Message); } finally { diagnosticTime.Stop(); UnityEngine.Debug.Log("Time needed to run the query (s): " + diagnosticTime.Elapsed.TotalSeconds); } dbConnection.Close(); }
/// <summary> /// Requests the SQLite database to run a query. /// </summary> /// <param name="requestor">Owner of the requested call. A message /// RequestDataSelection_CallBack will be sent to this gameObject with a List of strings /// containing the selection.</param> /// <param name="queryObj">VVIS query object containing the query information.</param> internal void RequestQuery(GameObject requestor, VVisQueryRequest queryObj) { if (dbIsReady && lastQueryCompleted) { thread.Abort(); thread = new Thread(() => ExecuteQuery(queryObj)); UnityEngine.Debug.Log("Thread for requesting query created"); lastQueryCompleted = false; thread.Start(); StartCoroutine(CallbackToRequestor(requestor)); } }
/// <summary> /// Visualizes a certain query from the vVis Data. /// </summary> /// <param name="vVisQuery">Query object with a select query.</param> internal void VisualizeQuery(VVisQueryRequest queryObj) { if (vVisSQLite != null && vVisSQLite.IsDBReady()) { vVisUICtrl.UICalculatingMode(true); CleanQueryRoadSelection(); vVisSQLite.RequestQuery(this.gameObject, queryObj); //Log info if (loggerAssembly != null && loggerAssembly.logVVis) { log.Info("Running query " + queryObj.name); } } }
/// <summary> /// Auxiliary method for threading. /// Executes the given query and fills the selectedRows list with the results. /// </summary> /// <param name="queryObj">VVIS query object containing the query information.</param> void ExecuteQuery(VVisQueryRequest queryObj) { SqliteCommand query = new SqliteCommand(queryObj.query, dbConnection); Stopwatch diagnosticTime = new Stopwatch(); diagnosticTime.Start(); try { UnityEngine.Debug.Log("Running query..."); selectedRows.Clear(); SqliteDataReader reader = query.ExecuteReader(); while (reader.Read()) { UnityEngine.Debug.Log(String.Format("{0}", reader[1])); selectedRows.Add(String.Format("{0}", reader[1])); } } catch (System.Exception e) { UnityEngine.Debug.LogWarning("The query could not be completed: " + e.Message); queryError = true; } finally { diagnosticTime.Stop(); UnityEngine.Debug.Log("Time needed to run the query (s): " + diagnosticTime.Elapsed.TotalSeconds); lastQueryCompleted = true; } }