Esempio n. 1
0
 def dropDB(self, db):
     if not self.sdk:
         return False, "please init driver first"
     status = sql_router_sdk.Status()
     if self.sdk.DropDB(db, status):
         return True, "ok"
     else:
         return False, status.msg
Esempio n. 2
0
 def getRequestBuilder(self, db, sql):
     if not self.sdk:
         return False, "please init driver first"
     status = sql_router_sdk.Status()
     row_builder = self.sdk.GetRequestRow(db, sql, status)
     if status.code != 0:
         return False, status.msg
     return True, row_builder
Esempio n. 3
0
 def executeDDL(self, db, ddl):
     if not self.sdk:
         return False, "please init driver first"
     status = sql_router_sdk.Status()
     if not self.sdk.ExecuteDDL(db, ddl, status):
         return False, status.msg
     else:
         self.sdk.RefreshCatalog()
         return True, "ok"
Esempio n. 4
0
    def executeQueryParameterized(self, db, sql, row_builder):
        if not self.sdk:
            return False, "please init driver first"

        if not row_builder:
            return False, "pealse init parameter row"

        status = sql_router_sdk.Status()
        rs = self.sdk.ExecuteSQLParameterized(db, sql, row_builder, status)
        if status.code != 0:
            return False, status.msg
        else:
            return True, rs
Esempio n. 5
0
    def executeQuery(self, db, sql, row_builder = None):
        if not self.sdk:
            return False, "please init driver first"

        status = sql_router_sdk.Status()
        if row_builder is not None:
            rs = self.sdk.ExecuteSQLRequest(db, sql, row_builder, status)
        else:
            rs = self.sdk.ExecuteSQL(db, sql, status)
        if status.code != 0:
            return False, status.msg
        else:
            return True, rs
Esempio n. 6
0
 def executeInsert(self, db, sql, row_builder = None):
     if not self.sdk:
         return False, "please init driver first"
     status = sql_router_sdk.Status()
     if row_builder is not None:
         if self.sdk.ExecuteInsert(db, sql, row_builder, status):
             return True, ""
         else:
             return False, status.msg
     else:
         if self.sdk.ExecuteInsert(db, sql, status):
             return True, ""
         else:
             return False, status.msg
Esempio n. 7
0
 def doBatchRowRequest(self, db, sql, commonCol, parameters):
     ok, requestRow = self.getRequestBuilder(db, sql)
     if not ok:
         return ok, "get request builder fail"
     schema = requestRow.GetSchema()
     commonCols = sql_router_sdk.ColumnIndicesSet(schema)
     count = schema.GetColumnCnt()
     commnColAddCount = 0
     for i in range(count):
         colName = schema.GetColumnName(i)
         if colName in commonCol:
             commonCols.AddCommonColumnIdx(i)
             commnColAddCount+=1
     if commnColAddCount != len(commonCol):
         return False, "some common col is not in table schema"
     requestRowBatch = sql_router_sdk.SQLRequestRowBatch(schema, commonCols)
     if requestRowBatch is None:
         return False, "generate sql request row batch fail"
     if isinstance(parameters, dict):
         ok, msg = self._append_request_row(requestRow, schema, parameters)
         if not ok:
             return ok, msg
         requestRowBatch.AddRow(requestRow)
     else:
         for d in parameters:
             ok, msg = self._append_request_row(requestRow, schema, d)
             if not ok:
                 return ok, msg
             requestRowBatch.AddRow(requestRow)
             ok, requestRow = self.getRequestBuilder(db, sql)
             if not ok:
                 return ok, "get request builder fail"
     status = sql_router_sdk.Status()
     rs = self.sdk.ExecuteSQLBatchRequest(db, sql, requestRowBatch, status)
     if status.code != 0:
         return False, status.msg
     return True, rs
Esempio n. 8
0
 def callProc(self, db, sp, rq):
     status = sql_router_sdk.Status()
     rs = self.sdk.CallProcedure(db, sp, rq, status)
     if status.code != 0:
         return False, status.msg
     return True, rs
Esempio n. 9
0
 def getRowBySp(self, db, sp):
     status = sql_router_sdk.Status()
     row_builder = self.sdk.GetRequestRowByProcedure(db, sp, status)
     if status.code != 0:
         return False, status.msg
     return True, row_builder