### Get SQLite Extension Version using xl_version Source: https://context7.com/asg017/sqlite-xl/llms.txt Demonstrates how to retrieve the version of the sqlite-xl extension using the scalar function `xl_version`. This function returns a string representing the current version of the loaded extension, which can be useful for compatibility checks or logging. ```sql -- Load the extension .load target/debug/libsqlite_xl sqlite3_xl_init -- Get the extension version SELECT xl_version(); -- Output: -- ┌────────────┐ -- │ xl_version │ -- ├────────────┤ -- │ 0.1.0 │ -- └────────────┘ ``` -------------------------------- ### Get Extension Version with xl_version (SQL) Source: https://context7.com/asg017/sqlite-xl/llms.txt The `xl_version` function returns the current version of the sqlite-xl extension as a string, prefixed with 'v'. This is useful for debugging and ensuring version compatibility. ```sql -- Load the extension .load target/debug/libsqlite_xl sqlite3_xl_init -- Get the extension version SELECT xl_version(); -- Output: v0.0.1-alpha.4 ``` -------------------------------- ### xl_version - Get Extension Version Source: https://context7.com/asg017/sqlite-xl/llms.txt The `xl_version` scalar function returns the current version of the sqlite-xl extension as a string, prefixed with 'v'. This is useful for debugging and compatibility checks. ```APIDOC ## xl_version - Get Extension Version ### Description Returns the current version of the sqlite-xl extension as a string, prefixed with 'v'. Useful for debugging and ensuring compatibility. ### Method SQL Scalar Function ### Endpoint N/A (SQL Function) ### Parameters None ### Request Example ```sql SELECT xl_version(); ``` ### Response #### Success Response - **version** (text) - The version string of the sqlite-xl extension (e.g., 'v0.0.1-alpha.4'). ``` -------------------------------- ### Query Individual Cells by Range using xl_cells Source: https://context7.com/asg017/sqlite-xl/llms.txt Shows how to use the `xl_cells` table-valued function to extract individual cell data from a specified range (e.g., 'A1:Z100') within a spreadsheet. The function returns the row number, column number, and the cell's value, automatically converting it to appropriate SQLite data types. Examples include querying specific ranges and aggregating cell values into JSON. ```sql -- Load the extension .load target/debug/libsqlite_xl sqlite3_xl_init -- Query cells in a specific range SELECT row, column, value FROM xl_cells( readfile('My Workbook.xlsx'), 'A1:Z100' ); -- Query header row cells (row 3, columns I through ZZ) SELECT row, column, value FROM xl_cells( readfile('election_data.xls'), 'I3:ZZ3' ) LIMIT 10; -- Aggregate cell values as JSON SELECT json_group_array(value) as candidates FROM xl_cells( readfile('My Workbook.xlsx'), 'I3:Z3' ); ``` -------------------------------- ### Initialize and Query Excel with SQLite (JavaScript) Source: https://github.com/asg017/sqlite-xl/blob/main/site/index.html This JavaScript code snippet initializes the sqlite3 module and attaches an Excel file for querying. It fetches the Excel file as an ArrayBuffer, prepares a statement binding function, and uses the `attach` function to define the queryable Excel data. ```javascript import {attach} from "./slim.js"; import {default as init} from "./sqlite3.mjs"; const sampleXlsx = await fetch('file-sample.xlsx').then(r => r.arrayBuffer()); console.log(sampleXlsx); const sqlite3 = await init(); function prepareStatement(stmt) { if (stmt.getParamIndex(":sample_xlsx") !== undefined) { stmt.bind({ ":sample_xlsx": sampleXlsx }); } sampleXlsx; } attach({ target: document.body.querySelector('#target'), sqlite3, prepareStatement, initialCode: `select rowid, xl_at(row, 0), xl_at(row, 1), xl_at(row, 2), xl_at(row, 3), xl_at(row, 4) from xl_rows(:sample_xlsx) limit 10; `, }); ``` -------------------------------- ### Create Virtual Table from Spreadsheet using xl0 Source: https://github.com/asg017/sqlite-xl/blob/main/README.md Shows how to create a virtual table in SQLite that maps directly to a spreadsheet file using the `xl0` extension. This allows standard SQL queries against the spreadsheet data. ```sql create virtual table temp.my_table using xl0('My Workbook.xlsx'); select A, B, C from temp.my_table; ``` -------------------------------- ### Query Cells from Spreadsheet using xl_cells Source: https://github.com/asg017/sqlite-xl/blob/main/README.md Demonstrates how to use the `xl_cells` function to read specific cell ranges from a spreadsheet file. This function takes the file content and a cell range as input, returning rows with address and value. ```sql select address, value from xl_cells( readfile('My Workbook.xlsx'), 'A1:Z100' ); ``` -------------------------------- ### Load sqlite-xl Extension and List Worksheets Source: https://context7.com/asg017/sqlite-xl/llms.txt Demonstrates how to load the sqlite-xl extension into SQLite and use the `xl_sheets` function to retrieve the names and visibility status of all worksheets within a given spreadsheet file. The `readfile` function is used to pass the workbook's binary content to the extension. ```sql -- Load the extension .load target/debug/libsqlite_xl sqlite3_xl_init -- List all sheets in a workbook SELECT name, visible FROM xl_sheets(readfile('My Workbook.xlsx')); -- Get sheet names as a JSON array SELECT json_group_array(name) as sheet_names FROM xl_sheets(readfile('My Workbook.xlsx')); ``` -------------------------------- ### Iterate Over Spreadsheet Rows using xl_rows and xl_at Source: https://context7.com/asg017/sqlite-xl/llms.txt Illustrates the use of the `xl_rows` table-valued function to iterate over rows in a spreadsheet, providing a `row_number` and a `row` pointer. The `xl_at` function or the `->>` operator can then be used to access individual cell values within each row by column index or letter. This is efficient for bulk data import and transformation. ```sql -- Load the extension .load target/debug/libsqlite_xl sqlite3_xl_init -- Query rows from a spreadsheet SELECT row_number, row FROM xl_rows(readfile('file-sample.xlsx')); -- Extract specific columns using xl_at with column index SELECT xl_at(row, 0) as column_a, xl_at(row, 1) as column_b, xl_at(row, 2) as column_c FROM xl_rows(readfile('My Workbook.xlsx')); -- Use the ->> operator with column letters for more readable queries SELECT row ->> 'A' as student_name, row ->> 'B' as student_age, row ->> 'C' as grade FROM xl_rows( readfile('My Workbook.xlsx'), 'Students!A2:F' ); -- Create a table from spreadsheet data for further analysis CREATE TABLE imported_data AS SELECT xl_at(row, 0) as A, xl_at(row, 1) as B, xl_at(row, 2) as C, xl_at(row, 3) as D, xl_at(row, 4) as E FROM xl_rows(readfile('file.xlsx')); SELECT count(*) FROM imported_data; SELECT max(A) FROM imported_data; ``` -------------------------------- ### Query Rows from Spreadsheet using xl_rows Source: https://github.com/asg017/sqlite-xl/blob/main/README.md Illustrates the usage of the `xl_rows` function to iterate over rows in a specified sheet and range. It allows accessing columns by their letter (e.g., 'A', 'B') using JSON operators. ```sql select row ->> 'A' as student_name, row ->> 'B' as student_age, row ->> 'C' as grade from xl_rows( readfile('My Workbook.xlsx'), 'Students!A2:F' ); ``` -------------------------------- ### Extract Column Value with xl_at (SQL) Source: https://context7.com/asg017/sqlite-xl/llms.txt The `xl_at` function extracts a column's value from a row pointer. It supports zero-based numeric indices or case-insensitive column letters. This function handles various spreadsheet data types and converts them to SQLite-compatible formats. ```sql -- Load the extension .load target/debug/libsqlite_xl sqlite3_xl_init -- Extract column by numeric index (0-based) SELECT xl_at(row, 0) as first_column, xl_at(row, 1) as second_column, xl_at(row, 25) as column_z FROM xl_rows(readfile('data.xlsx')); -- Extract column by letter (case-insensitive) SELECT xl_at(row, 'A') as column_a, xl_at(row, 'B') as column_b, xl_at(row, 'AA') as column_aa FROM xl_rows(readfile('data.xlsx')); -- Mix both approaches SELECT xl_at(row, 0) as id, xl_at(row, 'B') as name, xl_at(row, 2) as value FROM xl_rows(readfile('data.xlsx')) WHERE xl_at(row, 0) IS NOT NULL; ``` -------------------------------- ### xl_at - Extract Column Value from Row Source: https://context7.com/asg017/sqlite-xl/llms.txt The `xl_at` scalar function extracts a specific column value from a row pointer. It supports extraction by zero-based numeric index or column letter (case-insensitive) and handles various spreadsheet data types. ```APIDOC ## xl_at - Extract Column Value from Row ### Description Extracts a specific column value from a row pointer returned by `xl_rows`. Supports zero-based numeric index or column letter (case-insensitive). Handles all spreadsheet data types and converts them to appropriate SQLite values. ### Method SQL Scalar Function ### Endpoint N/A (SQL Function) ### Parameters #### Arguments - **row_pointer** (pointer) - Required - The row pointer returned by `xl_rows`. - **column_identifier** (integer or text) - Required - The zero-based numeric index or column letter (e.g., 0, 1, 'A', 'B', 'AA') of the column to extract. ### Request Example ```sql -- Extract column by numeric index (0-based) SELECT xl_at(row, 0) as first_column FROM xl_rows(readfile('data.xlsx')); -- Extract column by letter (case-insensitive) SELECT xl_at(row, 'A') as column_a FROM xl_rows(readfile('data.xlsx')); -- Mix both approaches SELECT xl_at(row, 0) as id, xl_at(row, 'B') as name FROM xl_rows(readfile('data.xlsx')); ``` ### Response #### Success Response - **column_value** (any) - The extracted value from the specified column, converted to an appropriate SQLite data type (integer, float, text, boolean, datetime, duration, null). ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.