Not able to use exported c function as custom function in query
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, sqlite, wasm
Hướng nghiên cứu
Start with exporting-c-function.js and its create_function call, then compare the alternate_case.c export and compiled alternate_case.js with the sql-wasm.js integration. Reproduce SELECT altcase(b) after database initialization and inspect the custom-function and web-worker entry points mentioned in the report. Done means the function accepts the selected column argument and the worker usage has a clear, working path.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I wrote a c function and compiled using the command
emcc lib/alternate_case.c -s WASM=1 -s EXPORTED_FUNCTIONS="['_alternatecase']" -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -s ASSERTIONS=1 -o public/alternate_case.js
Here is my C function
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<emscripten.h>
int main() {
return 1;
}
char * alternatecase(char *str) {
char *initial_ptr;
initial_ptr = str;
for (int i=0; i < *str!='\0' ; i++){
if( (i % 2) == 0)
*str = tolower(*str);
else
*str = toupper(*str);
str++;
}
return initial_ptr;
}
Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first Web Assembly Demo</title>
</head>
<body>
<h1> MY first web assembly demo</h1>
Output is in Javascript console
<main>
<button id="execute" class="button">Execute</button>
<pre id="output"> Results will be displayed here </pre>
</main>
</body>
<script src='/dist/sql-wasm.js'></script>
<script src='alternate_case.js'></script>
<script type="text/javascript" src="exporting-c-function.js"></script>
</html>
I took the sql-wasm.js from this repository. alternate_case.js is the compiled file from emcc.
This is the exporting-c-function.js
config = {
locateFile: filename => `dist/sql-wasm.wasm`
}
initSqlJs(config).then(function(SQL){
//Create the database
var db = new SQL.Database();
// Run a query without reading the results
const func = cwrap('alternatecase','string', ['string']);
db.create_function("altcase" , func)
sqlstr = "CREATE TABLE hello (a int, b char);";
sqlstr += "INSERT INTO hello VALUES (0, 'hello');"
sqlstr += "INSERT INTO hello VALUES (1, 'world');"
db.run(sqlstr); // Run the query without returning anything
//db.run("INSERT INTO hello VALUES (alternatecase('awdqwdq'));"); // Inserts 10 and 'Hello world'
db.run('SELECT altcase(b) from hello;');
});
It is throwing this error in the console
Error: wrong number of arguments to function altcase()
And it accepts only 0 arguments.
Note: if I try from browser console , I am able to use the function and get the output.
How to use this as custom function?
Also how to create custom function in web workers and use it ?
- Ngôn ngữ chính
- JavaScript
- Star
- 13.7k
- Fork
- 1.1k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của sql-js/sql.js
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Add the WebWorker API docs Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Tất cả issue của sql-js/sql.js
Issue tương tự
-
code-quality refactoring
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100