Beispiel #1
0
def update(user, database, table, format=None):
    require(user, database, 'write', format)
    _table = _get_table(user, database, table, format)
    unique = request.args.getlist('unique')
    if len(unique):
        require(user, database, 'delete', format)
    _table = _get_table(user, database, table, format)
    reader = read_request(request, format)
    try:
        for row in reader:
            if not len(row.keys()):
                continue
            if not _table.update_row(unique, row):
                _table.add_row(row)
    except NamingException, ne:
        raise WebstoreException('Invalid column name: %s' % ne.field,
                                format, state='error', code=400)
Beispiel #2
0
def upsert(user, database, table, format=None):
    require(user, database, 'write', format)
    try:
        db = db_factory.create(user, database)
    except NamingException, ne:
        raise WebstoreException('Invalid DB name: %s' % ne.field,
                format, state='error', code=400)
    try:
        _table = db[table]
    except NamingException, ne:
        raise WebstoreException('Invalid table name: %s' % ne.field,
                                format, state='error', code=400)
    unique = request.args.getlist('unique')
    if len(unique):
        require(user, database, 'delete', format)
    reader = read_request(request, format)
    new_count = 0
    try:
        for row in reader:
            if not len(row.keys()):
                continue
            if not _table.update_row(unique, row):
                _table.add_row(row)
            new_count += 1
    except StatementError, se:
        raise WebstoreException(unicode(se), format, state='error', 
                                code=400)
    except NamingException, ne:
        raise WebstoreException('Invalid column name: %s' % ne.field,
                                format, state='error', code=400)
    _table.commit()
Beispiel #3
0
def upsert(user, database, table, format=None):
    require(user, database, 'write', format)
    try:
        db = db_factory.create(user, database)
    except NamingException, ne:
        raise WebstoreException('Invalid DB name: %s' % ne.field,
                format, state='error', code=400)
    try:
        _table = db[table]
    except NamingException, ne:
        raise WebstoreException('Invalid table name: %s' % ne.field,
                                format, state='error', code=400)
    unique = request.args.getlist('unique')
    if len(unique):
        require(user, database, 'delete', format)
    reader = read_request(request, format)
    new_count = 0
    try:
        for row in reader:
            if not len(row.keys()):
                continue
            if not _table.update_row(unique, row):
                _table.add_row(row)
            new_count += 1
    except StatementError, se:
        raise WebstoreException(unicode(se), format, state='error', 
                                code=400)
    except NamingException, ne:
        raise WebstoreException('Invalid column name: %s' % ne.field,
                                format, state='error', code=400)
    _table.commit()