| 1 | package SQL::Engine::Grammar::Mssql; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | |||
| 13 | extends 'SQL::Engine::Grammar'; | ||
| 14 | |||
| 15 | our $VERSION = '0.02'; # VERSION | ||
| 16 | |||
| 17 | # METHODS | ||
| 18 | |||
| 19 | method column_change(HashRef $data) { | ||
| 20 | $self->operation($self->term(qw(begin transaction))); | ||
| 21 | |||
| 22 | my $def = $self->column_definition($data->{column}); | ||
| 23 | |||
| 24 | # column type | ||
| 25 | $self->operation(do { | ||
| 26 | my $sql = []; | ||
| 27 | |||
| 28 | # alter table | ||
| 29 | push @$sql, $self->term(qw(alter table)); | ||
| 30 | |||
| 31 | # safe | ||
| 32 | push @$sql, $self->term(qw(if exists)) if $data->{safe}; | ||
| 33 | |||
| 34 | # for | ||
| 35 | push @$sql, $self->table($data->{for}); | ||
| 36 | |||
| 37 | # alter column | ||
| 38 | push @$sql, $self->term(qw(alter column)); | ||
| 39 | |||
| 40 | # column name | ||
| 41 | push @$sql, $self->name($data->{column}{name}); | ||
| 42 | |||
| 43 | # column type | ||
| 44 | push @$sql, $def->{type}; | ||
| 45 | |||
| 46 | # column (set | drop) not null | ||
| 47 | push @$sql, | ||
| 48 | (exists $data->{column}{nullable}) | ||
| 49 | ? ( | ||
| 50 | $data->{column}{nullable} | ||
| 51 | ? $self->term(qw(null)) | ||
| 52 | : $self->term(qw(not null)) | ||
| 53 | ) | ||
| 54 | : $self->term(qw(null)); | ||
| 55 | |||
| 56 | # sql statement | ||
| 57 | join ' ', @$sql | ||
| 58 | }); | ||
| 59 | |||
| 60 | # drop any column default | ||
| 61 | $self->operation(do { | ||
| 62 | my $sql = []; | ||
| 63 | |||
| 64 | my $tsql = q{ | ||
| 65 | DECLARE @schema_name nvarchar(256); | ||
| 66 | DECLARE @table_name nvarchar(256); | ||
| 67 | DECLARE @col_name nvarchar(256); | ||
| 68 | DECLARE @Command nvarchar(1000); | ||
| 69 | |||
| 70 | SET @schema_name = DB_NAME(); | ||
| 71 | SET @table_name = N'{TABLE_NAME}'; | ||
| 72 | SET @col_name = N'{COLUMN_NAME}'; | ||
| 73 | |||
| 74 | SELECT @Command = 'ALTER TABLE ' + @schema_name + '.[' + @table_name + '] DROP CONSTRAINT ' + d.name | ||
| 75 | FROM sys.tables t | ||
| 76 | JOIN sys.default_constraints d on d.parent_object_id = t.object_id | ||
| 77 | JOIN sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id | ||
| 78 | WHERE t.name = @table_name | ||
| 79 | AND t.schema_id = schema_id(@schema_name) | ||
| 80 | AND c.name = @col_name; | ||
| 81 | |||
| 82 | EXECUTE (@Command) | ||
| 83 | }; | ||
| 84 | |||
| 85 | my $table_name = $self->table($data->{"for"}); | ||
| 86 | my $column_name = $self->name($data->{column}{name}); | ||
| 87 | |||
| 88 | $tsql =~ s/\{TABLE_NAME\}/$table_name/; | ||
| 89 | $tsql =~ s/\{COLUMN_NAME\}/$column_name/; | ||
| 90 | $tsql =~ s/\s+/ /g; | ||
| 91 | $tsql =~ s/\n+//g; | ||
| 92 | |||
| 93 | push @$sql, $tsql; | ||
| 94 | |||
| 95 | # sql statement | ||
| 96 | join ' ', @$sql | ||
| 97 | }); | ||
| 98 | |||
| 99 | # column set default | ||
| 100 | if ($data->{column}{default}) { | ||
| 101 | $self->operation(do { | ||
| 102 | my $sql = []; | ||
| 103 | |||
| 104 | # alter table | ||
| 105 | push @$sql, $self->term(qw(alter table)); | ||
| 106 | |||
| 107 | # safe | ||
| 108 | push @$sql, $self->term(qw(if exists)) if $data->{safe}; | ||
| 109 | |||
| 110 | # for | ||
| 111 | push @$sql, $self->table($data->{for}); | ||
| 112 | |||
| 113 | # default constraint name | ||
| 114 | push @$sql, $self->term(qw(add constraint)), | ||
| 115 | join '_', 'DF', $data->{column}{name}; | ||
| 116 | |||
| 117 | # default | ||
| 118 | push @$sql, $def->{default}; | ||
| 119 | |||
| 120 | # column name | ||
| 121 | push @$sql, $self->term(qw(for)), $self->name($data->{column}{name}); | ||
| 122 | |||
| 123 | # sql statement | ||
| 124 | join ' ', @$sql | ||
| 125 | }); | ||
| 126 | } | ||
| 127 | |||
| 128 | $self->operation($self->term('commit')); | ||
| 129 | |||
| 130 | return $self; | ||
| 131 | } | ||
| 132 | |||
| 133 | method column_create(HashRef $data) { | ||
| 134 | my $sql = []; | ||
| 135 | |||
| 136 | # alter table | ||
| 137 | push @$sql, $self->term(qw(alter table)); | ||
| 138 | |||
| 139 | # safe | ||
| 140 | push @$sql, $self->term(qw(if exists)) if $data->{safe}; | ||
| 141 | |||
| 142 | # for | ||
| 143 | push @$sql, $self->table($data->{for}); | ||
| 144 | |||
| 145 | # column | ||
| 146 | push @$sql, $self->term(qw(add)); | ||
| 147 | |||
| 148 | # column specification | ||
| 149 | push @$sql, $self->column_specification($data->{column}); | ||
| 150 | |||
| 151 | # sql statement | ||
| 152 | my $result = join ' ', @$sql; | ||
| 153 | |||
| 154 | return $self->operation($result); | ||
| 155 | } | ||
| 156 | |||
| 157 | method column_definition(HashRef $data) { | ||
| 158 | my $def = $self->next::method($data); | ||
| 159 | |||
| 160 | if (exists $data->{default}) { | ||
| 161 | $def->{default} = join ' ', $self->term('default'), | ||
| 162 | sprintf '(%s)', $self->expression($data->{default}); | ||
| 163 | } | ||
| 164 | |||
| 165 | if ($data->{increment}) { | ||
| 166 | $def->{increment} = $self->term('identity'); | ||
| 167 | } | ||
| 168 | |||
| 169 | return $def; | ||
| 170 | } | ||
| 171 | |||
| 172 | method column_rename(HashRef $data) { | ||
| 173 | my $sql = []; | ||
| 174 | |||
| 175 | # table name | ||
| 176 | my $table = join '.', $self->table($data->{"for"}), $self->name($data->{name}{old}); | ||
| 177 | |||
| 178 | # rename column | ||
| 179 | push @$sql, $self->term(qw(exec)), | ||
| 180 | 'sp_rename', | ||
| 181 | join ', ', | ||
| 182 | $self->value($table), | ||
| 183 | $self->value($self->name($data->{name}{new})), | ||
| 184 | $self->value(uc('column')); | ||
| 185 | |||
| 186 | # sql statement | ||
| 187 | my $result = join ' ', @$sql; | ||
| 188 | |||
| 189 | return $self->operation($result); | ||
| 190 | } | ||
| 191 | |||
| 192 | method index_drop(HashRef $data) { | ||
| 193 | my $sql = []; | ||
| 194 | |||
| 195 | # drop | ||
| 196 | push @$sql, $self->term('drop'); | ||
| 197 | |||
| 198 | # index | ||
| 199 | push @$sql, $self->term('index'); | ||
| 200 | |||
| 201 | # safe | ||
| 202 | push @$sql, $self->term(qw(if exists)) if $data->{safe}; | ||
| 203 | |||
| 204 | # index name | ||
| 205 | push @$sql, $self->wrap($self->index_name($data)); | ||
| 206 | |||
| 207 | # table | ||
| 208 | push @$sql, $self->term('on'), $self->table($data->{for}); | ||
| 209 | |||
| 210 | # sql statement | ||
| 211 | my $result = join ' ', @$sql; | ||
| 212 | |||
| 213 | return $self->operation($result); | ||
| 214 | } | ||
| 215 | |||
| 216 | method select(HashRef $data) { | ||
| 217 | my $sql = []; | ||
| 218 | |||
| 219 | # select | ||
| 220 | push @$sql, $self->term('select'); | ||
| 221 | |||
| 222 | # columns | ||
| 223 | if (my $columns = $data->{columns}) { | ||
| 224 | push @$sql, join(', ', map $self->expression($_), @$columns); | ||
| 225 | } | ||
| 226 | |||
| 227 | # into (mssql) | ||
| 228 | if (my $into = $data->{into}) { | ||
| 229 | push @$sql, $self->term('into'), $self->name($into); | ||
| 230 | } | ||
| 231 | |||
| 232 | # from | ||
| 233 | push @$sql, $self->term('from'), | ||
| 234 | ref($data->{from}) eq 'ARRAY' | ||
| 235 | ? join(', ', map $self->table($_), @{$data->{from}}) | ||
| 236 | : $self->table($data->{from}); | ||
| 237 | |||
| 238 | # joins | ||
| 239 | if (my $joins = $data->{joins}) { | ||
| 240 | for my $join (@$joins) { | ||
| 241 | push @$sql, $self->join_option($join->{type}), $self->table($join->{with}); | ||
| 242 | push @$sql, $self->term('on'), | ||
| 243 | join( | ||
| 244 | sprintf(' %s ', $self->term('and')), | ||
| 245 | @{$self->criteria($join->{having})} | ||
| 246 | ); | ||
| 247 | } | ||
| 248 | } | ||
| 249 | |||
| 250 | # where | ||
| 251 | if (my $where = $data->{where}) { | ||
| 252 | push @$sql, $self->term('where'), | ||
| 253 | join(sprintf(' %s ', $self->term('and')), @{$self->criteria($where)}); | ||
| 254 | } | ||
| 255 | |||
| 256 | # group-by | ||
| 257 | if (my $group_by = $data->{"group-by"}) { | ||
| 258 | push @$sql, $self->term(qw(group by)); | ||
| 259 | push @$sql, join ', ', map $self->expression($_), @$group_by; | ||
| 260 | |||
| 261 | # having | ||
| 262 | if (my $having = $data->{"having"}) { | ||
| 263 | push @$sql, $self->term('having'), | ||
| 264 | join(sprintf(' %s ', $self->term('and')), @{$self->criteria($having)}); | ||
| 265 | } | ||
| 266 | } | ||
| 267 | |||
| 268 | # order-by | ||
| 269 | if (my $orders = $data->{"order-by"}) { | ||
| 270 | my @orders; | ||
| 271 | push @$sql, $self->term(qw(order by)); | ||
| 272 | for my $order (@$orders) { | ||
| 273 | if ($order->{sort} | ||
| 274 | && ($order->{sort} eq 'asc' || $order->{sort} eq 'ascending')) | ||
| 275 | { | ||
| 276 | push @orders, sprintf '%s ASC', | ||
| 277 | $self->name($order->{"alias"}, $order->{"column"}); | ||
| 278 | } | ||
| 279 | elsif ($order->{sort} | ||
| 280 | && ($order->{sort} eq 'desc' || $order->{sort} eq 'descending')) | ||
| 281 | { | ||
| 282 | push @orders, sprintf '%s DESC', | ||
| 283 | $self->name($order->{"alias"}, $order->{"column"}); | ||
| 284 | } | ||
| 285 | else { | ||
| 286 | push @orders, $self->name($order->{"alias"}, $order->{"column"}); | ||
| 287 | } | ||
| 288 | } | ||
| 289 | push @$sql, join ', ', @orders; | ||
| 290 | } | ||
| 291 | |||
| 292 | # rows | ||
| 293 | if (my $rows = $data->{rows}) { | ||
| 294 | if ($rows->{limit} && $rows->{offset}) { | ||
| 295 | push @$sql, sprintf '%s %d %s', | ||
| 296 | $self->term('offset'), | ||
| 297 | $rows->{offset}, | ||
| 298 | $self->term(qw(rows)); | ||
| 299 | push @$sql, sprintf '%s %d %s', | ||
| 300 | $self->term(qw(fetch next)), | ||
| 301 | $rows->{limit}, | ||
| 302 | $self->term(qw(rows only)); | ||
| 303 | } | ||
| 304 | if ($rows->{limit} && !$rows->{offset}) { | ||
| 305 | push @$sql, sprintf '%s %d %s', | ||
| 306 | $self->term('offset'), | ||
| 307 | 0, | ||
| 308 | $self->term(qw(rows)); | ||
| 309 | push @$sql, sprintf '%s %d %s', | ||
| 310 | $self->term(qw(fetch next)), | ||
| 311 | $rows->{limit}, | ||
| 312 | $self->term(qw(rows only)); | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | # sql statement | ||
| 317 | my $result = join ' ', @$sql; | ||
| 318 | |||
| 319 | return $self->operation($result); | ||
| 320 | } | ||
| 321 | |||
| 322 | method table_create(HashRef $data) { | ||
| 323 | my $sql = []; | ||
| 324 | |||
| 325 | # create | ||
| 326 | push @$sql, $self->term('create'); | ||
| 327 | |||
| 328 | # temporary | ||
| 329 | my $name; | ||
| 330 | if ($data->{temp}) { | ||
| 331 | $name = "#".$data->{name}; | ||
| 332 | } | ||
| 333 | else { | ||
| 334 | $name = $data->{name}; | ||
| 335 | } | ||
| 336 | |||
| 337 | # table | ||
| 338 | push @$sql, $self->term('table'), | ||
| 339 | ($data->{safe} ? $self->term(qw(if not exists)) : ()), | ||
| 340 | $self->name($name); | ||
| 341 | |||
| 342 | # body | ||
| 343 | my $body = []; | ||
| 344 | |||
| 345 | # columns | ||
| 346 | if (my $columns = $data->{columns}) { | ||
| 347 | push @$body, map $self->column_specification($_), @$columns; | ||
| 348 | } | ||
| 349 | |||
| 350 | # constraints | ||
| 351 | if (my $constraints = $data->{constraints}) { | ||
| 352 | # unique | ||
| 353 | for my $constraint (grep {$_->{unique}} @{$constraints}) { | ||
| 354 | if (my $unique = $constraint->{unique}) { | ||
| 355 | my $name = $self->index_name({ | ||
| 356 | for => $data->{for}, | ||
| 357 | name => $unique->{name}, | ||
| 358 | columns => [map +{column => $_}, @{$unique->{columns}}], | ||
| 359 | unique => 1, | ||
| 360 | }); | ||
| 361 | push @$body, join ' ', $self->term('constraint'), $name, | ||
| 362 | $self->term('unique'), sprintf '(%s)', join ', ', | ||
| 363 | map $self->name($_), @{$unique->{columns}}; | ||
| 364 | } | ||
| 365 | } | ||
| 366 | # foreign | ||
| 367 | for my $constraint (grep {$_->{foreign}} @{$constraints}) { | ||
| 368 | if (my $foreign = $constraint->{foreign}) { | ||
| 369 | my $name = $self->constraint_name({ | ||
| 370 | source => { | ||
| 371 | table => $data->{name}, | ||
| 372 | column => $foreign->{column} | ||
| 373 | }, | ||
| 374 | target => $foreign->{reference}, | ||
| 375 | name => $foreign->{name} | ||
| 376 | }); | ||
| 377 | push @$body, join ' ', $self->term('constraint'), $name, | ||
| 378 | $self->term(qw(foreign key)), | ||
| 379 | sprintf('(%s)', $self->name($foreign->{column})), | ||
| 380 | $self->term(qw(references)), | ||
| 381 | sprintf('%s (%s)', | ||
| 382 | $self->table($foreign->{reference}), | ||
| 383 | $self->name($foreign->{reference}{column})), | ||
| 384 | ( | ||
| 385 | $foreign->{on}{delete} | ||
| 386 | ? ( | ||
| 387 | $self->term(qw(on delete)), | ||
| 388 | $self->constraint_option($foreign->{on}{delete}) | ||
| 389 | ) | ||
| 390 | : () | ||
| 391 | ), | ||
| 392 | ( | ||
| 393 | $foreign->{on}{update} | ||
| 394 | ? ( | ||
| 395 | $self->term(qw(on update)), | ||
| 396 | $self->constraint_option($foreign->{on}{update}) | ||
| 397 | ) | ||
| 398 | : () | ||
| 399 | ); | ||
| 400 | } | ||
| 401 | } | ||
| 402 | } | ||
| 403 | |||
| 404 | # definition | ||
| 405 | if (@$body) { | ||
| 406 | push @$sql, sprintf('(%s)', join ', ', @$body); | ||
| 407 | } | ||
| 408 | |||
| 409 | # query | ||
| 410 | if (my $query = $data->{query}) { | ||
| 411 | $sql = []; | ||
| 412 | $self->select({%{$query->{select}}, into => $name}); | ||
| 413 | my $operation = $self->operations->pop; | ||
| 414 | $self->{bindings} = $operation->bindings; | ||
| 415 | push @$sql, $operation->statement; | ||
| 416 | } | ||
| 417 | |||
| 418 | # sql statement | ||
| 419 | my $result = join ' ', @$sql; | ||
| 420 | |||
| 421 | return $self->operation($result); | ||
| 422 | } | ||
| 423 | |||
| 424 | method table_rename(HashRef $data) { | ||
| 425 | my $sql = []; | ||
| 426 | |||
| 427 | # rename table | ||
| 428 | push @$sql, $self->term(qw(exec)), 'sp_rename', | ||
| 429 | join ', ', $self->name($data->{name}{old}), $self->name($data->{name}{new}); | ||
| 430 | |||
| 431 | # sql statement | ||
| 432 | my $result = join ' ', @$sql; | ||
| 433 | |||
| 434 | return $self->operation($result); | ||
| 435 | } | ||
| 436 | |||
| 437 | method transaction(HashRef $data) { | ||
| 438 | my @mode; | ||
| 439 | if ($data->{mode}) { | ||
| 440 | @mode = map $self->term($_), @{$data->{mode}}; | ||
| 441 | } | ||
| 442 | if (@mode) { | ||
| 443 | $self->operation($self->term(qw(set transaction isolation level), @mode)); | ||
| 444 | } | ||
| 445 | $self->operation($self->term('begin', 'transaction')); | ||
| 446 | $self->process($_) for @{$data->{queries}}; | ||
| 447 | $self->operation($self->term('commit')); | ||
| 448 | |||
| 449 | return $self; | ||
| 450 | } | ||
| 451 | |||
| 452 | method type_binary(HashRef $data) { | ||
| 453 | |||
| 454 | return 'varbinary(max)'; | ||
| 455 | } | ||
| 456 | |||
| 457 | method type_boolean(HashRef $data) { | ||
| 458 | |||
| 459 | return 'bit'; | ||
| 460 | } | ||
| 461 | |||
| 462 | method type_char(HashRef $data) { | ||
| 463 | my $options = $data->{options} || []; | ||
| 464 | |||
| 465 | return sprintf('nchar(%s)', $self->value($options->[0] || 1)); | ||
| 466 | } | ||
| 467 | |||
| 468 | method type_date(HashRef $data) { | ||
| 469 | |||
| 470 | return 'date'; | ||
| 471 | } | ||
| 472 | |||
| 473 | method type_datetime(HashRef $data) { | ||
| 474 | |||
| 475 | return 'datetime'; | ||
| 476 | } | ||
| 477 | |||
| 478 | method type_datetime_wtz(HashRef $data) { | ||
| 479 | |||
| 480 | return 'datetimeoffset(0)'; | ||
| 481 | } | ||
| 482 | |||
| 483 | method type_decimal(HashRef $data) { | ||
| 484 | my $options = $data->{options} || []; | ||
| 485 | |||
| 486 | return sprintf( | ||
| 487 | 'decimal(%s)', | ||
| 488 | join(', ', | ||
| 489 | $self->value($options->[0]) || 5, | ||
| 490 | $self->value($options->[1]) || 2) | ||
| 491 | ); | ||
| 492 | } | ||
| 493 | |||
| 494 | method type_double(HashRef $data) { | ||
| 495 | |||
| 496 | return 'float'; | ||
| 497 | } | ||
| 498 | |||
| 499 | method type_enum(HashRef $data) { | ||
| 500 | |||
| 501 | return 'nvarchar(255)'; | ||
| 502 | } | ||
| 503 | |||
| 504 | method type_float(HashRef $data) { | ||
| 505 | |||
| 506 | return 'float'; | ||
| 507 | } | ||
| 508 | |||
| 509 | method type_integer(HashRef $data) { | ||
| 510 | |||
| 511 | return 'int'; | ||
| 512 | } | ||
| 513 | |||
| 514 | method type_integer_big(HashRef $data) { | ||
| 515 | |||
| 516 | return 'bigint'; | ||
| 517 | } | ||
| 518 | |||
| 519 | method type_integer_big_unsigned(HashRef $data) { | ||
| 520 | |||
| 521 | return $self->type_integer_big($data); | ||
| 522 | } | ||
| 523 | |||
| 524 | method type_integer_medium(HashRef $data) { | ||
| 525 | |||
| 526 | return 'int'; | ||
| 527 | } | ||
| 528 | |||
| 529 | method type_integer_medium_unsigned(HashRef $data) { | ||
| 530 | |||
| 531 | return $self->type_integer_medium($data); | ||
| 532 | } | ||
| 533 | |||
| 534 | method type_integer_small(HashRef $data) { | ||
| 535 | |||
| 536 | return 'smallint'; | ||
| 537 | } | ||
| 538 | |||
| 539 | method type_integer_small_unsigned(HashRef $data) { | ||
| 540 | |||
| 541 | return $self->type_integer_small($data); | ||
| 542 | } | ||
| 543 | |||
| 544 | method type_integer_tiny(HashRef $data) { | ||
| 545 | |||
| 546 | return 'tinyint'; | ||
| 547 | } | ||
| 548 | |||
| 549 | method type_integer_tiny_unsigned(HashRef $data) { | ||
| 550 | |||
| 551 | return $self->type_integer_tiny($data); | ||
| 552 | } | ||
| 553 | |||
| 554 | method type_integer_unsigned(HashRef $data) { | ||
| 555 | |||
| 556 | return $self->type_integer($data); | ||
| 557 | } | ||
| 558 | |||
| 559 | method type_json(HashRef $data) { | ||
| 560 | |||
| 561 | return 'nvarchar(max)'; | ||
| 562 | } | ||
| 563 | |||
| 564 | method type_number(HashRef $data) { | ||
| 565 | |||
| 566 | return $self->type_integer($data); | ||
| 567 | } | ||
| 568 | |||
| 569 | method type_string(HashRef $data) { | ||
| 570 | my $options = $data->{options} || []; | ||
| 571 | |||
| 572 | return sprintf('nvarchar(%s)', $options->[0] || 255); | ||
| 573 | } | ||
| 574 | |||
| 575 | method type_text(HashRef $data) { | ||
| 576 | |||
| 577 | return 'nvarchar(max)'; | ||
| 578 | } | ||
| 579 | |||
| 580 | method type_text_long(HashRef $data) { | ||
| 581 | |||
| 582 | return 'nvarchar(max)'; | ||
| 583 | } | ||
| 584 | |||
| 585 | method type_text_medium(HashRef $data) { | ||
| 586 | |||
| 587 | return 'nvarchar(max)'; | ||
| 588 | } | ||
| 589 | |||
| 590 | method type_time(HashRef $data) { | ||
| 591 | |||
| 592 | return 'time'; | ||
| 593 | } | ||
| 594 | |||
| 595 | method type_time_wtz(HashRef $data) { | ||
| 596 | |||
| 597 | return 'time'; | ||
| 598 | } | ||
| 599 | |||
| 600 | method type_timestamp(HashRef $data) { | ||
| 601 | |||
| 602 | return 'datetime'; | ||
| 603 | } | ||
| 604 | |||
| 605 | method type_timestamp_wtz(HashRef $data) { | ||
| 606 | |||
| 607 | return 'datetimeoffset(0)'; | ||
| 608 | } | ||
| 609 | |||
| 610 | method type_uuid(HashRef $data) { | ||
| 611 | |||
| 612 | return 'uniqueidentifier'; | ||
| 613 | } | ||
| 614 | |||
| 615 | method wrap(Str $name) { | ||
| 616 | |||
| 617 | return qq([$name]); | ||
| 618 | } | ||
| 619 | |||
| 620 | 1; | ||
| 621 | |||
| 622 | =encoding utf8 | ||
| 623 | |||
| 624 | =head1 NAME | ||
| 625 | |||
| 626 | SQL::Engine::Grammar::Mssql - Grammar For MSSQL | ||
| 627 | |||
| 628 | =cut | ||
| 629 | |||
| 630 | =head1 ABSTRACT | ||
| 631 | |||
| 632 | SQL::Engine Grammar For MSSQL | ||
| 633 | |||
| 634 | =cut | ||
| 635 | |||
| 636 | =head1 SYNOPSIS | ||
| 637 | |||
| 638 | use SQL::Engine::Grammar::Mssql; | ||
| 639 | |||
| 640 | my $grammar = SQL::Engine::Grammar::Mssql->new( | ||
| 641 | schema => { | ||
| 642 | select => { | ||
| 643 | from => { | ||
| 644 | table => 'users' | ||
| 645 | }, | ||
| 646 | columns => [ | ||
| 647 | { | ||
| 648 | column => '*' | ||
| 649 | } | ||
| 650 | ] | ||
| 651 | } | ||
| 652 | } | ||
| 653 | ); | ||
| 654 | |||
| 655 | # $grammar->execute; | ||
| 656 | |||
| 657 | =cut | ||
| 658 | |||
| 659 | =head1 DESCRIPTION | ||
| 660 | |||
| 661 | This package provides methods for converting | ||
| 662 | L<json-sql|https://github.com/iamalnewkirk/json-sql> data structures into | ||
| 663 | MSSQL statements. | ||
| 664 | |||
| 665 | =cut | ||
| 666 | |||
| 667 | =head1 INHERITS | ||
| 668 | |||
| 669 | This package inherits behaviors from: | ||
| 670 | |||
| 671 | L<SQL::Engine::Grammar> | ||
| 672 | |||
| 673 | =cut | ||
| 674 | |||
| 675 | =head1 LIBRARIES | ||
| 676 | |||
| 677 | This package uses type constraints from: | ||
| 678 | |||
| 679 | L<Types::Standard> | ||
| 680 | |||
| 681 | =cut | ||
| 682 | |||
| 683 | =head1 METHODS | ||
| 684 | |||
| 685 | This package implements the following methods: | ||
| 686 | |||
| 687 | =cut | ||
| 688 | |||
| 689 | =head2 column_change | ||
| 690 | |||
| 691 | column_change(HashRef $data) : Object | ||
| 692 | |||
| 693 | The column_change method generates SQL statements to change a column | ||
| 694 | definition. | ||
| 695 | |||
| 696 | =over 4 | ||
| 697 | |||
| 698 | =item column_change example #1 | ||
| 699 | |||
| 700 | my $grammar = SQL::Engine::Grammar::Mssql->new( | ||
| 701 | schema => { | ||
| 702 | 'column-change' => { | ||
| 703 | for => { | ||
| 704 | table => 'users' | ||
| 705 | }, | ||
| 706 | column => { | ||
| 707 | name => 'accessed', | ||
| 708 | type => 'datetime', | ||
| 709 | nullable => 1 | ||
| 710 | } | ||
| 711 | } | ||
| 712 | } | ||
| 713 | ); | ||
| 714 | |||
| 715 | $grammar->column_change($grammar->schema->{'column-change'}); | ||
| 716 | |||
| 717 | =back | ||
| 718 | |||
| 719 | =cut | ||
| 720 | |||
| 721 | =head2 transaction | ||
| 722 | |||
| 723 | transaction(HashRef $data) : Object | ||
| 724 | |||
| 725 | The transaction method generates SQL statements to commit an atomic database | ||
| 726 | transaction. | ||
| 727 | |||
| 728 | =over 4 | ||
| 729 | |||
| 730 | =item transaction example #1 | ||
| 731 | |||
| 732 | my $grammar = SQL::Engine::Grammar::Mssql->new( | ||
| 733 | schema => { | ||
| 734 | 'transaction' => { | ||
| 735 | queries => [ | ||
| 736 | { | ||
| 737 | 'table-create' => { | ||
| 738 | name => 'users', | ||
| 739 | columns => [ | ||
| 740 | { | ||
| 741 | name => 'id', | ||
| 742 | type => 'integer', | ||
| 743 | primary => 1 | ||
| 744 | } | ||
| 745 | ] | ||
| 746 | } | ||
| 747 | } | ||
| 748 | ] | ||
| 749 | } | ||
| 750 | } | ||
| 751 | ); | ||
| 752 | |||
| 753 | $grammar->transaction($grammar->schema->{'transaction'}); | ||
| 754 | |||
| 755 | =back | ||
| 756 | |||
| 757 | =cut | ||
| 758 | |||
| 759 | =head2 type_binary | ||
| 760 | |||
| 761 | type_binary(HashRef $data) : Str | ||
| 762 | |||
| 763 | The type_binary method returns the SQL expression representing a binary data | ||
| 764 | type. | ||
| 765 | |||
| 766 | =over 4 | ||
| 767 | |||
| 768 | =item type_binary example #1 | ||
| 769 | |||
| 770 | # given: synopsis | ||
| 771 | |||
| 772 | $grammar->type_binary({}); | ||
| 773 | |||
| 774 | # varbinary(max) | ||
| 775 | |||
| 776 | =back | ||
| 777 | |||
| 778 | =cut | ||
| 779 | |||
| 780 | =head2 type_boolean | ||
| 781 | |||
| 782 | type_boolean(HashRef $data) : Str | ||
| 783 | |||
| 784 | The type_boolean method returns the SQL expression representing a boolean data type. | ||
| 785 | |||
| 786 | =over 4 | ||
| 787 | |||
| 788 | =item type_boolean example #1 | ||
| 789 | |||
| 790 | # given: synopsis | ||
| 791 | |||
| 792 | $grammar->type_boolean({}); | ||
| 793 | |||
| 794 | # bit | ||
| 795 | |||
| 796 | =back | ||
| 797 | |||
| 798 | =cut | ||
| 799 | |||
| 800 | =head2 type_char | ||
| 801 | |||
| 802 | type_char(HashRef $data) : Str | ||
| 803 | |||
| 804 | The type_char method returns the SQL expression representing a char data type. | ||
| 805 | |||
| 806 | =over 4 | ||
| 807 | |||
| 808 | =item type_char example #1 | ||
| 809 | |||
| 810 | # given: synopsis | ||
| 811 | |||
| 812 | $grammar->type_char({}); | ||
| 813 | |||
| 814 | # nchar(1) | ||
| 815 | |||
| 816 | =back | ||
| 817 | |||
| 818 | =cut | ||
| 819 | |||
| 820 | =head2 type_date | ||
| 821 | |||
| 822 | type_date(HashRef $data) : Str | ||
| 823 | |||
| 824 | The type_date method returns the SQL expression representing a date data type. | ||
| 825 | |||
| 826 | =over 4 | ||
| 827 | |||
| 828 | =item type_date example #1 | ||
| 829 | |||
| 830 | # given: synopsis | ||
| 831 | |||
| 832 | $grammar->type_date({}); | ||
| 833 | |||
| 834 | # date | ||
| 835 | |||
| 836 | =back | ||
| 837 | |||
| 838 | =cut | ||
| 839 | |||
| 840 | =head2 type_datetime | ||
| 841 | |||
| 842 | type_datetime(HashRef $data) : Str | ||
| 843 | |||
| 844 | The type_datetime method returns the SQL expression representing a datetime | ||
| 845 | data type. | ||
| 846 | |||
| 847 | =over 4 | ||
| 848 | |||
| 849 | =item type_datetime example #1 | ||
| 850 | |||
| 851 | # given: synopsis | ||
| 852 | |||
| 853 | $grammar->type_datetime({}); | ||
| 854 | |||
| 855 | # datetime | ||
| 856 | |||
| 857 | =back | ||
| 858 | |||
| 859 | =cut | ||
| 860 | |||
| 861 | =head2 type_datetime_wtz | ||
| 862 | |||
| 863 | type_datetime_wtz(HashRef $data) : Str | ||
| 864 | |||
| 865 | The type_datetime_wtz method returns the SQL expression representing a datetime | ||
| 866 | (and timezone) data type. | ||
| 867 | |||
| 868 | =over 4 | ||
| 869 | |||
| 870 | =item type_datetime_wtz example #1 | ||
| 871 | |||
| 872 | # given: synopsis | ||
| 873 | |||
| 874 | $grammar->type_datetime_wtz({}); | ||
| 875 | |||
| 876 | # datetimeoffset(0) | ||
| 877 | |||
| 878 | =back | ||
| 879 | |||
| 880 | =cut | ||
| 881 | |||
| 882 | =head2 type_decimal | ||
| 883 | |||
| 884 | type_decimal(HashRef $data) : Str | ||
| 885 | |||
| 886 | The type_decimal method returns the SQL expression representing a decimal data | ||
| 887 | type. | ||
| 888 | |||
| 889 | =over 4 | ||
| 890 | |||
| 891 | =item type_decimal example #1 | ||
| 892 | |||
| 893 | # given: synopsis | ||
| 894 | |||
| 895 | $grammar->type_decimal({}); | ||
| 896 | |||
| 897 | # decimal(5, 2) | ||
| 898 | |||
| 899 | =back | ||
| 900 | |||
| 901 | =cut | ||
| 902 | |||
| 903 | =head2 type_double | ||
| 904 | |||
| 905 | type_double(HashRef $data) : Str | ||
| 906 | |||
| 907 | The type_double method returns the SQL expression representing a double data | ||
| 908 | type. | ||
| 909 | |||
| 910 | =over 4 | ||
| 911 | |||
| 912 | =item type_double example #1 | ||
| 913 | |||
| 914 | # given: synopsis | ||
| 915 | |||
| 916 | $grammar->type_double({}); | ||
| 917 | |||
| 918 | # float | ||
| 919 | |||
| 920 | =back | ||
| 921 | |||
| 922 | =cut | ||
| 923 | |||
| 924 | =head2 type_enum | ||
| 925 | |||
| 926 | type_enum(HashRef $data) : Str | ||
| 927 | |||
| 928 | The type_enum method returns the SQL expression representing a enum data type. | ||
| 929 | |||
| 930 | =over 4 | ||
| 931 | |||
| 932 | =item type_enum example #1 | ||
| 933 | |||
| 934 | # given: synopsis | ||
| 935 | |||
| 936 | $grammar->type_enum({ options => ['light', 'dark'] }); | ||
| 937 | |||
| 938 | # nvarchar(255) | ||
| 939 | |||
| 940 | =back | ||
| 941 | |||
| 942 | =cut | ||
| 943 | |||
| 944 | =head2 type_float | ||
| 945 | |||
| 946 | type_float(HashRef $data) : Str | ||
| 947 | |||
| 948 | The type_float method returns the SQL expression representing a float data | ||
| 949 | type. | ||
| 950 | |||
| 951 | =over 4 | ||
| 952 | |||
| 953 | =item type_float example #1 | ||
| 954 | |||
| 955 | # given: synopsis | ||
| 956 | |||
| 957 | $grammar->type_float({}); | ||
| 958 | |||
| 959 | # float | ||
| 960 | |||
| 961 | =back | ||
| 962 | |||
| 963 | =cut | ||
| 964 | |||
| 965 | =head2 type_integer | ||
| 966 | |||
| 967 | type_integer(HashRef $data) : Str | ||
| 968 | |||
| 969 | The type_integer method returns the SQL expression representing a integer data | ||
| 970 | type. | ||
| 971 | |||
| 972 | =over 4 | ||
| 973 | |||
| 974 | =item type_integer example #1 | ||
| 975 | |||
| 976 | # given: synopsis | ||
| 977 | |||
| 978 | $grammar->type_integer({}); | ||
| 979 | |||
| 980 | # int | ||
| 981 | |||
| 982 | =back | ||
| 983 | |||
| 984 | =cut | ||
| 985 | |||
| 986 | =head2 type_integer_big | ||
| 987 | |||
| 988 | type_integer_big(HashRef $data) : Str | ||
| 989 | |||
| 990 | The type_integer_big method returns the SQL expression representing a | ||
| 991 | big-integer data type. | ||
| 992 | |||
| 993 | =over 4 | ||
| 994 | |||
| 995 | =item type_integer_big example #1 | ||
| 996 | |||
| 997 | # given: synopsis | ||
| 998 | |||
| 999 | $grammar->type_integer_big({}); | ||
| 1000 | |||
| 1001 | # bigint | ||
| 1002 | |||
| 1003 | =back | ||
| 1004 | |||
| 1005 | =cut | ||
| 1006 | |||
| 1007 | =head2 type_integer_big_unsigned | ||
| 1008 | |||
| 1009 | type_integer_big_unsigned(HashRef $data) : Str | ||
| 1010 | |||
| 1011 | The type_integer_big_unsigned method returns the SQL expression representing a | ||
| 1012 | big unsigned integer data type. | ||
| 1013 | |||
| 1014 | =over 4 | ||
| 1015 | |||
| 1016 | =item type_integer_big_unsigned example #1 | ||
| 1017 | |||
| 1018 | # given: synopsis | ||
| 1019 | |||
| 1020 | $grammar->type_integer_big_unsigned({}); | ||
| 1021 | |||
| 1022 | # bigint | ||
| 1023 | |||
| 1024 | =back | ||
| 1025 | |||
| 1026 | =cut | ||
| 1027 | |||
| 1028 | =head2 type_integer_medium | ||
| 1029 | |||
| 1030 | type_integer_medium(HashRef $data) : Str | ||
| 1031 | |||
| 1032 | The type_integer_medium method returns the SQL expression representing a medium | ||
| 1033 | integer data type. | ||
| 1034 | |||
| 1035 | =over 4 | ||
| 1036 | |||
| 1037 | =item type_integer_medium example #1 | ||
| 1038 | |||
| 1039 | # given: synopsis | ||
| 1040 | |||
| 1041 | $grammar->type_integer_medium({}); | ||
| 1042 | |||
| 1043 | # int | ||
| 1044 | |||
| 1045 | =back | ||
| 1046 | |||
| 1047 | =cut | ||
| 1048 | |||
| 1049 | =head2 type_integer_medium_unsigned | ||
| 1050 | |||
| 1051 | type_integer_medium_unsigned(HashRef $data) : Str | ||
| 1052 | |||
| 1053 | The type_integer_medium_unsigned method returns the SQL expression representing | ||
| 1054 | a unsigned medium integer data type. | ||
| 1055 | |||
| 1056 | =over 4 | ||
| 1057 | |||
| 1058 | =item type_integer_medium_unsigned example #1 | ||
| 1059 | |||
| 1060 | # given: synopsis | ||
| 1061 | |||
| 1062 | $grammar->type_integer_medium_unsigned({}); | ||
| 1063 | |||
| 1064 | # int | ||
| 1065 | |||
| 1066 | =back | ||
| 1067 | |||
| 1068 | =cut | ||
| 1069 | |||
| 1070 | =head2 type_integer_small | ||
| 1071 | |||
| 1072 | type_integer_small(HashRef $data) : Str | ||
| 1073 | |||
| 1074 | The type_integer_small method returns the SQL expression representing a small | ||
| 1075 | integer data type. | ||
| 1076 | |||
| 1077 | =over 4 | ||
| 1078 | |||
| 1079 | =item type_integer_small example #1 | ||
| 1080 | |||
| 1081 | # given: synopsis | ||
| 1082 | |||
| 1083 | $grammar->type_integer_small({}); | ||
| 1084 | |||
| 1085 | # smallint | ||
| 1086 | |||
| 1087 | =back | ||
| 1088 | |||
| 1089 | =cut | ||
| 1090 | |||
| 1091 | =head2 type_integer_small_unsigned | ||
| 1092 | |||
| 1093 | type_integer_small_unsigned(HashRef $data) : Str | ||
| 1094 | |||
| 1095 | The type_integer_small_unsigned method returns the SQL expression representing | ||
| 1096 | a unsigned small integer data type. | ||
| 1097 | |||
| 1098 | =over 4 | ||
| 1099 | |||
| 1100 | =item type_integer_small_unsigned example #1 | ||
| 1101 | |||
| 1102 | # given: synopsis | ||
| 1103 | |||
| 1104 | $grammar->type_integer_small_unsigned({}); | ||
| 1105 | |||
| 1106 | # smallint | ||
| 1107 | |||
| 1108 | =back | ||
| 1109 | |||
| 1110 | =cut | ||
| 1111 | |||
| 1112 | =head2 type_integer_tiny | ||
| 1113 | |||
| 1114 | type_integer_tiny(HashRef $data) : Str | ||
| 1115 | |||
| 1116 | The type_integer_tiny method returns the SQL expression representing a tiny | ||
| 1117 | integer data type. | ||
| 1118 | |||
| 1119 | =over 4 | ||
| 1120 | |||
| 1121 | =item type_integer_tiny example #1 | ||
| 1122 | |||
| 1123 | # given: synopsis | ||
| 1124 | |||
| 1125 | $grammar->type_integer_tiny({}); | ||
| 1126 | |||
| 1127 | # tinyint | ||
| 1128 | |||
| 1129 | =back | ||
| 1130 | |||
| 1131 | =cut | ||
| 1132 | |||
| 1133 | =head2 type_integer_tiny_unsigned | ||
| 1134 | |||
| 1135 | type_integer_tiny_unsigned(HashRef $data) : Str | ||
| 1136 | |||
| 1137 | The type_integer_tiny_unsigned method returns the SQL expression representing a | ||
| 1138 | unsigned tiny integer data type. | ||
| 1139 | |||
| 1140 | =over 4 | ||
| 1141 | |||
| 1142 | =item type_integer_tiny_unsigned example #1 | ||
| 1143 | |||
| 1144 | # given: synopsis | ||
| 1145 | |||
| 1146 | $grammar->type_integer_tiny_unsigned({}); | ||
| 1147 | |||
| 1148 | # tinyint | ||
| 1149 | |||
| 1150 | =back | ||
| 1151 | |||
| 1152 | =cut | ||
| 1153 | |||
| 1154 | =head2 type_integer_unsigned | ||
| 1155 | |||
| 1156 | type_integer_unsigned(HashRef $data) : Str | ||
| 1157 | |||
| 1158 | The type_integer_unsigned method returns the SQL expression representing a | ||
| 1159 | unsigned integer data type. | ||
| 1160 | |||
| 1161 | =over 4 | ||
| 1162 | |||
| 1163 | =item type_integer_unsigned example #1 | ||
| 1164 | |||
| 1165 | # given: synopsis | ||
| 1166 | |||
| 1167 | $grammar->type_integer_unsigned({}); | ||
| 1168 | |||
| 1169 | # int | ||
| 1170 | |||
| 1171 | =back | ||
| 1172 | |||
| 1173 | =cut | ||
| 1174 | |||
| 1175 | =head2 type_json | ||
| 1176 | |||
| 1177 | type_json(HashRef $data) : Str | ||
| 1178 | |||
| 1179 | The type_json method returns the SQL expression representing a json data type. | ||
| 1180 | |||
| 1181 | =over 4 | ||
| 1182 | |||
| 1183 | =item type_json example #1 | ||
| 1184 | |||
| 1185 | # given: synopsis | ||
| 1186 | |||
| 1187 | $grammar->type_json({}); | ||
| 1188 | |||
| 1189 | # nvarchar(max) | ||
| 1190 | |||
| 1191 | =back | ||
| 1192 | |||
| 1193 | =cut | ||
| 1194 | |||
| 1195 | =head2 type_number | ||
| 1196 | |||
| 1197 | type_number(HashRef $data) : Str | ||
| 1198 | |||
| 1199 | The type_number method returns the SQL expression representing a number data | ||
| 1200 | type. | ||
| 1201 | |||
| 1202 | =over 4 | ||
| 1203 | |||
| 1204 | =item type_number example #1 | ||
| 1205 | |||
| 1206 | # given: synopsis | ||
| 1207 | |||
| 1208 | $grammar->type_number({}); | ||
| 1209 | |||
| 1210 | # int | ||
| 1211 | |||
| 1212 | =back | ||
| 1213 | |||
| 1214 | =cut | ||
| 1215 | |||
| 1216 | =head2 type_string | ||
| 1217 | |||
| 1218 | type_string(HashRef $data) : Str | ||
| 1219 | |||
| 1220 | The type_string method returns the SQL expression representing a string data | ||
| 1221 | type. | ||
| 1222 | |||
| 1223 | =over 4 | ||
| 1224 | |||
| 1225 | =item type_string example #1 | ||
| 1226 | |||
| 1227 | # given: synopsis | ||
| 1228 | |||
| 1229 | $grammar->type_string({}); | ||
| 1230 | |||
| 1231 | # nvarchar(255) | ||
| 1232 | |||
| 1233 | =back | ||
| 1234 | |||
| 1235 | =cut | ||
| 1236 | |||
| 1237 | =head2 type_text | ||
| 1238 | |||
| 1239 | type_text(HashRef $data) : Str | ||
| 1240 | |||
| 1241 | The type_text method returns the SQL expression representing a text data type. | ||
| 1242 | |||
| 1243 | =over 4 | ||
| 1244 | |||
| 1245 | =item type_text example #1 | ||
| 1246 | |||
| 1247 | # given: synopsis | ||
| 1248 | |||
| 1249 | $grammar->type_text({}); | ||
| 1250 | |||
| 1251 | # nvarchar(max) | ||
| 1252 | |||
| 1253 | =back | ||
| 1254 | |||
| 1255 | =cut | ||
| 1256 | |||
| 1257 | =head2 type_text_long | ||
| 1258 | |||
| 1259 | type_text_long(HashRef $data) : Str | ||
| 1260 | |||
| 1261 | The type_text_long method returns the SQL expression representing a long text | ||
| 1262 | data type. | ||
| 1263 | |||
| 1264 | =over 4 | ||
| 1265 | |||
| 1266 | =item type_text_long example #1 | ||
| 1267 | |||
| 1268 | # given: synopsis | ||
| 1269 | |||
| 1270 | $grammar->type_text_long({}); | ||
| 1271 | |||
| 1272 | # nvarchar(max) | ||
| 1273 | |||
| 1274 | =back | ||
| 1275 | |||
| 1276 | =cut | ||
| 1277 | |||
| 1278 | =head2 type_text_medium | ||
| 1279 | |||
| 1280 | type_text_medium(HashRef $data) : Str | ||
| 1281 | |||
| 1282 | The type_text_medium method returns the SQL expression representing a medium | ||
| 1283 | text data type. | ||
| 1284 | |||
| 1285 | =over 4 | ||
| 1286 | |||
| 1287 | =item type_text_medium example #1 | ||
| 1288 | |||
| 1289 | # given: synopsis | ||
| 1290 | |||
| 1291 | $grammar->type_text_medium({}); | ||
| 1292 | |||
| 1293 | # nvarchar(max) | ||
| 1294 | |||
| 1295 | =back | ||
| 1296 | |||
| 1297 | =cut | ||
| 1298 | |||
| 1299 | =head2 type_time | ||
| 1300 | |||
| 1301 | type_time(HashRef $data) : Str | ||
| 1302 | |||
| 1303 | The type_time method returns the SQL expression representing a time data type. | ||
| 1304 | |||
| 1305 | =over 4 | ||
| 1306 | |||
| 1307 | =item type_time example #1 | ||
| 1308 | |||
| 1309 | # given: synopsis | ||
| 1310 | |||
| 1311 | $grammar->type_time({}); | ||
| 1312 | |||
| 1313 | # time | ||
| 1314 | |||
| 1315 | =back | ||
| 1316 | |||
| 1317 | =cut | ||
| 1318 | |||
| 1319 | =head2 type_time_wtz | ||
| 1320 | |||
| 1321 | type_time_wtz(HashRef $data) : Str | ||
| 1322 | |||
| 1323 | The type_time_wtz method returns the SQL expression representing a time (and | ||
| 1324 | timezone) data type. | ||
| 1325 | |||
| 1326 | =over 4 | ||
| 1327 | |||
| 1328 | =item type_time_wtz example #1 | ||
| 1329 | |||
| 1330 | # given: synopsis | ||
| 1331 | |||
| 1332 | $grammar->type_time_wtz({}); | ||
| 1333 | |||
| 1334 | # time | ||
| 1335 | |||
| 1336 | =back | ||
| 1337 | |||
| 1338 | =cut | ||
| 1339 | |||
| 1340 | =head2 type_timestamp | ||
| 1341 | |||
| 1342 | type_timestamp(HashRef $data) : Str | ||
| 1343 | |||
| 1344 | The type_timestamp method returns the SQL expression representing a timestamp | ||
| 1345 | data type. | ||
| 1346 | |||
| 1347 | =over 4 | ||
| 1348 | |||
| 1349 | =item type_timestamp example #1 | ||
| 1350 | |||
| 1351 | # given: synopsis | ||
| 1352 | |||
| 1353 | $grammar->type_timestamp({}); | ||
| 1354 | |||
| 1355 | # datetime | ||
| 1356 | |||
| 1357 | =back | ||
| 1358 | |||
| 1359 | =cut | ||
| 1360 | |||
| 1361 | =head2 type_timestamp_wtz | ||
| 1362 | |||
| 1363 | type_timestamp_wtz(HashRef $data) : Str | ||
| 1364 | |||
| 1365 | The type_timestamp_wtz method returns the SQL expression representing a | ||
| 1366 | timestamp (and timezone) data type. | ||
| 1367 | |||
| 1368 | =over 4 | ||
| 1369 | |||
| 1370 | =item type_timestamp_wtz example #1 | ||
| 1371 | |||
| 1372 | # given: synopsis | ||
| 1373 | |||
| 1374 | $grammar->type_timestamp_wtz({}); | ||
| 1375 | |||
| 1376 | # datetimeoffset(0) | ||
| 1377 | |||
| 1378 | =back | ||
| 1379 | |||
| 1380 | =cut | ||
| 1381 | |||
| 1382 | =head2 type_uuid | ||
| 1383 | |||
| 1384 | type_uuid(HashRef $data) : Str | ||
| 1385 | |||
| 1386 | The type_uuid method returns the SQL expression representing a uuid data type. | ||
| 1387 | |||
| 1388 | =over 4 | ||
| 1389 | |||
| 1390 | =item type_uuid example #1 | ||
| 1391 | |||
| 1392 | # given: synopsis | ||
| 1393 | |||
| 1394 | $grammar->type_uuid({}); | ||
| 1395 | |||
| 1396 | # uniqueidentifier | ||
| 1397 | |||
| 1398 | =back | ||
| 1399 | |||
| 1400 | =cut | ||
| 1401 | |||
| 1402 | =head2 wrap | ||
| 1403 | |||
| 1404 | wrap(Str $name) : Str | ||
| 1405 | |||
| 1406 | The wrap method returns a SQL-escaped string. | ||
| 1407 | |||
| 1408 | =over 4 | ||
| 1409 | |||
| 1410 | =item wrap example #1 | ||
| 1411 | |||
| 1412 | # given: synopsis | ||
| 1413 | |||
| 1414 | $grammar->wrap('field'); | ||
| 1415 | |||
| 1416 | # "field" | ||
| 1417 | |||
| 1418 | =back | ||
| 1419 | |||
| 1420 | =cut | ||
| 1421 | |||
| 1422 | =head1 AUTHOR | ||
| 1423 | |||
| 1424 | Al Newkirk, C<awncorp@cpan.org> | ||
| 1425 | |||
| 1426 | =head1 LICENSE | ||
| 1427 | |||
| 1428 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 1429 | |||
| 1430 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 1431 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 1432 | file"|https://github.com/iamalnewkirk/sql-engine/blob/master/LICENSE>. | ||
| 1433 | |||
| 1434 | =head1 PROJECT | ||
| 1435 | |||
| 1436 | L<Wiki|https://github.com/iamalnewkirk/sql-engine/wiki> | ||
| 1437 | |||
| 1438 | L<Project|https://github.com/iamalnewkirk/sql-engine> | ||
| 1439 | |||
| 1440 | L<Initiatives|https://github.com/iamalnewkirk/sql-engine/projects> | ||
| 1441 | |||
| 1442 | L<Milestones|https://github.com/iamalnewkirk/sql-engine/milestones> | ||
| 1443 | |||
| 1444 | L<Contributing|https://github.com/iamalnewkirk/sql-engine/blob/master/CONTRIBUTE.md> | ||
| 1445 | |||
| 1446 | L<Issues|https://github.com/iamalnewkirk/sql-engine/issues> | ||
| 1447 | |||
| 1448 | =cut |