# Path: pyke/goal.py
# def compile(goal_str):
#     def __init__(self, goal_str, rb_name, goal_name, patterns, pattern_vars):
#     def prove(self, engine, **args):
#     def prove_1(self, engine, **args):
#     def __init__(self, engine, rb_name, goal_name, patterns, context,
#                        pattern_vars):
#     def __enter__(self):
#     def __exit__(self, type, value, tb):
#     def doctor_answer(self, prototype_plan):
# class prover(object):
# class producer(object):


import contextlib
from pyke import goal
            for name, in table_cursor.fetchall():
                _load_table(engine, column_cursor, name)
    depth = 1
    while _links_to(engine, depth): depth += 1

def _load_table(engine, cursor, table_name):
    # This doesn't allow sql parameters!
    cursor.execute("pragma table_info(%s)" % table_name)
    for col_num, col_name, type, null_flag, default, key in cursor.fetchall():
        _create_column(engine, table_name, col_name, type, null_flag != 99,
                       key, default, None)

def _create_column(engine, table_name, col_name, type, null, key, default,
                   extra):
    #null = null.upper() == 'YES'
    if not key: key = None
    if not default: default = None
    if not extra: extra = None
    _add_fact(engine, "column",
              (table_name, col_name, type, null, key, default, extra))
    if col_name == 'id':
        _add_fact(engine, "primary_key", (table_name, (col_name,)))
    if col_name.endswith('_id'):
        to_table = col_name[:-3]
        _add_fact(engine, "many_to_1",
                  (table_name, to_table, (col_name,), ('id',)))

many_to_1 = goal.compile(
  'schema.many_to_1($from_table, $to_table, $from_columns, $to_columns)')


# Path: pyke/goal.py
# def compile(goal_str):
#     def __init__(self, goal_str, rb_name, goal_name, patterns, pattern_vars):
#     def prove(self, engine, **args):
#     def prove_1(self, engine, **args):
#     def __init__(self, engine, rb_name, goal_name, patterns, context,
#                        pattern_vars):
#     def __enter__(self):
#     def __exit__(self, type, value, tb):
#     def doctor_answer(self, prototype_plan):
# class prover(object):
# class producer(object):


# Path: examples/sqlgen/load_sqlite3_schema.py
import contextlib
from pyke import goal

            for name, in table_cursor.fetchall():
                _load_table(engine, column_cursor, name)
    depth = 1
    while _links_to(engine, depth): depth += 1

def _load_table(engine, cursor, table_name):
    # This doesn't allow sql parameters!
    cursor.execute("pragma table_info(%s)" % table_name)
    for col_num, col_name, type, null_flag, default, key in cursor.fetchall():
        _create_column(engine, table_name, col_name, type, null_flag != 99,
                       key, default, None)

def _create_column(engine, table_name, col_name, type, null, key, default,
                   extra):
    #null = null.upper() == 'YES'
    if not key: key = None
    if not default: default = None
    if not extra: extra = None
    _add_fact(engine, "column",
              (table_name, col_name, type, null, key, default, extra))
    if col_name == 'id':
        _add_fact(engine, "primary_key", (table_name, (col_name,)))
    if col_name.endswith('_id'):
        to_table = col_name[:-3]
        _add_fact(engine, "many_to_1",
                  (table_name, to_table, (col_name,), ('id',)))

many_to_1 = goal.compile(
  'schema.many_to_1($from_table, $to_table, $from_columns, $to_columns)')


links_to = goal.compile(