Example #1
0
(taskid, title, note, deleted) \
VALUES (new._id, new.title, new.note, {})".format(log.name, deleted))
    triggers.append(t)

# Notifications
nots = Table('notification')
nots.add_cols(
    Column('time').integer,
    Column('permanent').integer.not_null.default(0),
    Column('taskid').integer,
    Column('repeats').integer.not_null.default(0),
    Column('locationname').text,
    Column('latitude').real,
    Column('longitude').real,
    Column('radius').real)
nots.add_constraints(ForeignKey('taskid').references(tasks.name)\
                    .on_delete_cascade)
tables.append(nots)

# Let's try to create the SQL
st = SQLTester()
st.add_tables(*tables)
st.add_triggers(*triggers)

st.test_create()

#g = Generator(path='./sample/src/com/example/appname/database/')
#g.add_tables(persons, log)
#g.add_triggers(trigger)
#g.write()
log = Table('Log').add_cols(
    Column('pId').integer.not_null,
    Column('firstname').text.not_null,
    Column('lastname').text.not_null,
    Column('bio').text.not_null,
    Column('time').timestamp.default_current_timestamp)

# Create a trigger that keeps the log up to date
# I recommend using temp triggers unless you see a performance hit
trigger = Trigger('tr_log').temp.if_not_exists

# Here I have given the wrong table name on purpose. Notice that the sql
# creation will fail because there is no table named bob.
trigger.after.update_on("bob")
#trigger.after.update_on(log.name)

# Raw sql
trigger.do_sql("INSERT INTO {table} ({cols}) VALUES\
 ({oldcols})".format(table=log.name,
                     cols=log.list_column_names(exclude=['_id', 'time']),
                     oldcols=persons.list_column_names(exclude=[],
                                                       prefix="old.")))

# Let's try to create the SQL
st = SQLTester()
st.add_tables(persons, log)
st.add_triggers(trigger)

st.test_create()
Example #3
0
        )
    )
    triggers.append(t)

# Notifications
nots = Table("notification")
nots.add_cols(
    Column("time").integer,
    Column("permanent").integer.not_null.default(0),
    Column("taskid").integer,
    Column("repeats").integer.not_null.default(0),
    Column("locationname").text,
    Column("latitude").real,
    Column("longitude").real,
    Column("radius").real,
)
nots.add_constraints(ForeignKey("taskid").references(tasks.name).on_delete_cascade)
tables.append(nots)

# Let's try to create the SQL
st = SQLTester()
st.add_tables(*tables)
st.add_triggers(*triggers)

st.test_create()

# g = Generator(path='./sample/src/com/example/appname/database/')
# g.add_tables(persons, log)
# g.add_triggers(trigger)
# g.write()
                         .add_constraints(Unique('firstname').on_conflict_replace)

log = Table('Log').add_cols(Column('pId').integer.not_null,
                        Column('firstname').text.not_null,
                        Column('lastname').text.not_null,
                        Column('bio').text.not_null,
                        Column('time').timestamp.default_current_timestamp)

# Create a trigger that keeps the log up to date
# I recommend using temp triggers unless you see a performance hit
trigger = Trigger('tr_log').temp.if_not_exists

# Here I have given the wrong table name on purpose. Notice that the sql
# creation will fail because there is no table named bob.
trigger.after.update_on("bob")
#trigger.after.update_on(log.name)

# Raw sql
trigger.do_sql("INSERT INTO {table} ({cols}) VALUES\
 ({oldcols})".format(table=log.name,
                     cols=log.list_column_names(exclude=['_id','time']),
                     oldcols=persons.list_column_names(exclude=[],
                                                       prefix="old.")))

# Let's try to create the SQL
st = SQLTester()
st.add_tables(persons, log)
st.add_triggers(trigger)

st.test_create()
deltrigger.after.delete_on(links.name)
deltrigger.do_sql("INSERT INTO {table} (sha, url, timestamp, deleted) VALUES\
 (old.sha, old.url, old.timestamp, 1)".format(table=synclinks.name))


intrigger = Trigger("tr_ins_link").temp.if_not_exists
intrigger.after.insert_on(links.name)
intrigger.do_sql("INSERT INTO {table} (sha, url, timestamp) \
VALUES (new.sha, new.url, new.timestamp)"\
                 .format(table=synclinks.name))

#uptrigger = Trigger("tr_upd_link").temp.if_not_exists
#uptrigger.after.update_on(links.name)
#uptrigger.do_sql("INSERT INTO {table} (sha, url, timestamp) \
#VALUES (new.sha, new.url, new.timestamp)"\
#                 .format(table=synclinks.name))
'''

s = SQLTester()
s.add_tables(links)
#s.add_triggers(deltrigger, intrigger)
s.test_create()

g = Generator(path='android-client/src/com/nononsenseapps/linksgcm/database',
              pkg='com.nononsenseapps.linksgcm.database')

g.add_tables(links)
#g.add_triggers(deltrigger, intrigger)

g.write()