optional param for pre-determined column types to be supplied instead of guessing
This commit is contained in:
parent
605a1e95b0
commit
fac0a38977
@ -2374,7 +2374,7 @@ Function MISCe_col_to_letter(ByRef x As Long) As String
|
||||
End Function
|
||||
|
||||
|
||||
Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, headers As Boolean, syntax As SQLsyntax, ByRef quote_headers As Boolean) As String
|
||||
Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, headers As Boolean, syntax As SQLsyntax, ByRef quote_headers As Boolean, ParamArray typeflag()) As String
|
||||
|
||||
|
||||
Dim i As Long
|
||||
@ -2388,6 +2388,14 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
||||
Dim strip_text As String
|
||||
Dim strip_num As String
|
||||
Dim strip_date As String
|
||||
Dim nullText As String
|
||||
|
||||
If syntax = PostgreSQL Then
|
||||
nullText = "text"
|
||||
Else
|
||||
nullText = "varchar(255)"
|
||||
End If
|
||||
|
||||
|
||||
Set rx = CreateObject("vbscript.regexp")
|
||||
rx.Global = True
|
||||
@ -2396,9 +2404,16 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
||||
strip_num = "[^0-9\.]"
|
||||
strip_date = "[^0-9\/\-\:\.]"
|
||||
|
||||
'------if a type flag array has been supplied copy its contents---------------
|
||||
If UBound(typeflag) <> -1 Then
|
||||
ReDim type_flag(UBound(typeflag))
|
||||
For i = 0 To UBound(typeflag)
|
||||
type_flag(i) = typeflag(i)
|
||||
Next i
|
||||
Else
|
||||
ReDim type_flag(UBound(tbl, 1))
|
||||
For j = 0 To UBound(tbl, 1)
|
||||
If IsNumeric(tbl(j, 1)) Then
|
||||
For j = LBound(tbl, 1) To UBound(tbl, 1)
|
||||
If IsNumeric(tbl(j, LBound(tbl, 2) + 1)) Then
|
||||
If InStr(1, tbl(j, 1), ".") > 0 Then
|
||||
type_flag(j) = "N"
|
||||
Else
|
||||
@ -2416,20 +2431,21 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
||||
End If
|
||||
End If
|
||||
Next j
|
||||
End If
|
||||
|
||||
rx.Pattern = strip_text
|
||||
If headers Then
|
||||
start_row = 1
|
||||
For i = 0 To UBound(tbl, 1)
|
||||
If i > 0 Then col_name = col_name & ","
|
||||
start_row = LBound(tbl, 2) + 1
|
||||
For i = LBound(tbl, 1) To UBound(tbl, 1)
|
||||
If i > LBound(tbl, 1) Then col_name = col_name & ","
|
||||
If quote_headers Then
|
||||
col_name = col_name & """" & rx.Replace(tbl(i, 0), "") & """"
|
||||
col_name = col_name & """" & rx.Replace(tbl(i, LBound(tbl, 2)), "") & """"
|
||||
Else
|
||||
col_name = col_name & rx.Replace(tbl(i, 0), "")
|
||||
col_name = col_name & rx.Replace(tbl(i, LBound(tbl, 2)), "")
|
||||
End If
|
||||
Next i
|
||||
Else
|
||||
start_row = 0
|
||||
start_row = LBound(tbl, 2)
|
||||
End If
|
||||
|
||||
|
||||
@ -2437,8 +2453,8 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
||||
rec = ""
|
||||
If i <> start_row Then sql = sql & "," & vbCrLf
|
||||
rec = rec & "("
|
||||
For j = 0 To UBound(tbl, 1)
|
||||
If j <> 0 Then rec = rec & ","
|
||||
For j = LBound(tbl, 1) To UBound(tbl, 1)
|
||||
If j <> LBound(tbl, 1) Then rec = rec & ","
|
||||
Select Case type_flag(j)
|
||||
Case "N" '-------N = numeric but should probably be N for numeric----
|
||||
rx.Pattern = strip_num
|
||||
@ -2450,7 +2466,7 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
||||
Case "S" '-------S = string------------------------------------------
|
||||
rx.Pattern = strip_text
|
||||
If LTrim(RTrim(tbl(j, i))) = "" Then
|
||||
rec = rec & "CAST(NULL AS VARCHAR(255))"
|
||||
rec = rec & "CAST(NULL AS " & nullText & ")"
|
||||
Else
|
||||
If trim Then
|
||||
rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'"
|
||||
@ -2469,7 +2485,7 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
||||
Case Else '-------Assume text------------------------------------------
|
||||
rx.Pattern = strip_text
|
||||
If LTrim(RTrim(tbl(j, i))) = "" Then
|
||||
rec = rec & "CAST(NULL AS VARCHAR(255))"
|
||||
rec = rec & "CAST(NULL AS " & nullText & ")"
|
||||
Else
|
||||
If trim Then
|
||||
rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'"
|
||||
|
Loading…
Reference in New Issue
Block a user