@@ -16,25 +16,19 @@ pub struct InnerConnection {
1616 owned : bool ,
1717}
1818
19- impl Clone for InnerConnection {
20- fn clone ( & self ) -> Self {
21- unsafe { InnerConnection :: new ( self . db , false ) }
22- }
23- }
24-
2519impl InnerConnection {
26- #[ allow( clippy:: mutex_atomic) ]
2720 #[ inline]
28- pub unsafe fn new ( db : ffi:: duckdb_database , owned : bool ) -> InnerConnection {
21+ pub unsafe fn new ( db : ffi:: duckdb_database , owned : bool ) -> Result < InnerConnection > {
2922 let mut con: ffi:: duckdb_connection = ptr:: null_mut ( ) ;
3023 let r = ffi:: duckdb_connect ( db, & mut con) ;
3124 if r != ffi:: DuckDBSuccess {
3225 ffi:: duckdb_disconnect ( & mut con) ;
33- let e = Error :: DuckDBFailure ( ffi:: Error :: new ( r) , Some ( "connect error" . to_owned ( ) ) ) ;
34- // TODO: fix this
35- panic ! ( "error {:?}" , e) ;
26+ return Err ( Error :: DuckDBFailure (
27+ ffi:: Error :: new ( r) ,
28+ Some ( "connect error" . to_owned ( ) ) ,
29+ ) ) ;
3630 }
37- InnerConnection { db, con, owned }
31+ Ok ( InnerConnection { db, con, owned } )
3832 }
3933
4034 pub fn open_with_flags ( c_path : & CStr , config : Config ) -> Result < InnerConnection > {
@@ -47,11 +41,10 @@ impl InnerConnection {
4741 ffi:: duckdb_free ( c_err as * mut c_void ) ;
4842 return Err ( Error :: DuckDBFailure ( ffi:: Error :: new ( r as u32 ) , msg) ) ;
4943 }
50- Ok ( InnerConnection :: new ( db, true ) )
44+ InnerConnection :: new ( db, true )
5145 }
5246 }
5347
54- #[ allow( clippy:: mutex_atomic) ]
5548 pub fn close ( & mut self ) -> Result < ( ) > {
5649 if self . db . is_null ( ) {
5750 return Ok ( ( ) ) ;
@@ -71,6 +64,11 @@ impl InnerConnection {
7164 Ok ( ( ) )
7265 }
7366
67+ /// Creates a new connection to the already-opened database.
68+ pub fn try_clone ( & self ) -> Result < Self > {
69+ unsafe { InnerConnection :: new ( self . db , false ) }
70+ }
71+
7472 pub fn execute ( & mut self , sql : & str ) -> Result < ( ) > {
7573 let c_str = CString :: new ( sql) . unwrap ( ) ;
7674 unsafe {
@@ -106,12 +104,6 @@ impl InnerConnection {
106104 Ok ( Appender :: new ( conn, c_app) )
107105 }
108106
109- #[ inline]
110- #[ allow( dead_code) ]
111- pub fn changes ( & mut self ) -> usize {
112- panic ! ( "changes: not supported" )
113- }
114-
115107 #[ inline]
116108 pub fn is_autocommit ( & self ) -> bool {
117109 true
0 commit comments