-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement Sqlite3 Module #4260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Sqlite3 Module #4260
Conversation
0a7f6fe
to
8bebe38
Compare
@youknowone Can you help with that compilation fail with android? |
that looks like a toolchain problem. rather than fighting with it, how about just disabling sqlite3 for android? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! You made a huge work!
let guard = self.db.lock(); | ||
if guard.is_some() { | ||
Ok(PyMutexGuard::map(guard, |x| unsafe { | ||
x.as_mut().unwrap_unchecked() | ||
})) | ||
} else { | ||
Err(new_programming_error( | ||
vm, | ||
"Cannot operate on a closed database.".to_owned(), | ||
)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let guard = self.db.lock(); | |
if guard.is_some() { | |
Ok(PyMutexGuard::map(guard, |x| unsafe { | |
x.as_mut().unwrap_unchecked() | |
})) | |
} else { | |
Err(new_programming_error( | |
vm, | |
"Cannot operate on a closed database.".to_owned(), | |
)) | |
} | |
let Some(guard) = self.db.lock() else { | |
return Err(new_programming_error( | |
vm, | |
"Cannot operate on a closed database.".to_owned(), | |
)); | |
}; | |
Ok(PyMutexGuard::map(guard, |x| unsafe { | |
x.as_mut().unwrap_unchecked() | |
})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not going to work as the variable guard is MutexGuard<Option<_>>
stdlib/src/sqlite.rs
Outdated
unsafe { | ||
sqlite3_create_collation_v2(db.db, name.as_ptr(), SQLITE_UTF8, null_mut(), None, None); | ||
return Ok(()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe { | |
sqlite3_create_collation_v2(db.db, name.as_ptr(), SQLITE_UTF8, null_mut(), None, None); | |
return Ok(()); | |
} | |
unsafe { | |
sqlite3_create_collation_v2(db.db, name.as_ptr(), SQLITE_UTF8, null_mut(), None, None); | |
} | |
return Ok(()); |
later code's unsafe blocks don't contain return Ok(())
but this one does.
let guard = self.inner.lock(); | ||
if guard.is_some() { | ||
Ok(PyMutexGuard::map(guard, |x| unsafe { | ||
x.as_mut().unwrap_unchecked() | ||
})) | ||
} else { | ||
Err(new_programming_error( | ||
vm, | ||
"Cannot operate on a closed cursor.".to_owned(), | ||
)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let guard = self.inner.lock(); | |
if guard.is_some() { | |
Ok(PyMutexGuard::map(guard, |x| unsafe { | |
x.as_mut().unwrap_unchecked() | |
})) | |
} else { | |
Err(new_programming_error( | |
vm, | |
"Cannot operate on a closed cursor.".to_owned(), | |
)) | |
} | |
let Some(guard) = self.inner.lock() else { | |
return Err(new_programming_error( | |
vm, | |
"Cannot operate on a closed cursor.".to_owned(), | |
)); | |
}; | |
Ok(PyMutexGuard::map(guard, |x| unsafe { | |
x.as_mut().unwrap_unchecked() | |
})) |
} | ||
|
||
fn inner(&self, vm: &VirtualMachine) -> PyResult<PyMappedMutexGuard<BlobInner>> { | ||
let guard = self.inner.lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let-else for guard here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do let-else on a MutexGuard
?
closes #3983