def executeDelete(data): if not catalogManager.existTable(data['from']): return { 'status': 'error', 'payload': 'Table ' + data['tableName'] + ' does not exist' } return recordManager.delete(data['from'], data['where'])
def executeDropTable(data): if not catalogManager.existTable(data['tableName']): return { 'status': 'error', 'payload': 'Table ' + data['tableName'] + ' does not exist' } indices = catalogManager.getIndexList(data['tableName']) for index in indices: result = indexManager.dropIndex(index[0]) if result['status'] == 'error': return result result = catalogManager.dropIndex(index[0]) if result['status'] == 'error': return result result = recordManager.dropTable(data['tableName']) if result['status'] == 'error': return result return catalogManager.dropTable(data['tableName'])
def executeSelect(data): if not catalogManager.existTable(data['from']): return { 'status': 'error', 'payload': 'Table ' + data['from'] + ' does not exist' } fieldList = catalogManager.getFieldsList(data['from']) fields = [] for f in fieldList: fields.append(f['name']) head = [] if '*' in data['fields']: head = fields else: for field in data['fields']: if field in fields: head.append(field) else: return { 'status': 'error', 'payload': 'Field ' + field + ' does not exist' } if data['orderBy'] is not None: orderByFieldNo = catalogManager.getFieldNumber(data['from'], data['orderBy']) if orderByFieldNo == -1: return { 'status': 'error', 'payload': 'Field ' + data['fieldName'] + ' does not exist' } else: orderByFieldNo = None result = recordManager.select(data['from'], data['fields'], data['where'], orderByFieldNo, data['limit']) if result['status'] == 'error': return result return { 'status': 'success', 'payload': { 'head': head, 'body': result['payload'] } }
def executeCreateTable(data): if catalogManager.existTable(data['tableName']): return { 'status': 'error', 'payload': 'Table ' + data['tableName'] + ' already exists' } fields = data['fields'] for field in fields: if field['name'] == data[ 'primaryKey']: # auto set primary key to unique field['unique'] = True result = recordManager.createTable(data['tableName']) if result['status'] == 'error': return result result = catalogManager.createTable(data['tableName'], data['primaryKey'], fields) if result['status'] == 'error': return result # catalogManager.createIndex('auto$' + data['tableName'] + '$' + field['name'], data['tableName'],columnCount) columnCount = 0 for field in fields: if field['unique']: result = catalogManager.createIndex( 'auto$' + data['tableName'] + '$' + field['name'], data['tableName'], columnCount) if result['status'] == 'error': return result columnCount += 1 columnCount = 0 for field in fields: if field['unique']: result = indexManager.createIndex( 'auto$' + data['tableName'] + '$' + field['name'], data['tableName'], columnCount) if result['status'] == 'error': return result columnCount += 1 return {'status': 'success', 'payload': None}
def executeInsert(data): if not catalogManager.existTable(data['tableName']): return {'status': 'error', 'payload': 'Table does not exist'} return recordManager.insert(data['tableName'], data['values'])