我正在尝试编写一个代码来解析一个类中的某些数据,然后将解析后的数据插入到其他类的sqlite DB(以及其他任务)中。
我创建了一个sqlite类:
USE [Database]
DECLARE @name sysname
DECLARE @cntAll int
DECLARE @cntDist int
DECLARE @cntNull int
DECLARE @err int
DECLARE @stm nvarchar(max)
DECLARE @tblName sysname
SET @tblName = 'Table'
-- All rows
SET @stm = N'SELECT @cntAll = COUNT(*) FROM dbo.[' + @tblName + ']'
EXEC @err = sp_executesql @stm, N'@cntAll int OUTPUT', @cntAll OUTPUT
IF @err <> 0 BEGIN
RETURN
END
-- Distinct rows by column
DECLARE columns_tables CURSOR GLOBAL FORWARD_ONLY READ_ONLY FOR
SELECT [name] FROM sys.columns WHERE object_id = OBJECT_ID('dbo.[' + @tblName + ']')
OPEN columns_tables
FETCH NEXT FROM columns_tables INTO @name
WHILE (@@FETCH_STATUS = 0) BEGIN
SET @stm =
N'SELECT @cntDist = COUNT(DISTINCT [' + @name + ']) '+
'FROM dbo.[' + @tblName + '] '+
'WHERE [' + @name + '] IS NOT NULL'
EXEC @err = sp_executesql @stm, N'@cntDist int OUTPUT', @cntDist OUTPUT
IF @err <> 0 BEGIN
CLOSE columns_tables
DEALLOCATE columns_tables
BREAK
END
SET @stm =
N'IF EXISTS (' +
'SELECT ([' + @name + ']) '+
'FROM dbo.[' + @tblName + '] '+
'WHERE [' + @name + '] IS NULL'+
') SET @cntNull = 1 '+
'ELSE SET @cntNull = 0'
EXEC @err = sp_executesql @stm, N'@cntNull int OUTPUT', @cntNull OUTPUT
IF @err <> 0 BEGIN
CLOSE columns_tables
DEALLOCATE columns_tables
BREAK
END
IF (@cntAll = @cntDist) AND (@cntNull = 0) BEGIN
PRINT 'Possible column ' + @name
END
FETCH NEXT FROM columns_tables INTO @name
END
CLOSE columns_tables
DEALLOCATE columns_tables
????????
我需要将一些已解析的数据传递给DB_MNG.db_opertaor并相应地更新表格...
答案 0 :(得分:0)
试试这个:
class Test1():
def f1(self):
print('Test1->f1()')
class Test2():
def __init__(self):
self.obj1 = Test1()
self.obj1.f1()
首先创建类Test1,然后在类Test2中创建我创建Test1类的对象。
然后在从Test2类创建对象期间,您可以从第一个类运行方法:
obj2 = Test2()
>> Test1->f1()