Revision 2850
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
415 | 415 |
else: |
416 | 416 |
if left_non_null is not left_value: # wrapped, so wrap both |
417 | 417 |
left_value = left_non_null |
418 |
right_value = EnsureNotNull(right_value, left_value.args[1])
|
|
418 |
right_value = EnsureNotNull(right_value, left_value.type)
|
|
419 | 419 |
|
420 | 420 |
if equals and is_null(right_value): operator = 'IS' |
421 | 421 |
|
... | ... | |
523 | 523 |
|
524 | 524 |
row_count = CustomCode('count(*)') |
525 | 525 |
|
526 |
def EnsureNotNull(value, null):
|
|
527 |
return FunctionCall(InternalFunction('coalesce'), as_Col(value), null)
|
|
526 |
# See <http://www.postgresql.org/docs/8.3/static/datatype-numeric.html>
|
|
527 |
null_sentinels = {'text': r'\N', 'integer': 2147483647}
|
|
528 | 528 |
|
529 |
class EnsureNotNull(FunctionCall): |
|
530 |
def __init__(self, value, type_): |
|
531 |
FunctionCall.__init__(self, InternalFunction('coalesce'), as_Col(value), |
|
532 |
null_sentinels[type_]) |
|
533 |
|
|
534 |
self.type = type_ |
|
535 |
|
|
529 | 536 |
##### Table exprs |
530 | 537 |
|
531 | 538 |
class Values(Code): |
... | ... | |
574 | 581 |
|
575 | 582 |
def to_Col(self): return Col(self.name) |
576 | 583 |
|
577 |
# See <http://www.postgresql.org/docs/8.3/static/datatype-numeric.html> |
|
578 |
null_sentinels = {'text': r'\N', 'integer': 2147483647} |
|
579 |
|
|
580 | 584 |
ensure_not_null_excs = (NoUnderlyingTableException, KeyError) |
581 | 585 |
|
582 | 586 |
def ensure_not_null(db, col): |
... | ... | |
586 | 590 |
@throws ensure_not_null_excs |
587 | 591 |
''' |
588 | 592 |
typed_col = db.col_info(underlying_col(col)) |
589 |
if typed_col.nullable: |
|
590 |
col = EnsureNotNull(col, null_sentinels[typed_col.type]) |
|
593 |
if typed_col.nullable: col = EnsureNotNull(col, typed_col.type) |
|
591 | 594 |
return col |
Also available in: Unified diff
sql_gen.py: EnsureNotNull: Take a type param instead of a null param so that the EnsureNotNull object stores the underlying column's type