-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#[cfg(feature="bigdecimal")] | ||
pub mod bigdecimal { | ||
extern crate bigdecimal; | ||
|
||
use std::error::Error; | ||
use std::io::prelude::*; | ||
|
||
use mysql::{Mysql, MysqlType}; | ||
|
||
use self::bigdecimal::BigDecimal; | ||
|
||
use types::{self, FromSql, ToSql, ToSqlOutput, IsNull, HasSqlType}; | ||
|
||
impl ToSql<types::Numeric, Mysql> for BigDecimal { | ||
fn to_sql<W: Write>(&self, out: &mut ToSqlOutput<W, Mysql>) -> Result<IsNull, Box<Error+Send+Sync>> { | ||
write!(out, "{}", *self) | ||
.map(|_| IsNull::No) | ||
.map_err(|e| e.into()) | ||
} | ||
} | ||
|
||
impl FromSql<types::Numeric, Mysql> for BigDecimal { | ||
fn from_sql(bytes: Option<&[u8]>) -> Result<Self, Box<Error+Send+Sync>> { | ||
let bytes = not_none!(bytes); | ||
BigDecimal::parse_bytes(bytes, 10) | ||
.ok_or_else(|| Box::from(format!("{:?} is not valid decimal number ", bytes))) | ||
} | ||
} | ||
|
||
impl HasSqlType<BigDecimal> for Mysql { | ||
fn metadata(_: &()) -> MysqlType { | ||
MysqlType::String | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters