Skip to content

Commit 018d539

Browse files
Mark Songhurstalexbrainman
Mark Songhurst
authored andcommitted
Replaced more panic calls with returned error
1 parent bfee230 commit 018d539

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

column.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ func NewColumn(h api.SQLHSTMT, idx int) (Column, error) {
9090
var v api.SQLGUID
9191
return NewBindableColumn(b, api.SQL_C_GUID, int(unsafe.Sizeof(v))), nil
9292
case api.SQL_CHAR, api.SQL_VARCHAR:
93-
return NewVariableWidthColumn(b, api.SQL_C_CHAR, size), nil
93+
return NewVariableWidthColumn(b, api.SQL_C_CHAR, size)
9494
case api.SQL_WCHAR, api.SQL_WVARCHAR:
95-
return NewVariableWidthColumn(b, api.SQL_C_WCHAR, size), nil
95+
return NewVariableWidthColumn(b, api.SQL_C_WCHAR, size)
9696
case api.SQL_BINARY, api.SQL_VARBINARY:
97-
return NewVariableWidthColumn(b, api.SQL_C_BINARY, size), nil
97+
return NewVariableWidthColumn(b, api.SQL_C_BINARY, size)
9898
case api.SQL_LONGVARCHAR:
99-
return NewVariableWidthColumn(b, api.SQL_C_CHAR, 0), nil
99+
return NewVariableWidthColumn(b, api.SQL_C_CHAR, 0)
100100
case api.SQL_WLONGVARCHAR, api.SQL_SS_XML:
101-
return NewVariableWidthColumn(b, api.SQL_C_WCHAR, 0), nil
101+
return NewVariableWidthColumn(b, api.SQL_C_WCHAR, 0)
102102
case api.SQL_LONGVARBINARY:
103-
return NewVariableWidthColumn(b, api.SQL_C_BINARY, 0), nil
103+
return NewVariableWidthColumn(b, api.SQL_C_BINARY, 0)
104104
default:
105105
return nil, fmt.Errorf("unsupported column type %d", sqltype)
106106
}
@@ -199,10 +199,10 @@ func NewBindableColumn(b *BaseColumn, ctype api.SQLSMALLINT, bufSize int) *Binda
199199
return c
200200
}
201201

202-
func NewVariableWidthColumn(b *BaseColumn, ctype api.SQLSMALLINT, colWidth api.SQLULEN) Column {
202+
func NewVariableWidthColumn(b *BaseColumn, ctype api.SQLSMALLINT, colWidth api.SQLULEN) (Column, error) {
203203
if colWidth == 0 || colWidth > 1024 {
204204
b.CType = ctype
205-
return &NonBindableColumn{b}
205+
return &NonBindableColumn{b}, nil
206206
}
207207
l := int(colWidth)
208208
switch ctype {
@@ -214,11 +214,11 @@ func NewVariableWidthColumn(b *BaseColumn, ctype api.SQLSMALLINT, colWidth api.S
214214
case api.SQL_C_BINARY:
215215
// nothing to do
216216
default:
217-
panic(fmt.Errorf("do not know how wide column of ctype %d is", ctype))
217+
return nil, fmt.Errorf("do not know how wide column of ctype %d is", ctype)
218218
}
219219
c := NewBindableColumn(b, ctype, l)
220220
c.IsVariableWidth = true
221-
return c
221+
return c, nil
222222
}
223223

224224
func (c *BindableColumn) Bind(h api.SQLHSTMT, idx int) (bool, error) {
@@ -242,7 +242,7 @@ func (c *BindableColumn) Value(h api.SQLHSTMT, idx int) (driver.Value, error) {
242242
return nil, nil
243243
}
244244
if !c.IsVariableWidth && int(c.Len) != c.Size {
245-
panic(fmt.Errorf("wrong column #%d length %d returned, %d expected", idx, c.Len, c.Size))
245+
return nil, fmt.Errorf("wrong column #%d length %d returned, %d expected", idx, c.Len, c.Size)
246246
}
247247
return c.BaseColumn.Value(c.Buffer[:c.Len])
248248
}

error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewError(apiName string, handle interface{}) error {
5858
break
5959
}
6060
if IsError(ret) {
61-
panic(fmt.Errorf("SQLGetDiagRec failed: ret=%d", ret))
61+
return fmt.Errorf("SQLGetDiagRec failed: ret=%d", ret)
6262
}
6363
r := DiagRecord{
6464
State: api.UTF16ToString(state),

0 commit comments

Comments
 (0)