Comments (3)
Use Option<ToSql>
.
let mut stmt = conn
.statement("insert into employees values (:name, :salary)")
.build()?;
stmt.execute_named(&[("name", &"Allen"), ("salary", &None::<i32>)])?;
let employees: [(&str, Option<i32>); 3] = [
("Jones", Some(7566)),
("Martin", Some(7654)),
("Blake", None),
];
for emp in &employees {
stmt.execute_named(&[("name", &emp.0), ("salary", &emp.1)])?;
}
from rust-oracle.
Ok, thanks, should the type always match the column type when setting null values?
Suppose I have a table like this:
CREATE TABLE test (id INT PRIMARY KEY, ival INT, sval VARCHAR(100));
If I need to set ival and sval as null do I need to set the Option type as i32 and str like this?
let mut stmt = conn
.statement("insert into test (id, ival, sval) values (:id, :ival, :sval)")
.build()?;
stmt.execute_named(&[("id", &1), ("ival", &None::<i32>), ("sval", &None::<str>)])?;
Are columns types checked?
Thanks,
Frank
from rust-oracle.
Ok, thanks, should the type always match the column type when setting null values?
Not always. For column types (number, date, timestamp, interval, ...) supporting implicit type conversion from string, &None::<&str>
is available. For other column types (object, collection), the type must match the column type.
from rust-oracle.
Related Issues (20)
- Working with Oracle Advance Queues HOT 4
- Error with oracle round function HOT 1
- Request cancellation HOT 1
- use semantic versioning & follow changelog standards HOT 2
- add build matrix to CI with optional features
- Any reason SqlValues are .dup_by_handle()'d on retrieving a row? HOT 3
- VARRAY HOT 2
- Problems with loading large clob values via returning clauses HOT 2
- Any idea why I'm getting `DPI Error: DPI-1080: connection was closed by ORA-3156` HOT 3
- Usage with asynchronous code problem - how to shut down `.connect()` call that hangs indefinitely HOT 6
- How to change the value of "oracleClientLibDir" in dpiContextCreateParams struct HOT 3
- API to upload file as BLOB without preallocation HOT 3
- Question - async/await stream to many users using just 1 thread HOT 2
- the `?` operator can only be used in a function that returns `Result` or `Option` HOT 1
- QUESTION the trait `ToSql` is not implemented for `SqlValue`
- Question - Calling Oracle Stored Procedures Example HOT 3
- Convert recordset to Vec of Columns HOT 1
- Question - Alter Sessions HOT 1
- A way to set path for oracle instant client HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-oracle.