pub struct Collection { /* private fields */ }
Expand description
Oracle-specific collection data type
This type corresponds to varray and nested table data types. See Oracle manual.
let conn = Connection::connect("scott", "tiger", "")?;
// MDSYS.SDO_ELEM_INFO_ARRAY is defined as VARRAY (1048576) of NUMBER.
let objtype = conn.object_type("MDSYS.SDO_ELEM_INFO_ARRAY")?;
// Create a new collection
let mut obj = objtype.new_collection()?;
obj.push(&1);
obj.push(&3);
assert_eq!(obj.to_string(), "MDSYS.SDO_ELEM_INFO_ARRAY(1, 3)");
Note: Methods in the type may be changed in future.
Implementations§
Source§impl Collection
impl Collection
Sourcepub fn object_type(&self) -> &ObjectType
pub fn object_type(&self) -> &ObjectType
Returns type information.
Sourcepub fn size(&self) -> Result<i32>
pub fn size(&self) -> Result<i32>
Returns the number of elements.
This counts also deleted elements. See “Comments” about OCICollSize().
Sourcepub fn iter<T>(&self) -> Iter<'_, T> ⓘwhere
T: FromSql,
pub fn iter<T>(&self) -> Iter<'_, T> ⓘwhere
T: FromSql,
Returns an iterator visiting all values with indices in the collection.
// Creates VARRAY type and gets the type information
conn.execute("create or replace type string_varray is varray(20) of varchar2(60)", &[])?;
let objtype = conn.object_type("STRING_VARRAY")?;
// Creates a VARRAY instance and appends three elements.
let mut coll = objtype.new_collection()?;
coll.push(&"First Element")?;
coll.push(&"Second Element")?;
coll.push(&"Third Element")?;
let vec = coll
.iter::<String>() // iterator returning Result<(i32, String)>
.collect::<Result<Vec<_>>>()?;
assert_eq!(vec[0], (0, "First Element".to_string()));
assert_eq!(vec[1], (1, "Second Element".to_string()));
assert_eq!(vec[2], (2, "Third Element".to_string()));
// Creates Table type and gets the type information
conn.execute("create or replace type string_table is table of varchar2(60)", &[])?;
let objtype = conn.object_type("STRING_TABLE")?;
// Creates a TABLE instance, appends four elements and makes a hole.
let mut coll = objtype.new_collection()?;
coll.push(&"First Element")?;
coll.push(&"Second Element")?;
coll.push(&"Third Element")?;
coll.push(&"Fourth Element")?;
coll.remove(2)?; // Remove "Third Element"
// iterator returning Result<(i32, String)>
let mut iter = coll.iter::<String>();
assert_eq!(iter.next().unwrap()?, (0, "First Element".to_string()));
assert_eq!(iter.next().unwrap()?, (1, "Second Element".to_string()));
assert_eq!(iter.next().unwrap()?, (3, "Fourth Element".to_string()));
assert!(iter.next().is_none());
Sourcepub fn indices(&self) -> Indices<'_> ⓘ
pub fn indices(&self) -> Indices<'_> ⓘ
Returns an iterator visiting all indices in the collection.
// Creates Table type and gets the type information
conn.execute("create or replace type string_table is table of varchar2(60)", &[])?;
let objtype = conn.object_type("STRING_TABLE")?;
// Creates a TABLE instance, appends four elements and makes a hole.
let mut coll = objtype.new_collection()?;
coll.push(&"First Element")?; // index 0
coll.push(&"Second Element")?; // index 1
coll.push(&"Third Element")?; // index 2
coll.push(&"Fourth Element")?; // index 3
coll.remove(2)?; // remote index 2
// coll's indices are 0, 1 and 3.
let mut indices = coll.indices();
assert_eq!(indices.next().unwrap().unwrap(), 0);
assert_eq!(indices.next().unwrap().unwrap(), 1);
assert_eq!(indices.next().unwrap().unwrap(), 3);
assert!(indices.next().is_none());
Sourcepub fn values<T>(&self) -> Values<'_, T> ⓘwhere
T: FromSql,
pub fn values<T>(&self) -> Values<'_, T> ⓘwhere
T: FromSql,
Returns an iterator visiting all values in the collection.
// Creates VARRAY type and gets the type information
conn.execute("create or replace type string_varray3 is varray(20) of varchar2(60)", &[])?;
let objtype = conn.object_type("STRING_VARRAY3")?;
// Creates a VARRAY instance and appends three elements.
let mut coll = objtype.new_collection()?;
coll.push(&"First Element");
coll.push(&"Second Element");
coll.push(&"Third Element");
let mut iter = coll.values::<String>();
assert_eq!(iter.next().unwrap()?, "First Element".to_string());
assert_eq!(iter.next().unwrap()?, "Second Element".to_string());
assert_eq!(iter.next().unwrap()?, "Third Element".to_string());
assert!(iter.next().is_none());
Sourcepub fn first_index(&self) -> Result<i32>
pub fn first_index(&self) -> Result<i32>
Returns the first index.
Use this method if indexes of the collection isn’t continuous.
Sourcepub fn last_index(&self) -> Result<i32>
pub fn last_index(&self) -> Result<i32>
Returns the last index.
Use this method if indexes of the collection isn’t continuous.
Sourcepub fn next_index(&self, index: i32) -> Result<i32>
pub fn next_index(&self, index: i32) -> Result<i32>
Returns the next index following the specified index.
Use this method if indexes of the collection isn’t continuous.
Sourcepub fn prev_index(&self, index: i32) -> Result<i32>
pub fn prev_index(&self, index: i32) -> Result<i32>
Returns the previous index following the specified index.
Use this method if indexes of the collection isn’t continuous.
Sourcepub fn exist(&self, index: i32) -> Result<bool>
pub fn exist(&self, index: i32) -> Result<bool>
Returns whether an element exists at the specified index.
Sourcepub fn get<T>(&self, index: i32) -> Result<T>where
T: FromSql,
pub fn get<T>(&self, index: i32) -> Result<T>where
T: FromSql,
Returns the value of the element at the specified index.
Sourcepub fn set(&mut self, index: i32, value: &dyn ToSql) -> Result<()>
pub fn set(&mut self, index: i32, value: &dyn ToSql) -> Result<()>
Sets the value to the element at the specified index.
Sourcepub fn push(&mut self, value: &dyn ToSql) -> Result<()>
pub fn push(&mut self, value: &dyn ToSql) -> Result<()>
Appends an element to the end of the collection.
Trait Implementations§
Source§impl Clone for Collection
impl Clone for Collection
Source§fn clone(&self) -> Collection
fn clone(&self) -> Collection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more