def _runQuery(): sliceEnv = SliceEnv() custDB = sliceEnv.open(_getInput('Enter Database Name')) if custDB == None: return columns = _getInput('Enter the list of columns to be displayed separated by the symbol "|"').split('|') conditionAttributes = _getInput('Enter the column, condition and the literal value separated by the symbol "|"').split('|') if(len(conditionAttributes) == 3): condition = SliceCondition(conditionAttributes[0], conditionAttributes[1], conditionAttributes[2]) else: print 'Error: Condition format should be column_name|operation|literal_value' return custQuery = SliceQuery(columns, custDB, condition) sliceRecords = custDB.query(custQuery) if(sliceRecords == None): return output = " " for column in columns: output += column + " " print output for record in sliceRecords: output = " " for column in columns: output += record._getValue(column) + " " print output sliceEnv.close("CustDB")
def _bulkLoad(): sliceEnv = SliceEnv() custDB = sliceEnv.open(_getInput('Enter Database Name')) if custDB == None: return print 'Only accepts file with .apd extension' custDB.load(_getInput('Enter Upload File Name (without .apd)')) sliceEnv.close("CustDB")
def _report2(): sliceEnv = SliceEnv() custDB = sliceEnv.open("CustDB") salseDB = sliceEnv.open("SalesDB") orderDB = sliceEnv.open("OrderDB") join_database = custDB.join(salseDB, "cust") if(join_database == None): return join_database = orderDB.join(salseDB, "order") if(join_database == None): return subprocess.check_call(["runhaskell", "report2"])
def _updateRecord(): sliceEnv = SliceEnv() custDB = sliceEnv.open(_getInput('Enter Database Name')) if custDB == None: return custRecord = custDB.createRecord() for field in custRecord.record: if custRecord.getFieldType(field[0], custDB.schema) == DBSlice.INT: custRecord.setInt(field[0], _processInteger('Enter ' + field[0])) elif custRecord.getFieldType(field[0], custDB.schema) == DBSlice.DOUBLE: custRecord.setDouble(field[0], _processFloat('Enter ' + field[0])) elif custRecord.getFieldType(field[0], custDB.schema) == DBSlice.STRING: custRecord.setString(field[0], _getInput('Enter ' + field[0])) custDB.update(custRecord) sliceEnv.close("CustDB")
def _deleteRecord(): sliceEnv = SliceEnv() custDB = sliceEnv.open(_getInput('Enter Database Name')) if custDB == None: return if custDB.index == None: print "Error: Cannot perform deletion on database without index" return keyValue = _processInteger('Enter ' + custDB.index) for i, record in enumerate(custDB.database): if int(record.getFieldValue(custDB.index)) == keyValue: custDB.database.pop(i) sliceEnv.close("CustDB") print "Record Deleted" return i = i + 1 print "Error: Record does not exist"
def _createDatabase(): dataabaseName = _getInput('Enter Database Name') count = _processInteger('Enter Number of Fields') schemaElements = [] i = 0 while i < count: field_name = _getInput('Enter Field Name') if _checkIfAlreadyExists(field_name, schemaElements): print "Error: Field name already exits" else: while True: print ("\nChoose Field Type\n" + "1. INT\n" + "2. DOUBLE\n" + "3. STRING\n") client_input = _getInput('Select') if(client_input == '1'): field_type = DBSlice.INT break elif(client_input == '2'): field_type = DBSlice.DOUBLE break elif(client_input == '3'): field_type = DBSlice.STRING break else: print "Error: Invalid input" schemaElements.append(SliceField(field_name, field_type)) i = i + 1 indexNotGood = True while indexNotGood: index = _getInput('Enter Index Name (Optional, INT Type)') if index == '': indexNotGood = False for field in schemaElements: if field.name == index and field.type == DBSlice.INT: indexNotGood = False if index == '': index = None sliceEnv = SliceEnv() sliceEnv.createDB(dataabaseName, schemaElements, index)
def _displayJoin(): sliceEnv = SliceEnv() custDB = sliceEnv.open(_getInput('Enter First Database Name')) if custDB == None: return salesDB = sliceEnv.open(_getInput('Enter Second Database Name')) if salesDB == None: return join_column = _getInput('Enter the join column') join_database = [] if(join_column == ''): join_database = custDB.join(salesDB) else: join_database = custDB.join(salesDB, join_column) if(join_database != None): print "You can find the join database in the file " + custDB.name + salesDB.name + ".join" sliceEnv.close("SalesDB") sliceEnv.close("CustDB")
''' Created on Aug 21, 2014 @author: Mehrdad Dehdashti ''' from SliceDBMS.SliceEnv import SliceEnv from SliceDBMS.SliceDB import SliceDB from SliceDBMS.SliceRecord import SliceRecord if __name__ == '__main__': sliceEnv = SliceEnv() custDB = sliceEnv.open("CustDB") custRecord = custDB.get(298) if(custRecord): print "Name " + custRecord.getString("name") print "Age " + custRecord.getInt("age") print "Address " + custRecord.getString("address") sliceEnv.close("CustDB")
''' Created on Aug 21, 2014 @author: Mehrdad Dehdashti ''' from SliceDBMS.SliceEnv import SliceEnv from SliceDBMS.SliceDB import SliceDB from SliceDBMS.SliceRecord import SliceRecord if __name__ == '__main__': sliceEnv = SliceEnv() custDB = sliceEnv.open("CustDB") salseDB = sliceEnv.open("SalesDB") joinList = custDB.join(salseDB) for record in joinList: name = record.getString("name") total = record.getDouble("total") print "Sales for " + name + ": " + total sliceEnv.close("SalesDB") sliceEnv.close("CustDB")
''' Created on Aug 12, 2014 @author: Mehrdad Dehdashti ''' from SliceDBMS import DBSlice from SliceDBMS.SliceEnv import SliceEnv from SliceDBMS.SliceField import SliceField if __name__ == '__main__': schemaElements = [ SliceField("cust", DBSlice.INT), SliceField("name", DBSlice.STRING), SliceField("age", DBSlice.INT), SliceField("phone", DBSlice.STRING), SliceField("address", DBSlice.STRING) ] sliceEnv = SliceEnv() sliceEnv.createDB("CustDB", schemaElements, "cust")