| 1 |
use sqlx::error::DatabaseError; |
| 2 |
use sqlx::sqlite::{SqliteConnectOptions, SqliteError}; |
| 3 |
use sqlx::ConnectOptions; |
| 4 |
use sqlx::TypeInfo; |
| 5 |
use sqlx::{sqlite::Sqlite, Column, Executor}; |
| 6 |
use sqlx_test::new; |
| 7 |
use std::env; |
| 8 |
|
| 9 |
#[sqlx_macros::test] |
| 10 |
async fn it_describes_simple() -> anyhow::Result<()> { |
| 11 |
let mut conn = new::<Sqlite>().await?; |
| 12 |
|
| 13 |
let info = conn.describe("SELECT * FROM tweet").await?; |
| 14 |
let columns = info.columns(); |
| 15 |
|
| 16 |
assert_eq!(columns[0].name(), "id"); |
| 17 |
assert_eq!(columns[1].name(), "text"); |
| 18 |
assert_eq!(columns[2].name(), "is_sent"); |
| 19 |
assert_eq!(columns[3].name(), "owner_id"); |
| 20 |
|
| 21 |
assert_eq!(columns[0].ordinal(), 0); |
| 22 |
assert_eq!(columns[1].ordinal(), 1); |
| 23 |
assert_eq!(columns[2].ordinal(), 2); |
| 24 |
assert_eq!(columns[3].ordinal(), 3); |
| 25 |
|
| 26 |
assert_eq!(info.nullable(0), Some(false)); |
| 27 |
assert_eq!(info.nullable(1), Some(false)); |
| 28 |
assert_eq!(info.nullable(2), Some(false)); |
| 29 |
assert_eq!(info.nullable(3), Some(true)); |
| 30 |
|
| 31 |
assert_eq!(columns[0].type_info().name(), "INTEGER"); |
| 32 |
assert_eq!(columns[1].type_info().name(), "TEXT"); |
| 33 |
assert_eq!(columns[2].type_info().name(), "BOOLEAN"); |
| 34 |
assert_eq!(columns[3].type_info().name(), "INTEGER"); |
| 35 |
|
| 36 |
Ok(()) |
| 37 |
} |
| 38 |
|
| 39 |
#[sqlx_macros::test] |
| 40 |
async fn it_describes_variables() -> anyhow::Result<()> { |
| 41 |
let mut conn = new::<Sqlite>().await?; |
| 42 |
|
| 43 |
|
| 44 |
let info = conn.describe("SELECT ?1").await?; |
| 45 |
|
| 46 |
assert_eq!(info.columns()[0].type_info().name(), "NULL"); |
| 47 |
assert_eq!(info.nullable(0), Some(true)); |
| 48 |
|
| 49 |
|
| 50 |
let info = conn.describe("SELECT CAST(?1 AS REAL)").await?; |
| 51 |
|
| 52 |
assert_eq!(info.columns()[0].type_info().name(), "REAL"); |
| 53 |
assert_eq!(info.nullable(0), Some(true)); |
| 54 |
|
| 55 |
Ok(()) |
| 56 |
} |
| 57 |
|
| 58 |
#[sqlx_macros::test] |
| 59 |
async fn it_describes_expression() -> anyhow::Result<()> { |
| 60 |
let mut conn = new::<Sqlite>().await?; |
| 61 |
|
| 62 |
let d = conn |
| 63 |
.describe("SELECT 1 + 10, 5.12 * 2, 'Hello', x'deadbeef', null") |
| 64 |
.await?; |
| 65 |
|
| 66 |
let columns = d.columns(); |
| 67 |
|
| 68 |
assert_eq!(columns[0].type_info().name(), "INTEGER"); |
| 69 |
assert_eq!(columns[0].name(), "1 + 10"); |
| 70 |
assert_eq!(d.nullable(0), Some(false)); |
| 71 |
|
| 72 |
assert_eq!(columns[1].type_info().name(), "REAL"); |
| 73 |
assert_eq!(columns[1].name(), "5.12 * 2"); |
| 74 |
assert_eq!(d.nullable(1), Some(false)); |
| 75 |
|
| 76 |
assert_eq!(columns[2].type_info().name(), "TEXT"); |
| 77 |
assert_eq!(columns[2].name(), "'Hello'"); |
| 78 |
assert_eq!(d.nullable(2), Some(false)); |
| 79 |
|
| 80 |
assert_eq!(columns[3].type_info().name(), "BLOB"); |
| 81 |
assert_eq!(columns[3].name(), "x'deadbeef'"); |
| 82 |
assert_eq!(d.nullable(3), Some(false)); |
| 83 |
|
| 84 |
assert_eq!(columns[4].type_info().name(), "NULL"); |
| 85 |
assert_eq!(columns[4].name(), "null"); |
| 86 |
assert_eq!(d.nullable(4), Some(true)); |
| 87 |
|
| 88 |
Ok(()) |
| 89 |
} |
| 90 |
|
| 91 |
#[sqlx_macros::test] |
| 92 |
async fn it_describes_temporary_table() -> anyhow::Result<()> { |
| 93 |
let mut conn = new::<Sqlite>().await?; |
| 94 |
|
| 95 |
conn.execute( |
| 96 |
"CREATE TEMPORARY TABLE IF NOT EXISTS empty_all_types_and_nulls( |
| 97 |
i1 integer NULL, |
| 98 |
r1 real NULL, |
| 99 |
t1 text NULL, |
| 100 |
b1 blob NULL, |
| 101 |
i2 INTEGER NOT NULL, |
| 102 |
r2 REAL NOT NULL, |
| 103 |
t2 TEXT NOT NULL, |
| 104 |
b2 BLOB NOT NULL |
| 105 |
)", |
| 106 |
) |
| 107 |
.await?; |
| 108 |
|
| 109 |
let d = conn |
| 110 |
.describe("SELECT * FROM empty_all_types_and_nulls") |
| 111 |
.await?; |
| 112 |
assert_eq!(d.columns().len(), 8); |
| 113 |
|
| 114 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 115 |
assert_eq!(d.nullable(0), Some(true)); |
| 116 |
|
| 117 |
assert_eq!(d.column(1).type_info().name(), "REAL"); |
| 118 |
assert_eq!(d.nullable(1), Some(true)); |
| 119 |
|
| 120 |
assert_eq!(d.column(2).type_info().name(), "TEXT"); |
| 121 |
assert_eq!(d.nullable(2), Some(true)); |
| 122 |
|
| 123 |
assert_eq!(d.column(3).type_info().name(), "BLOB"); |
| 124 |
assert_eq!(d.nullable(3), Some(true)); |
| 125 |
|
| 126 |
assert_eq!(d.column(4).type_info().name(), "INTEGER"); |
| 127 |
assert_eq!(d.nullable(4), Some(false)); |
| 128 |
|
| 129 |
assert_eq!(d.column(5).type_info().name(), "REAL"); |
| 130 |
assert_eq!(d.nullable(5), Some(false)); |
| 131 |
|
| 132 |
assert_eq!(d.column(6).type_info().name(), "TEXT"); |
| 133 |
assert_eq!(d.nullable(6), Some(false)); |
| 134 |
|
| 135 |
assert_eq!(d.column(7).type_info().name(), "BLOB"); |
| 136 |
assert_eq!(d.nullable(7), Some(false)); |
| 137 |
|
| 138 |
Ok(()) |
| 139 |
} |
| 140 |
|
| 141 |
#[sqlx_macros::test] |
| 142 |
async fn it_describes_expression_from_empty_table() -> anyhow::Result<()> { |
| 143 |
let mut conn = new::<Sqlite>().await?; |
| 144 |
|
| 145 |
conn.execute("CREATE TEMP TABLE _temp_empty ( name TEXT NOT NULL, a INT )") |
| 146 |
.await?; |
| 147 |
|
| 148 |
let d = conn |
| 149 |
.describe("SELECT COUNT(*), a + 1, name, 5.12, 'Hello' FROM _temp_empty") |
| 150 |
.await?; |
| 151 |
|
| 152 |
assert_eq!(d.columns()[0].type_info().name(), "INTEGER"); |
| 153 |
assert_eq!(d.nullable(0), Some(false)); |
| 154 |
|
| 155 |
assert_eq!(d.columns()[1].type_info().name(), "INTEGER"); |
| 156 |
assert_eq!(d.nullable(1), Some(true)); |
| 157 |
|
| 158 |
assert_eq!(d.columns()[2].type_info().name(), "TEXT"); |
| 159 |
assert_eq!(d.nullable(2), Some(true)); |
| 160 |
|
| 161 |
assert_eq!(d.columns()[3].type_info().name(), "REAL"); |
| 162 |
assert_eq!(d.nullable(3), Some(false)); |
| 163 |
|
| 164 |
assert_eq!(d.columns()[4].type_info().name(), "TEXT"); |
| 165 |
assert_eq!(d.nullable(4), Some(false)); |
| 166 |
|
| 167 |
Ok(()) |
| 168 |
} |
| 169 |
|
| 170 |
#[sqlx_macros::test] |
| 171 |
async fn it_describes_expression_from_empty_table_with_star() -> anyhow::Result<()> { |
| 172 |
let mut conn = new::<Sqlite>().await?; |
| 173 |
|
| 174 |
conn.execute("CREATE TEMP TABLE _temp_empty ( name TEXT, a INT )") |
| 175 |
.await?; |
| 176 |
|
| 177 |
let d = conn |
| 178 |
.describe("SELECT *, 5, 'Hello' FROM _temp_empty") |
| 179 |
.await?; |
| 180 |
|
| 181 |
assert_eq!(d.columns()[0].type_info().name(), "TEXT"); |
| 182 |
assert_eq!(d.columns()[1].type_info().name(), "INTEGER"); |
| 183 |
assert_eq!(d.columns()[2].type_info().name(), "INTEGER"); |
| 184 |
assert_eq!(d.columns()[3].type_info().name(), "TEXT"); |
| 185 |
|
| 186 |
Ok(()) |
| 187 |
} |
| 188 |
|
| 189 |
#[sqlx_macros::test] |
| 190 |
async fn it_describes_insert() -> anyhow::Result<()> { |
| 191 |
let mut conn = new::<Sqlite>().await?; |
| 192 |
|
| 193 |
let d = conn |
| 194 |
.describe("INSERT INTO tweet (id, text) VALUES (2, 'Hello')") |
| 195 |
.await?; |
| 196 |
|
| 197 |
assert_eq!(d.columns().len(), 0); |
| 198 |
|
| 199 |
let d = conn |
| 200 |
.describe("INSERT INTO tweet (id, text) VALUES (2, 'Hello'); SELECT last_insert_rowid();") |
| 201 |
.await?; |
| 202 |
|
| 203 |
assert_eq!(d.columns().len(), 1); |
| 204 |
assert_eq!(d.columns()[0].type_info().name(), "INTEGER"); |
| 205 |
assert_eq!(d.nullable(0), Some(false)); |
| 206 |
|
| 207 |
Ok(()) |
| 208 |
} |
| 209 |
|
| 210 |
#[sqlx_macros::test] |
| 211 |
async fn it_describes_insert_with_read_only() -> anyhow::Result<()> { |
| 212 |
sqlx_test::setup_if_needed(); |
| 213 |
|
| 214 |
let mut options: SqliteConnectOptions = env::var("DATABASE_URL")?.parse().unwrap(); |
| 215 |
options = options.read_only(true); |
| 216 |
|
| 217 |
let mut conn = options.connect().await?; |
| 218 |
|
| 219 |
let d = conn |
| 220 |
.describe("INSERT INTO tweet (id, text) VALUES (2, 'Hello')") |
| 221 |
.await?; |
| 222 |
|
| 223 |
assert_eq!(d.columns().len(), 0); |
| 224 |
|
| 225 |
Ok(()) |
| 226 |
} |
| 227 |
|
| 228 |
#[sqlx_macros::test] |
| 229 |
async fn it_describes_insert_with_returning() -> anyhow::Result<()> { |
| 230 |
let mut conn = new::<Sqlite>().await?; |
| 231 |
|
| 232 |
let d = conn |
| 233 |
.describe("INSERT INTO tweet (id, text) VALUES (2, 'Hello') RETURNING *") |
| 234 |
.await?; |
| 235 |
|
| 236 |
assert_eq!(d.columns().len(), 4); |
| 237 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 238 |
assert_eq!(d.nullable(0), Some(false)); |
| 239 |
assert_eq!(d.column(1).type_info().name(), "TEXT"); |
| 240 |
assert_eq!(d.nullable(1), Some(false)); |
| 241 |
|
| 242 |
let d = conn |
| 243 |
.describe("INSERT INTO accounts (name, is_active) VALUES ('a', true) RETURNING id") |
| 244 |
.await?; |
| 245 |
|
| 246 |
assert_eq!(d.columns().len(), 1); |
| 247 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 248 |
assert_eq!(d.nullable(0), Some(false)); |
| 249 |
|
| 250 |
Ok(()) |
| 251 |
} |
| 252 |
|
| 253 |
#[sqlx_macros::test] |
| 254 |
async fn it_describes_bound_columns_non_null() -> anyhow::Result<()> { |
| 255 |
let mut conn = new::<Sqlite>().await?; |
| 256 |
let d = conn |
| 257 |
.describe("INSERT INTO tweet (id, text) VALUES ($1, $2) returning *") |
| 258 |
.await?; |
| 259 |
|
| 260 |
assert_eq!(d.columns().len(), 4); |
| 261 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 262 |
assert_eq!(d.nullable(0), Some(false)); |
| 263 |
assert_eq!(d.column(1).type_info().name(), "TEXT"); |
| 264 |
assert_eq!(d.nullable(1), Some(false)); |
| 265 |
|
| 266 |
Ok(()) |
| 267 |
} |
| 268 |
|
| 269 |
#[sqlx_macros::test] |
| 270 |
async fn it_describes_update_with_returning() -> anyhow::Result<()> { |
| 271 |
let mut conn = new::<Sqlite>().await?; |
| 272 |
|
| 273 |
let d = conn |
| 274 |
.describe("UPDATE accounts SET is_active=true WHERE name=?1 RETURNING id") |
| 275 |
.await?; |
| 276 |
|
| 277 |
assert_eq!(d.columns().len(), 1); |
| 278 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 279 |
assert_eq!(d.nullable(0), Some(false)); |
| 280 |
|
| 281 |
let d = conn |
| 282 |
.describe("UPDATE accounts SET is_active=true WHERE id=?1 RETURNING *") |
| 283 |
.await?; |
| 284 |
|
| 285 |
assert_eq!(d.columns().len(), 3); |
| 286 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 287 |
assert_eq!(d.nullable(0), Some(false)); |
| 288 |
assert_eq!(d.column(1).type_info().name(), "TEXT"); |
| 289 |
assert_eq!(d.nullable(1), Some(false)); |
| 290 |
assert_eq!(d.column(2).type_info().name(), "BOOLEAN"); |
| 291 |
|
| 292 |
|
| 293 |
let d = conn |
| 294 |
.describe("UPDATE accounts SET is_active=true WHERE id=?1 RETURNING id") |
| 295 |
.await?; |
| 296 |
|
| 297 |
assert_eq!(d.columns().len(), 1); |
| 298 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 299 |
assert_eq!(d.nullable(0), Some(false)); |
| 300 |
|
| 301 |
Ok(()) |
| 302 |
} |
| 303 |
|
| 304 |
#[sqlx_macros::test] |
| 305 |
async fn it_describes_delete_with_returning() -> anyhow::Result<()> { |
| 306 |
let mut conn = new::<Sqlite>().await?; |
| 307 |
|
| 308 |
let d = conn |
| 309 |
.describe("DELETE FROM accounts WHERE name=?1 RETURNING id") |
| 310 |
.await?; |
| 311 |
|
| 312 |
assert_eq!(d.columns().len(), 1); |
| 313 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 314 |
assert_eq!(d.nullable(0), Some(false)); |
| 315 |
|
| 316 |
Ok(()) |
| 317 |
} |
| 318 |
|
| 319 |
#[sqlx_macros::test] |
| 320 |
async fn it_describes_bad_statement() -> anyhow::Result<()> { |
| 321 |
let mut conn = new::<Sqlite>().await?; |
| 322 |
|
| 323 |
let err = conn.describe("SELECT 1 FROM not_found").await.unwrap_err(); |
| 324 |
let err = err |
| 325 |
.as_database_error() |
| 326 |
.unwrap() |
| 327 |
.downcast_ref::<SqliteError>(); |
| 328 |
|
| 329 |
assert_eq!(err.message(), "no such table: not_found"); |
| 330 |
assert_eq!(err.code().as_deref(), Some("1")); |
| 331 |
|
| 332 |
Ok(()) |
| 333 |
} |
| 334 |
|
| 335 |
#[sqlx_macros::test] |
| 336 |
async fn it_describes_left_join() -> anyhow::Result<()> { |
| 337 |
let mut conn = new::<Sqlite>().await?; |
| 338 |
|
| 339 |
let d = conn.describe("select accounts.id from accounts").await?; |
| 340 |
|
| 341 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 342 |
assert_eq!(d.nullable(0), Some(false)); |
| 343 |
|
| 344 |
let d = conn |
| 345 |
.describe("select tweet.id from accounts left join tweet on owner_id = accounts.id") |
| 346 |
.await?; |
| 347 |
|
| 348 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 349 |
assert_eq!(d.nullable(0), Some(true)); |
| 350 |
|
| 351 |
let d = conn |
| 352 |
.describe( |
| 353 |
"select tweet.id, accounts.id from accounts left join tweet on owner_id = accounts.id", |
| 354 |
) |
| 355 |
.await?; |
| 356 |
|
| 357 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 358 |
assert_eq!(d.nullable(0), Some(true)); |
| 359 |
|
| 360 |
assert_eq!(d.column(1).type_info().name(), "INTEGER"); |
| 361 |
assert_eq!(d.nullable(1), Some(false)); |
| 362 |
|
| 363 |
let d = conn |
| 364 |
.describe( |
| 365 |
"select tweet.id, accounts.id from accounts inner join tweet on owner_id = accounts.id", |
| 366 |
) |
| 367 |
.await?; |
| 368 |
|
| 369 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 370 |
assert_eq!(d.nullable(0), Some(false)); |
| 371 |
|
| 372 |
assert_eq!(d.column(1).type_info().name(), "INTEGER"); |
| 373 |
assert_eq!(d.nullable(1), Some(false)); |
| 374 |
|
| 375 |
let d = conn |
| 376 |
.describe( |
| 377 |
"select tweet.id, accounts.id from accounts left join tweet on tweet.id = accounts.id", |
| 378 |
) |
| 379 |
.await?; |
| 380 |
|
| 381 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 382 |
assert_eq!(d.nullable(0), Some(true)); |
| 383 |
|
| 384 |
assert_eq!(d.column(1).type_info().name(), "INTEGER"); |
| 385 |
assert_eq!(d.nullable(1), Some(false)); |
| 386 |
|
| 387 |
Ok(()) |
| 388 |
} |
| 389 |
|
| 390 |
#[sqlx_macros::test] |
| 391 |
async fn it_describes_group_by() -> anyhow::Result<()> { |
| 392 |
let mut conn = new::<Sqlite>().await?; |
| 393 |
|
| 394 |
let d = conn.describe("select id from accounts group by id").await?; |
| 395 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 396 |
assert_eq!(d.nullable(0), Some(false)); |
| 397 |
|
| 398 |
let d = conn |
| 399 |
.describe("SELECT name from accounts GROUP BY 1 LIMIT -1 OFFSET 1") |
| 400 |
.await?; |
| 401 |
assert_eq!(d.column(0).type_info().name(), "TEXT"); |
| 402 |
assert_eq!(d.nullable(0), Some(false)); |
| 403 |
|
| 404 |
let d = conn |
| 405 |
.describe("SELECT sum(id), sum(is_sent) from tweet GROUP BY owner_id") |
| 406 |
.await?; |
| 407 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 408 |
assert_eq!(d.nullable(0), Some(false)); |
| 409 |
assert_eq!(d.column(1).type_info().name(), "INTEGER"); |
| 410 |
assert_eq!(d.nullable(1), Some(false)); |
| 411 |
|
| 412 |
Ok(()) |
| 413 |
} |
| 414 |
|
| 415 |
#[sqlx_macros::test] |
| 416 |
async fn it_describes_ungrouped_aggregate() -> anyhow::Result<()> { |
| 417 |
let mut conn = new::<Sqlite>().await?; |
| 418 |
|
| 419 |
let d = conn.describe("select count(1) from accounts").await?; |
| 420 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 421 |
assert_eq!(d.nullable(0), Some(false)); |
| 422 |
|
| 423 |
let d = conn.describe("SELECT sum(is_sent) from tweet").await?; |
| 424 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 425 |
assert_eq!(d.nullable(0), Some(true)); |
| 426 |
|
| 427 |
let d = conn |
| 428 |
.describe("SELECT coalesce(sum(is_sent),0) from tweet") |
| 429 |
.await?; |
| 430 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 431 |
assert_eq!(d.nullable(0), Some(false)); |
| 432 |
|
| 433 |
Ok(()) |
| 434 |
} |
| 435 |
|
| 436 |
#[sqlx_macros::test] |
| 437 |
async fn it_describes_literal_subquery() -> anyhow::Result<()> { |
| 438 |
async fn assert_literal_described( |
| 439 |
conn: &mut sqlx::SqliteConnection, |
| 440 |
query: &str, |
| 441 |
) -> anyhow::Result<()> { |
| 442 |
let info = conn.describe(query).await?; |
| 443 |
|
| 444 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 445 |
assert_eq!(info.nullable(0), Some(false), "{query}"); |
| 446 |
assert_eq!(info.column(1).type_info().name(), "NULL", "{query}"); |
| 447 |
assert_eq!(info.nullable(1), Some(true), "{query}"); |
| 448 |
|
| 449 |
Ok(()) |
| 450 |
} |
| 451 |
|
| 452 |
let mut conn = new::<Sqlite>().await?; |
| 453 |
assert_literal_described(&mut conn, "SELECT 'a', NULL").await?; |
| 454 |
assert_literal_described(&mut conn, "SELECT * FROM (SELECT 'a', NULL)").await?; |
| 455 |
assert_literal_described( |
| 456 |
&mut conn, |
| 457 |
"WITH cte AS (SELECT 'a', NULL) SELECT * FROM cte", |
| 458 |
) |
| 459 |
.await?; |
| 460 |
assert_literal_described( |
| 461 |
&mut conn, |
| 462 |
"WITH cte AS MATERIALIZED (SELECT 'a', NULL) SELECT * FROM cte", |
| 463 |
) |
| 464 |
.await?; |
| 465 |
assert_literal_described( |
| 466 |
&mut conn, |
| 467 |
"WITH RECURSIVE cte(a,b) AS (SELECT 'a', NULL UNION ALL SELECT a||a, NULL FROM cte WHERE length(a)<3) SELECT * FROM cte", |
| 468 |
) |
| 469 |
.await?; |
| 470 |
|
| 471 |
Ok(()) |
| 472 |
} |
| 473 |
|
| 474 |
async fn assert_tweet_described( |
| 475 |
conn: &mut sqlx::SqliteConnection, |
| 476 |
query: &str, |
| 477 |
) -> anyhow::Result<()> { |
| 478 |
let info = conn.describe(query).await?; |
| 479 |
let columns = info.columns(); |
| 480 |
|
| 481 |
assert_eq!(columns[0].name(), "id", "{query}"); |
| 482 |
assert_eq!(columns[1].name(), "text", "{query}"); |
| 483 |
assert_eq!(columns[2].name(), "is_sent", "{query}"); |
| 484 |
assert_eq!(columns[3].name(), "owner_id", "{query}"); |
| 485 |
|
| 486 |
assert_eq!(columns[0].ordinal(), 0, "{query}"); |
| 487 |
assert_eq!(columns[1].ordinal(), 1, "{query}"); |
| 488 |
assert_eq!(columns[2].ordinal(), 2, "{query}"); |
| 489 |
assert_eq!(columns[3].ordinal(), 3, "{query}"); |
| 490 |
|
| 491 |
assert_eq!(info.nullable(0), Some(false), "{query}"); |
| 492 |
assert_eq!(info.nullable(1), Some(false), "{query}"); |
| 493 |
assert_eq!(info.nullable(2), Some(false), "{query}"); |
| 494 |
assert_eq!(info.nullable(3), Some(true), "{query}"); |
| 495 |
|
| 496 |
assert_eq!(columns[0].type_info().name(), "INTEGER", "{query}"); |
| 497 |
assert_eq!(columns[1].type_info().name(), "TEXT", "{query}"); |
| 498 |
assert_eq!(columns[2].type_info().name(), "BOOLEAN", "{query}"); |
| 499 |
assert_eq!(columns[3].type_info().name(), "INTEGER", "{query}"); |
| 500 |
|
| 501 |
Ok(()) |
| 502 |
} |
| 503 |
|
| 504 |
#[sqlx_macros::test] |
| 505 |
async fn it_describes_table_subquery() -> anyhow::Result<()> { |
| 506 |
let mut conn = new::<Sqlite>().await?; |
| 507 |
assert_tweet_described(&mut conn, "SELECT * FROM tweet").await?; |
| 508 |
assert_tweet_described(&mut conn, "SELECT * FROM (SELECT * FROM tweet)").await?; |
| 509 |
assert_tweet_described( |
| 510 |
&mut conn, |
| 511 |
"WITH cte AS (SELECT * FROM tweet) SELECT * FROM cte", |
| 512 |
) |
| 513 |
.await?; |
| 514 |
assert_tweet_described( |
| 515 |
&mut conn, |
| 516 |
"WITH cte AS MATERIALIZED (SELECT * FROM tweet) SELECT * FROM cte", |
| 517 |
) |
| 518 |
.await?; |
| 519 |
|
| 520 |
Ok(()) |
| 521 |
} |
| 522 |
|
| 523 |
#[sqlx_macros::test] |
| 524 |
async fn it_describes_table_order_by() -> anyhow::Result<()> { |
| 525 |
let mut conn = new::<Sqlite>().await?; |
| 526 |
assert_tweet_described(&mut conn, "SELECT * FROM tweet ORDER BY id").await?; |
| 527 |
assert_tweet_described(&mut conn, "SELECT * FROM tweet ORDER BY id NULLS LAST").await?; |
| 528 |
assert_tweet_described( |
| 529 |
&mut conn, |
| 530 |
"SELECT * FROM tweet ORDER BY owner_id DESC, text ASC", |
| 531 |
) |
| 532 |
.await?; |
| 533 |
|
| 534 |
async fn assert_literal_order_by_described( |
| 535 |
conn: &mut sqlx::SqliteConnection, |
| 536 |
query: &str, |
| 537 |
) -> anyhow::Result<()> { |
| 538 |
let info = conn.describe(query).await?; |
| 539 |
|
| 540 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 541 |
assert_eq!(info.nullable(0), Some(false), "{query}"); |
| 542 |
assert_eq!(info.column(1).type_info().name(), "TEXT", "{query}"); |
| 543 |
assert_eq!(info.nullable(1), Some(false), "{query}"); |
| 544 |
|
| 545 |
Ok(()) |
| 546 |
} |
| 547 |
|
| 548 |
assert_literal_order_by_described(&mut conn, "SELECT 'a', text FROM tweet ORDER BY id").await?; |
| 549 |
assert_literal_order_by_described( |
| 550 |
&mut conn, |
| 551 |
"SELECT 'a', text FROM tweet ORDER BY id NULLS LAST", |
| 552 |
) |
| 553 |
.await?; |
| 554 |
assert_literal_order_by_described(&mut conn, "SELECT 'a', text FROM tweet ORDER BY text") |
| 555 |
.await?; |
| 556 |
assert_literal_order_by_described( |
| 557 |
&mut conn, |
| 558 |
"SELECT 'a', text FROM tweet ORDER BY text NULLS LAST", |
| 559 |
) |
| 560 |
.await?; |
| 561 |
assert_literal_order_by_described( |
| 562 |
&mut conn, |
| 563 |
"SELECT 'a', text FROM tweet ORDER BY text DESC NULLS LAST", |
| 564 |
) |
| 565 |
.await?; |
| 566 |
|
| 567 |
Ok(()) |
| 568 |
} |
| 569 |
|
| 570 |
#[sqlx_macros::test] |
| 571 |
async fn it_describes_union() -> anyhow::Result<()> { |
| 572 |
async fn assert_union_described( |
| 573 |
conn: &mut sqlx::SqliteConnection, |
| 574 |
query: &str, |
| 575 |
) -> anyhow::Result<()> { |
| 576 |
let info = conn.describe(query).await?; |
| 577 |
|
| 578 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 579 |
assert_eq!(info.nullable(0), Some(false), "{query}"); |
| 580 |
assert_eq!(info.column(1).type_info().name(), "TEXT", "{query}"); |
| 581 |
assert_eq!(info.nullable(1), Some(true), "{query}"); |
| 582 |
assert_eq!(info.column(2).type_info().name(), "INTEGER", "{query}"); |
| 583 |
assert_eq!(info.nullable(2), Some(true), "{query}"); |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
Ok(()) |
| 589 |
} |
| 590 |
|
| 591 |
let mut conn = new::<Sqlite>().await?; |
| 592 |
assert_union_described( |
| 593 |
&mut conn, |
| 594 |
"SELECT 'txt','a',null,'b' UNION ALL SELECT 'int',NULL,1,2 ", |
| 595 |
) |
| 596 |
.await?; |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
assert_union_described( |
| 602 |
&mut conn, |
| 603 |
"SELECT 'tweet',text,owner_id id,null from tweet |
| 604 |
UNION SELECT 'account',name,id,is_active from accounts |
| 605 |
UNION SELECT 'account',name,id,is_active from accounts_view |
| 606 |
UNION SELECT 'dummy',null,null,null |
| 607 |
ORDER BY id |
| 608 |
", |
| 609 |
) |
| 610 |
.await?; |
| 611 |
|
| 612 |
Ok(()) |
| 613 |
} |
| 614 |
|
| 615 |
#[sqlx_macros::test] |
| 616 |
async fn it_describes_having_group_by() -> anyhow::Result<()> { |
| 617 |
let mut conn = new::<Sqlite>().await?; |
| 618 |
|
| 619 |
let d = conn |
| 620 |
.describe( |
| 621 |
r#" |
| 622 |
WITH tweet_reply_unq as ( --tweets with a single response |
| 623 |
SELECT tweet_id id |
| 624 |
FROM tweet_reply |
| 625 |
GROUP BY tweet_id |
| 626 |
HAVING COUNT(1) = 1 |
| 627 |
) |
| 628 |
SELECT |
| 629 |
( |
| 630 |
SELECT COUNT(*) |
| 631 |
FROM ( |
| 632 |
SELECT NULL |
| 633 |
FROM tweet |
| 634 |
JOIN tweet_reply_unq |
| 635 |
USING (id) |
| 636 |
WHERE tweet.owner_id = accounts.id |
| 637 |
) |
| 638 |
) single_reply_count |
| 639 |
FROM accounts |
| 640 |
WHERE id = ?1 |
| 641 |
"#, |
| 642 |
) |
| 643 |
.await?; |
| 644 |
|
| 645 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 646 |
assert_eq!(d.nullable(0), Some(false)); |
| 647 |
|
| 648 |
Ok(()) |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
#[sqlx_macros::test] |
| 653 |
async fn it_describes_strange_queries() -> anyhow::Result<()> { |
| 654 |
async fn assert_single_column_described( |
| 655 |
conn: &mut sqlx::SqliteConnection, |
| 656 |
query: &str, |
| 657 |
typename: &str, |
| 658 |
nullable: bool, |
| 659 |
) -> anyhow::Result<()> { |
| 660 |
let info = conn.describe(query).await?; |
| 661 |
assert_eq!(info.column(0).type_info().name(), typename, "{query}"); |
| 662 |
assert_eq!(info.nullable(0), Some(nullable), "{query}"); |
| 663 |
|
| 664 |
Ok(()) |
| 665 |
} |
| 666 |
|
| 667 |
let mut conn = new::<Sqlite>().await?; |
| 668 |
|
| 669 |
assert_single_column_described( |
| 670 |
&mut conn, |
| 671 |
"SELECT true FROM (SELECT true) a ORDER BY true", |
| 672 |
"INTEGER", |
| 673 |
false, |
| 674 |
) |
| 675 |
.await?; |
| 676 |
|
| 677 |
assert_single_column_described( |
| 678 |
&mut conn, |
| 679 |
" |
| 680 |
SELECT true |
| 681 |
FROM ( |
| 682 |
SELECT 'a' |
| 683 |
) |
| 684 |
CROSS JOIN ( |
| 685 |
SELECT 'b' |
| 686 |
FROM (SELECT 'c') |
| 687 |
CROSS JOIN accounts |
| 688 |
ORDER BY id |
| 689 |
LIMIT 1 |
| 690 |
) |
| 691 |
", |
| 692 |
"INTEGER", |
| 693 |
false, |
| 694 |
) |
| 695 |
.await?; |
| 696 |
|
| 697 |
assert_single_column_described( |
| 698 |
&mut conn, |
| 699 |
"SELECT true FROM tweet |
| 700 |
ORDER BY true ASC NULLS LAST", |
| 701 |
"INTEGER", |
| 702 |
false, |
| 703 |
) |
| 704 |
.await?; |
| 705 |
|
| 706 |
assert_single_column_described( |
| 707 |
&mut conn, |
| 708 |
"SELECT true LIMIT -1 OFFSET -1", |
| 709 |
"INTEGER", |
| 710 |
false, |
| 711 |
) |
| 712 |
.await?; |
| 713 |
|
| 714 |
assert_single_column_described( |
| 715 |
&mut conn, |
| 716 |
"SELECT true FROM tweet J LIMIT 10 OFFSET 1000000", |
| 717 |
"INTEGER", |
| 718 |
false, |
| 719 |
) |
| 720 |
.await?; |
| 721 |
|
| 722 |
assert_single_column_described( |
| 723 |
&mut conn, |
| 724 |
"SELECT text |
| 725 |
FROM (SELECT null) |
| 726 |
CROSS JOIN ( |
| 727 |
SELECT text |
| 728 |
FROM tweet |
| 729 |
GROUP BY text |
| 730 |
) |
| 731 |
LIMIT -1 OFFSET -1", |
| 732 |
"TEXT", |
| 733 |
false, |
| 734 |
) |
| 735 |
.await?; |
| 736 |
|
| 737 |
assert_single_column_described( |
| 738 |
&mut conn, |
| 739 |
"SELECT EYH.id,COUNT(EYH.id) |
| 740 |
FROM accounts EYH", |
| 741 |
"INTEGER", |
| 742 |
true, |
| 743 |
) |
| 744 |
.await?; |
| 745 |
|
| 746 |
assert_single_column_described( |
| 747 |
&mut conn, |
| 748 |
"SELECT SUM(tweet.text) FROM (SELECT NULL FROM accounts_view LIMIT -1 OFFSET 1) CROSS JOIN tweet", |
| 749 |
"REAL", |
| 750 |
true, |
| 751 |
) |
| 752 |
.await?; |
| 753 |
|
| 754 |
Ok(()) |
| 755 |
} |
| 756 |
|
| 757 |
#[sqlx_macros::test] |
| 758 |
async fn it_describes_func_date() -> anyhow::Result<()> { |
| 759 |
let mut conn = new::<Sqlite>().await?; |
| 760 |
|
| 761 |
let query = "SELECT date();"; |
| 762 |
let info = conn.describe(query).await?; |
| 763 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 764 |
assert_eq!(info.nullable(0), Some(false), "{query}"); |
| 765 |
|
| 766 |
let query = "SELECT date('now');"; |
| 767 |
let info = conn.describe(query).await?; |
| 768 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 769 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 770 |
|
| 771 |
let query = "SELECT date('now', 'start of month');"; |
| 772 |
let info = conn.describe(query).await?; |
| 773 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 774 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 775 |
|
| 776 |
let query = "SELECT date(:datebind);"; |
| 777 |
let info = conn.describe(query).await?; |
| 778 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 779 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 780 |
Ok(()) |
| 781 |
} |
| 782 |
|
| 783 |
#[sqlx_macros::test] |
| 784 |
async fn it_describes_func_time() -> anyhow::Result<()> { |
| 785 |
let mut conn = new::<Sqlite>().await?; |
| 786 |
|
| 787 |
let query = "SELECT time();"; |
| 788 |
let info = conn.describe(query).await?; |
| 789 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 790 |
assert_eq!(info.nullable(0), Some(false), "{query}"); |
| 791 |
|
| 792 |
let query = "SELECT time('now');"; |
| 793 |
let info = conn.describe(query).await?; |
| 794 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 795 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 796 |
|
| 797 |
let query = "SELECT time('now', 'start of month');"; |
| 798 |
let info = conn.describe(query).await?; |
| 799 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 800 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 801 |
|
| 802 |
let query = "SELECT time(:datebind);"; |
| 803 |
let info = conn.describe(query).await?; |
| 804 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 805 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 806 |
Ok(()) |
| 807 |
} |
| 808 |
|
| 809 |
#[sqlx_macros::test] |
| 810 |
async fn it_describes_func_datetime() -> anyhow::Result<()> { |
| 811 |
let mut conn = new::<Sqlite>().await?; |
| 812 |
|
| 813 |
let query = "SELECT datetime();"; |
| 814 |
let info = conn.describe(query).await?; |
| 815 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 816 |
assert_eq!(info.nullable(0), Some(false), "{query}"); |
| 817 |
|
| 818 |
let query = "SELECT datetime('now');"; |
| 819 |
let info = conn.describe(query).await?; |
| 820 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 821 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 822 |
|
| 823 |
let query = "SELECT datetime('now', 'start of month');"; |
| 824 |
let info = conn.describe(query).await?; |
| 825 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 826 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 827 |
|
| 828 |
let query = "SELECT datetime(:datebind);"; |
| 829 |
let info = conn.describe(query).await?; |
| 830 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 831 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 832 |
Ok(()) |
| 833 |
} |
| 834 |
|
| 835 |
#[sqlx_macros::test] |
| 836 |
async fn it_describes_func_julianday() -> anyhow::Result<()> { |
| 837 |
let mut conn = new::<Sqlite>().await?; |
| 838 |
|
| 839 |
let query = "SELECT julianday();"; |
| 840 |
let info = conn.describe(query).await?; |
| 841 |
assert_eq!(info.column(0).type_info().name(), "REAL", "{query}"); |
| 842 |
assert_eq!(info.nullable(0), Some(false), "{query}"); |
| 843 |
|
| 844 |
let query = "SELECT julianday('now');"; |
| 845 |
let info = conn.describe(query).await?; |
| 846 |
assert_eq!(info.column(0).type_info().name(), "REAL", "{query}"); |
| 847 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 848 |
|
| 849 |
let query = "SELECT julianday('now', 'start of month');"; |
| 850 |
let info = conn.describe(query).await?; |
| 851 |
assert_eq!(info.column(0).type_info().name(), "REAL", "{query}"); |
| 852 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 853 |
|
| 854 |
let query = "SELECT julianday(:datebind);"; |
| 855 |
let info = conn.describe(query).await?; |
| 856 |
assert_eq!(info.column(0).type_info().name(), "REAL", "{query}"); |
| 857 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 858 |
Ok(()) |
| 859 |
} |
| 860 |
|
| 861 |
#[sqlx_macros::test] |
| 862 |
async fn it_describes_func_strftime() -> anyhow::Result<()> { |
| 863 |
let mut conn = new::<Sqlite>().await?; |
| 864 |
|
| 865 |
let query = "SELECT strftime('%s','now');"; |
| 866 |
let info = conn.describe(query).await?; |
| 867 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 868 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 869 |
|
| 870 |
let query = "SELECT strftime('%s', 'now', 'start of month');"; |
| 871 |
let info = conn.describe(query).await?; |
| 872 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 873 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 874 |
|
| 875 |
let query = "SELECT strftime('%s',:datebind);"; |
| 876 |
let info = conn.describe(query).await?; |
| 877 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 878 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 879 |
Ok(()) |
| 880 |
} |
| 881 |
|
| 882 |
#[sqlx_macros::test] |
| 883 |
async fn it_describes_with_recursive() -> anyhow::Result<()> { |
| 884 |
let mut conn = new::<Sqlite>().await?; |
| 885 |
|
| 886 |
let query = " |
| 887 |
WITH RECURSIVE schedule(begin_date) AS ( |
| 888 |
SELECT datetime('2022-10-01') |
| 889 |
WHERE datetime('2022-10-01') < datetime('2022-11-03') |
| 890 |
UNION ALL |
| 891 |
SELECT datetime(begin_date,'+1 day') |
| 892 |
FROM schedule |
| 893 |
WHERE datetime(begin_date) < datetime(?2) |
| 894 |
) |
| 895 |
SELECT |
| 896 |
begin_date |
| 897 |
FROM schedule |
| 898 |
GROUP BY begin_date |
| 899 |
"; |
| 900 |
let info = conn.describe(query).await?; |
| 901 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 902 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 903 |
|
| 904 |
let query = " |
| 905 |
WITH RECURSIVE schedule(begin_date) AS MATERIALIZED ( |
| 906 |
SELECT datetime('2022-10-01') |
| 907 |
WHERE datetime('2022-10-01') < datetime('2022-11-03') |
| 908 |
UNION ALL |
| 909 |
SELECT datetime(begin_date,'+1 day') |
| 910 |
FROM schedule |
| 911 |
WHERE datetime(begin_date) < datetime(?2) |
| 912 |
) |
| 913 |
SELECT |
| 914 |
begin_date |
| 915 |
FROM schedule |
| 916 |
GROUP BY begin_date |
| 917 |
"; |
| 918 |
let info = conn.describe(query).await?; |
| 919 |
assert_eq!(info.column(0).type_info().name(), "TEXT", "{query}"); |
| 920 |
assert_eq!(info.nullable(0), Some(true), "{query}"); |
| 921 |
|
| 922 |
Ok(()) |
| 923 |
} |
| 924 |
|
| 925 |
#[sqlx_macros::test] |
| 926 |
async fn it_describes_analytical_function() -> anyhow::Result<()> { |
| 927 |
let mut conn = new::<Sqlite>().await?; |
| 928 |
|
| 929 |
let d = conn |
| 930 |
.describe("select row_number() over () from accounts") |
| 931 |
.await?; |
| 932 |
dbg!(&d); |
| 933 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 934 |
assert_eq!(d.nullable(0), Some(false)); |
| 935 |
|
| 936 |
let d = conn.describe("select rank() over () from accounts").await?; |
| 937 |
dbg!(&d); |
| 938 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 939 |
assert_eq!(d.nullable(0), Some(false)); |
| 940 |
|
| 941 |
let d = conn |
| 942 |
.describe("select dense_rank() over () from accounts") |
| 943 |
.await?; |
| 944 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 945 |
assert_eq!(d.nullable(0), Some(false)); |
| 946 |
|
| 947 |
let d = conn |
| 948 |
.describe("select percent_rank() over () from accounts") |
| 949 |
.await?; |
| 950 |
assert_eq!(d.column(0).type_info().name(), "REAL"); |
| 951 |
assert_eq!(d.nullable(0), Some(false)); |
| 952 |
|
| 953 |
let d = conn |
| 954 |
.describe("select cume_dist() over () from accounts") |
| 955 |
.await?; |
| 956 |
assert_eq!(d.column(0).type_info().name(), "REAL"); |
| 957 |
assert_eq!(d.nullable(0), Some(false)); |
| 958 |
|
| 959 |
let d = conn |
| 960 |
.describe("select ntile(1) over () from accounts") |
| 961 |
.await?; |
| 962 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 963 |
assert_eq!(d.nullable(0), Some(false)); |
| 964 |
|
| 965 |
let d = conn |
| 966 |
.describe("select lag(id) over () from accounts") |
| 967 |
.await?; |
| 968 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 969 |
assert_eq!(d.nullable(0), Some(true)); |
| 970 |
|
| 971 |
let d = conn |
| 972 |
.describe("select lag(name) over () from accounts") |
| 973 |
.await?; |
| 974 |
assert_eq!(d.column(0).type_info().name(), "TEXT"); |
| 975 |
assert_eq!(d.nullable(0), Some(true)); |
| 976 |
|
| 977 |
let d = conn |
| 978 |
.describe("select lead(id) over () from accounts") |
| 979 |
.await?; |
| 980 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 981 |
assert_eq!(d.nullable(0), Some(true)); |
| 982 |
|
| 983 |
let d = conn |
| 984 |
.describe("select lead(name) over () from accounts") |
| 985 |
.await?; |
| 986 |
assert_eq!(d.column(0).type_info().name(), "TEXT"); |
| 987 |
assert_eq!(d.nullable(0), Some(true)); |
| 988 |
|
| 989 |
let d = conn |
| 990 |
.describe("select first_value(id) over () from accounts") |
| 991 |
.await?; |
| 992 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 993 |
assert_eq!(d.nullable(0), Some(true)); |
| 994 |
|
| 995 |
let d = conn |
| 996 |
.describe("select first_value(name) over () from accounts") |
| 997 |
.await?; |
| 998 |
assert_eq!(d.column(0).type_info().name(), "TEXT"); |
| 999 |
assert_eq!(d.nullable(0), Some(true)); |
| 1000 |
|
| 1001 |
let d = conn |
| 1002 |
.describe("select last_value(id) over () from accounts") |
| 1003 |
.await?; |
| 1004 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 1005 |
assert_eq!(d.nullable(0), Some(false)); |
| 1006 |
|
| 1007 |
let d = conn |
| 1008 |
.describe("select first_value(name) over () from accounts") |
| 1009 |
.await?; |
| 1010 |
assert_eq!(d.column(0).type_info().name(), "TEXT"); |
| 1011 |
|
| 1012 |
|
| 1013 |
let d = conn |
| 1014 |
.describe("select nth_value(id,10) over () from accounts") |
| 1015 |
.await?; |
| 1016 |
assert_eq!(d.column(0).type_info().name(), "INTEGER"); |
| 1017 |
assert_eq!(d.nullable(0), Some(true)); |
| 1018 |
|
| 1019 |
let d = conn |
| 1020 |
.describe("select nth_value(name,10) over () from accounts") |
| 1021 |
.await?; |
| 1022 |
assert_eq!(d.column(0).type_info().name(), "TEXT"); |
| 1023 |
assert_eq!(d.nullable(0), Some(true)); |
| 1024 |
|
| 1025 |
Ok(()) |
| 1026 |
} |