Function ccntool_core::myquery
source · pub fn myquery(conn: Pool<MySql>, notes: &str) -> Result<Vec<String>, Error>Expand description
Executes a SQL query against the dcim database and returns a vector
of strings containing the results. The query looks for the first port
in the fac_Ports table with a matching Notes field to the notes
argument, and returns various details about the associated switch and
port. If no matching row is found, an error is returned.
Arguments
conn- APool<MySql>representing a connection to thedcimdatabase.notes- A&strcontaining theNotesfield value to match against in thefac_Portstable.
Returns
A Result containing a vector of strings, where each string
represents a different detail about the switch and port.
The vector contains the following fields, in order:
results[0]- Switch hostname (Labelfield fromfac_Devicetable)results[1]- Port description (Notesfield fromfac_Portstable)results[2]- Switch port (Labelfield fromfac_Portstable)results[3]- Switch IP address (PrimaryIPfield fromfac_Devicetable)results[4]- Switch device ID (DeviceIDfield fromfac_Devicetable)
Errors
Returns an error of type sqlx::Error if no matching row is found in
the fac_Ports table.
Examples
fn main() {
let results = match myquery(connectdb(None, None, None), "01.1.001-1") {
Ok(rows) => {
self.error.clear();
rows
}
Err(error) => {
let error_message = format!("Received garbage: {error}");
self.error = error_message;
eprintln!("Error: {error}");
return;
}
};
..
}