optional param for pre-determined column types to be supplied instead of guessing

This commit is contained in:
Paul Trowbridge 2021-03-15 15:40:43 -04:00
parent 605a1e95b0
commit fac0a38977

View File

@ -2374,7 +2374,7 @@ Function MISCe_col_to_letter(ByRef x As Long) As String
End Function 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 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_text As String
Dim strip_num As String Dim strip_num As String
Dim strip_date 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") Set rx = CreateObject("vbscript.regexp")
rx.Global = True rx.Global = True
@ -2396,40 +2404,48 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
strip_num = "[^0-9\.]" strip_num = "[^0-9\.]"
strip_date = "[^0-9\/\-\:\.]" strip_date = "[^0-9\/\-\:\.]"
ReDim type_flag(UBound(tbl, 1)) '------if a type flag array has been supplied copy its contents---------------
For j = 0 To UBound(tbl, 1) If UBound(typeflag) <> -1 Then
If IsNumeric(tbl(j, 1)) Then ReDim type_flag(UBound(typeflag))
If InStr(1, tbl(j, 1), ".") > 0 Then For i = 0 To UBound(typeflag)
type_flag(j) = "N" type_flag(i) = typeflag(i)
Else Next i
type_flag(j) = "S" Else
End If ReDim type_flag(UBound(tbl, 1))
Else For j = LBound(tbl, 1) To UBound(tbl, 1)
If Len(tbl(j, 1)) >= 6 Then If IsNumeric(tbl(j, LBound(tbl, 2) + 1)) Then
If IsDate(tbl(j, 1)) Then If InStr(1, tbl(j, 1), ".") > 0 Then
type_flag(j) = "D" type_flag(j) = "N"
Else Else
type_flag(j) = "S" type_flag(j) = "S"
End If End If
Else Else
type_flag(j) = "S" If Len(tbl(j, 1)) >= 6 Then
If IsDate(tbl(j, 1)) Then
type_flag(j) = "D"
Else
type_flag(j) = "S"
End If
Else
type_flag(j) = "S"
End If
End If End If
End If Next j
Next j End If
rx.Pattern = strip_text rx.Pattern = strip_text
If headers Then If headers Then
start_row = 1 start_row = LBound(tbl, 2) + 1
For i = 0 To UBound(tbl, 1) For i = LBound(tbl, 1) To UBound(tbl, 1)
If i > 0 Then col_name = col_name & "," If i > LBound(tbl, 1) Then col_name = col_name & ","
If quote_headers Then 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 Else
col_name = col_name & rx.Replace(tbl(i, 0), "") col_name = col_name & rx.Replace(tbl(i, LBound(tbl, 2)), "")
End If End If
Next i Next i
Else Else
start_row = 0 start_row = LBound(tbl, 2)
End If End If
@ -2437,8 +2453,8 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
rec = "" rec = ""
If i <> start_row Then sql = sql & "," & vbCrLf If i <> start_row Then sql = sql & "," & vbCrLf
rec = rec & "(" rec = rec & "("
For j = 0 To UBound(tbl, 1) For j = LBound(tbl, 1) To UBound(tbl, 1)
If j <> 0 Then rec = rec & "," If j <> LBound(tbl, 1) Then rec = rec & ","
Select Case type_flag(j) Select Case type_flag(j)
Case "N" '-------N = numeric but should probably be N for numeric---- Case "N" '-------N = numeric but should probably be N for numeric----
rx.Pattern = strip_num 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------------------------------------------ Case "S" '-------S = string------------------------------------------
rx.Pattern = strip_text rx.Pattern = strip_text
If LTrim(RTrim(tbl(j, i))) = "" Then If LTrim(RTrim(tbl(j, i))) = "" Then
rec = rec & "CAST(NULL AS VARCHAR(255))" rec = rec & "CAST(NULL AS " & nullText & ")"
Else Else
If trim Then If trim Then
rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'" 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------------------------------------------ Case Else '-------Assume text------------------------------------------
rx.Pattern = strip_text rx.Pattern = strip_text
If LTrim(RTrim(tbl(j, i))) = "" Then If LTrim(RTrim(tbl(j, i))) = "" Then
rec = rec & "CAST(NULL AS VARCHAR(255))" rec = rec & "CAST(NULL AS " & nullText & ")"
Else Else
If trim Then If trim Then
rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'" rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'"