feat: add mysql svr

This commit is contained in:
2021-02-17 12:01:37 +08:00
parent 4c5ee6f908
commit ed41681faf
4 changed files with 1420 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
use std::io;
use msql_srv::*;
pub struct Backend;
impl<W: io::Write> MysqlShim<W> for Backend {
type Error = io::Error;
fn on_prepare(&mut self, query: &str, info: StatementMetaWriter<W>) -> io::Result<()> {
println!("Backend on prepare, query: {}", query);
info.reply(42, &[], &[])
}
fn on_execute(&mut self, id: u32, _params: ParamParser, results: QueryResultWriter<W>, ) -> io::Result<()> {
println!("Backend on execute, id: {}", id);
results.completed(0, 0)
}
fn on_close(&mut self, stmt: u32) {
println!("Backend on close, stmt: {}", stmt);
}
fn on_init(&mut self, _unknown: &str, _writer: InitWriter<W>) -> io::Result<()> {
println!("Backend on init, param2: {}", _unknown);
Ok(())
}
fn on_query(&mut self, query: &str, results: QueryResultWriter<W>) -> io::Result<()> {
println!("Backend on query, query: {}", query);
let cols = [
Column {
table: "foo".to_string(),
column: "a".to_string(),
coltype: ColumnType::MYSQL_TYPE_LONGLONG,
colflags: ColumnFlags::empty(),
},
Column {
table: "foo".to_string(),
column: "b".to_string(),
coltype: ColumnType::MYSQL_TYPE_STRING,
colflags: ColumnFlags::empty(),
},
];
let mut rw = results.start(&cols)?;
rw.write_col(42)?;
rw.write_col("b's value")?;
rw.finish()
}
}