This commit is contained in:
yumoqing 2021-01-03 04:36:27 +00:00
parent 8cfed2cb9d
commit 63a4e89a7e
6 changed files with 34 additions and 9 deletions

20
docs/postgresql.md Normal file
View File

@ -0,0 +1,20 @@
# POSTGRESQL
## create database
create database testdb;
## create user
create role guest with login;
## grat privileges
grant all privileges on database testdb to guest;
### grant table privileges
psql -d testdb
grant all privileges on all tables in schema public to guest;

View File

@ -5,4 +5,6 @@ class AioPostgresqlor(PostgreSQLor):
def isMe(self,name): def isMe(self,name):
return name=='aiopg' return name=='aiopg'
async def commit(self):
pass

View File

@ -256,7 +256,10 @@ class DBPools:
await p.release(conn) await p.release(conn)
""" """
if self.isAsyncDriver(dbname): if self.isAsyncDriver(dbname):
await cur.close() try:
await cur.close()
except:
pass
else: else:
try: try:
cur.fetchall() cur.fetchall()

View File

@ -4,7 +4,7 @@ VARCHAR({{len}})
{%- elif type=='char' -%} {%- elif type=='char' -%}
CHAR({{len}}) CHAR({{len}})
{%- elif type=='long' or type=='int' or type=='short' -%} {%- elif type=='long' or type=='int' or type=='short' -%}
INTEGER NUMERIC(30,0)
{%- elif type=='float' or type=='double' or type=='ddouble' -%} {%- elif type=='float' or type=='double' or type=='ddouble' -%}
NUMERIC({{len}},{{dec}}) NUMERIC({{len}},{{dec}})
{%- elif type=='date' -%} {%- elif type=='date' -%}

View File

@ -38,7 +38,7 @@ class PostgreSQLor(SQLor):
} }
@classmethod @classmethod
def isMe(self,name): def isMe(self,name):
return name=='psycopg2' or name=='aiopg' or name=='pyguass' return name=='psycopg2' or name=='pyguass'
def grammar(self): def grammar(self):
return { return {
@ -48,13 +48,13 @@ class PostgreSQLor(SQLor):
def placeHolder(self,varname,i): def placeHolder(self,varname,i):
if varname=='__mainsql__' : if varname=='__mainsql__' :
return '' return ''
return '$%d' % i return '%%(%s)s' % varname
def dataConvert(self,dataList): def dataConvert(self,dataList):
x = super().dataConvert(dataList) if type(dataList) == type({}):
if x == []: return dataList
return None d = { i['name']:i['value'] for i in dataList }
return x return d
def pagingSQLmodel(self): def pagingSQLmodel(self):
return u"""select * return u"""select *

View File

@ -201,7 +201,7 @@ class SQLor(object):
using a opened cursor to run a SQL statment with variable, the variable is setup in NS namespace using a opened cursor to run a SQL statment with variable, the variable is setup in NS namespace
return a cursor with data return a cursor with data
""" """
markedSQL,datas = self.maskingSQL(sql,NS) markedSQL, datas = self.maskingSQL(sql,NS)
datas = self.dataConvert(datas) datas = self.dataConvert(datas)
try: try:
if self.async_mode: if self.async_mode: