# -*- coding: utf-8 -*-
# 定义数据库相关操作

import sqlite3
from lib.gmssl.sm3 import sm3_hash

class DB:
	connection = None
	cursor = None
	def __init__(self, db_name):
		self.connection = sqlite3.connect(db_name, check_same_thread = False)
		self.cursor = self.connection.cursor()

	def __del__(self):
		self.connection.close()

	def GetUserData(self, uname):
		hashed_uname = sm3_hash(list(bytes(uname, "UTF-8")))
		result_set = self.cursor.execute("SELECT Data FROM User WHERE HashedName=?", (hashed_uname, ))
		data = result_set.fetchone()
		if data == None:
			return None
		return data[0]

	def NewUser(self, uname, encoded_udata):
		hashed_uname = sm3_hash(list(bytes(uname, "UTF-8")))
		self.cursor.execute("INSERT INTO User(HashedName, Data) VALUES(?, ?)", (hashed_uname, encoded_udata, ))
		self.connection.commit()

0bbb01bd00ce5592327a0aa11fe45d40585d4a2a
<mask token>


class DB:
    <mask token>
    <mask token>

    def __init__(self, db_name):
        self.connection = sqlite3.connect(db_name, check_same_thread=False)
        self.cursor = self.connection.cursor()
    <mask token>
    <mask token>

    def NewUser(self, uname, encoded_udata):
        hashed_uname = sm3_hash(list(bytes(uname, 'UTF-8')))
        self.cursor.execute('INSERT INTO User(HashedName, Data) VALUES(?, ?)',
            (hashed_uname, encoded_udata))
        self.connection.commit()

<mask token>


class DB:
    <mask token>
    <mask token>

    def __init__(self, db_name):
        self.connection = sqlite3.connect(db_name, check_same_thread=False)
        self.cursor = self.connection.cursor()

    def __del__(self):
        self.connection.close()
    <mask token>

    def NewUser(self, uname, encoded_udata):
        hashed_uname = sm3_hash(list(bytes(uname, 'UTF-8')))
        self.cursor.execute('INSERT INTO User(HashedName, Data) VALUES(?, ?)',
            (hashed_uname, encoded_udata))
        self.connection.commit()

<mask token>


class DB:
    connection = None
    cursor = None

    def __init__(self, db_name):
        self.connection = sqlite3.connect(db_name, check_same_thread=False)
        self.cursor = self.connection.cursor()

    def __del__(self):
        self.connection.close()

    def GetUserData(self, uname):
        hashed_uname = sm3_hash(list(bytes(uname, 'UTF-8')))
        result_set = self.cursor.execute(
            'SELECT Data FROM User WHERE HashedName=?', (hashed_uname,))
        data = result_set.fetchone()
        if data == None:
            return None
        return data[0]

    def NewUser(self, uname, encoded_udata):
        hashed_uname = sm3_hash(list(bytes(uname, 'UTF-8')))
        self.cursor.execute('INSERT INTO User(HashedName, Data) VALUES(?, ?)',
            (hashed_uname, encoded_udata))
        self.connection.commit()

import sqlite3
from lib.gmssl.sm3 import sm3_hash


class DB:
    connection = None
    cursor = None

    def __init__(self, db_name):
        self.connection = sqlite3.connect(db_name, check_same_thread=False)
        self.cursor = self.connection.cursor()

    def __del__(self):
        self.connection.close()

    def GetUserData(self, uname):
        hashed_uname = sm3_hash(list(bytes(uname, 'UTF-8')))
        result_set = self.cursor.execute(
            'SELECT Data FROM User WHERE HashedName=?', (hashed_uname,))
        data = result_set.fetchone()
        if data == None:
            return None
        return data[0]

    def NewUser(self, uname, encoded_udata):
        hashed_uname = sm3_hash(list(bytes(uname, 'UTF-8')))
        self.cursor.execute('INSERT INTO User(HashedName, Data) VALUES(?, ?)',
            (hashed_uname, encoded_udata))
        self.connection.commit()

# -*- coding: utf-8 -*-
# 定义数据库相关操作

import sqlite3
from lib.gmssl.sm3 import sm3_hash

class DB:
	connection = None
	cursor = None
	def __init__(self, db_name):
		self.connection = sqlite3.connect(db_name, check_same_thread = False)
		self.cursor = self.connection.cursor()

	def __del__(self):
		self.connection.close()

	def GetUserData(self, uname):
		hashed_uname = sm3_hash(list(bytes(uname, "UTF-8")))
		result_set = self.cursor.execute("SELECT Data FROM User WHERE HashedName=?", (hashed_uname, ))
		data = result_set.fetchone()
		if data == None:
			return None
		return data[0]

	def NewUser(self, uname, encoded_udata):
		hashed_uname = sm3_hash(list(bytes(uname, "UTF-8")))
		self.cursor.execute("INSERT INTO User(HashedName, Data) VALUES(?, ?)", (hashed_uname, encoded_udata, ))
		self.connection.commit()
