Skip to content

Commit

Permalink
Merge pull request #433 from pymssql/saner-username-default
Browse files Browse the repository at this point in the history
Allow no username, password.

Fixes #402.
  • Loading branch information
ramiro committed Jun 22, 2016
2 parents 7409a2a + 44608bd commit 55e9e8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 15 additions & 7 deletions src/_mssql.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ cdef class MSSQLConnection:
self.column_names = None
self.column_types = None

def __init__(self, server="localhost", user="sa", password="",
def __init__(self, server="localhost", user=None, password=None,
charset='UTF-8', database='', appname=None, port='1433', tds_version=None, conn_properties=None):
log("_mssql.MSSQLConnection.__init__()")

Expand All @@ -564,15 +564,23 @@ cdef class MSSQLConnection:
appname = appname or "pymssql=%s" % __full_version__

# For Python 3, we need to convert unicode to byte strings
cdef bytes user_bytes = user.encode('utf-8')
cdef char *user_cstr = user_bytes
cdef bytes password_bytes = password.encode('utf-8')
cdef char *password_cstr = password_bytes
cdef bytes user_bytes
cdef char *user_cstr = NULL
if user is not None:
user_bytes = user.encode('utf-8')
user_cstr = user_bytes
cdef bytes password_bytes
cdef char *password_cstr = NULL
if password is not None:
password_bytes = password.encode('utf-8')
password_cstr = password_bytes
cdef bytes appname_bytes = appname.encode('utf-8')
cdef char *appname_cstr = appname_bytes

DBSETLUSER(login, user_cstr)
DBSETLPWD(login, password_cstr)
if user is not None:
DBSETLUSER(login, user_cstr)
if password is not None:
DBSETLPWD(login, password_cstr)
DBSETLAPP(login, appname_cstr)
if tds_version is not None:
DBSETLVERSION(login, _tds_ver_str_to_constant(tds_version))
Expand Down
6 changes: 3 additions & 3 deletions src/pymssql.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ cdef class Cursor:
"""
pass

def connect(server='.', user='', password='', database='', timeout=0,
def connect(server='.', user=None, password=None, database='', timeout=0,
login_timeout=60, charset='UTF-8', as_dict=False,
host='', appname=None, port='1433', conn_properties=None, autocommit=False, tds_version=None):
"""
Expand All @@ -587,9 +587,9 @@ def connect(server='.', user='', password='', database='', timeout=0,
:param server: database host
:type server: string
:param user: database user to connect as
:param user: database user to connect as. Default value: None.
:type user: string
:param password: user's password
:param password: user's password. Default value: None.
:type password: string
:param database: the database to initially connect to
:type database: string
Expand Down

0 comments on commit 55e9e8a

Please sign in to comment.