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 thedcim
database.notes
- A&str
containing theNotes
field value to match against in thefac_Ports
table.
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 (Label
field fromfac_Device
table)results[1]
- Port description (Notes
field fromfac_Ports
table)results[2]
- Switch port (Label
field fromfac_Ports
table)results[3]
- Switch IP address (PrimaryIP
field fromfac_Device
table)results[4]
- Switch device ID (DeviceID
field fromfac_Device
table)
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;
}
};
..
}