Problems with RODBC sqlSave, Error in odbcUpdate - sql

I am trying to insert my data into my SQL using RODBC
This is the code I am using:
sqlSave(
odbcChannel,
final,
tablename = "SRP_KAZ_Mega_Shipment_Plan",
rownames = FALSE,
colnames = FALSE,
safer = TRUE,
fast = TRUE,
append = TRUE,
varTypes = c(
филиал = "nvarchar(250)",
SKU = "nvarchar(250)",
Month = "datetime",
Volume = "float",
Feature = "nvarchar(250)",
Period = "nvarchar(250)"
)
)
And this is what I get:
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, :
missing columns in 'data'
I don't know what is wrong here, but whenever I run the exact same code and data on other computers it works perfectly fine.
Any ideas of what this might be will do.
Thanks

Related

Schema Length Validation Error on Python Dash DataTable

I am building a dashboard using python dash and have a requirement of datatable with multiple dropdowns. The dataframe is created one with groupby (multiple columns) and aggregation.
I have written the code as below:
'''
app = JupyterDash()
app.layout = html.Div(children = [html.H2('SPEND PLANNING',
style = {'background-color':'#C0C0C0',
'border': '5px solid',
'font-family':'Serif',
'font-size': 25,
'text-align':'center',
'margin':'auto',
'justify-content': 'space-evenly',
'width':'100%'
}),
html.H1(),
html.Div(children = [dcc.Dropdown(
id ='period-filter',
options = dict([{"label": i, "value": i} for i in s2['PERIOD'].unique()]),
value = s2['PERIOD'].max(),
multi = True,
searchable=True,
style = {'display':'inline-block','width':'48%','vertical-align':'top'},
clearable=False,
placeholder="Quarter"
)]),
html.H1(),
html.Div(children = [dcc.Dropdown(
id ='commodity-filter',
options = dict([{"label": i, "value": i} for i in s2['COMMODITY GROUP'].unique()]),
value = s2['COMMODITY GROUP'].max(),
multi = True,
searchable=True,
style = {'display':'inline-block','width':'48%'},
clearable=False,
placeholder= "Commodity Group"
)]),
html.H1(),
html.Div(children = [dt(
id = "datatable",
columns = [{"name": i, "id": i} for i in s2.columns],
editable = True,
data = s2.to_dict('records'),
multi = True
])
#app.callback(output = [Output("datatable", "data")],
inputs = [Input("period-filter", "value"),Input("commodity-filter","value")])
def display_table(comm,period):
filtered_df = s2.loc[(s2['COMMODITY GROUP'].eq('comm')) & (s2['PERIOD'].eq('period'))]
return filtered_df.to_dict('records')
if _name_ == "_main_":
app.run_server(debug=True)
'''
The error after running the script is below:
SchemaLengthValidationError: Schema: [<Output datatable.data>]
Path: ()
Expected length: 1
Received value of length 0:
[]
When I remove the [] from [Output("datatable", "data")] the error is gone, however the data in the table also disappears giving a blank table.
The dropdowns also do not show the values, instead shows only - value.
Please help me with the above.

How to query from "any"/"map" data type on Tarantool?

Following example from this answer. If I created map without index, how to query the inner value of the map?
box.schema.create_space('x', {format = {[1] = {'id', 'unsigned'}, [2] = {'obj', 'map'}}})
box.space.x:create_index('pk', {parts = {[1] = {field = 1, type = 'unsigned'}}})
box.space.x:insert({2, {text = 'second', timestamp = 123}}
box.execute [[ SELECT * FROM "x" ]]
-- [2, {'timestamp': 123, 'text': 'second'}]
How to fetch timestamp or text column directly from SQL without creating index?
Tried these but didn't work:
SELECT "obj.text" FROM "x"
SELECT "obj"."text" FROM "x"
SELECT "obj"["text"] FROM "x"
SELECT "obj"->"text" FROM "x"
You can register a Lua function to call it from SQL. The first example from our SQL + Lua manual shows exactly what you asked.
A bit simplified version of the example to explain the idea:
box.schema.func.create('GETFIELD', {
language = 'LUA',
returns = 'any',
body = [[
function(msgpack_value, field)
return require('msgpack').decode(msgpack_value)[field]
end]],
is_sandboxed = false,
param_list = {'string', 'string'},
exports = {'SQL'},
is_deterministic = true
})
After registration of the function you can call it from SQL:
tarantool> \set language sql
tarantool> select getfield("obj", 'text') from "x"
---
- metadata:
- name: COLUMN_1
type: any
rows:
- ['second']
...
tarantool> select getfield("obj", 'timestamp') from "x"
---
- metadata:
- name: COLUMN_1
type: any
rows:
- [123]
...
Differences from the example in the manual:
No hack with the global variable, but no dot syntax ('foo.bar.baz').
Exported only to SQL.
The return type is 'any': so it can be used for, say, the numeric 'timestamp' field. Downside: 'any' is reported in the result set metainformation.
(The idea suggested by Nikita Pettik, my teammate.)

CopyAllViews = false is being ignored by SMO

I want SMO to not script the views so I do this
var transfer = new Transfer(database)
{
CopyAllTables = true,
CopyAllDefaults = false,
CopyAllStoredProcedures = true,
CopyAllDatabaseTriggers = true,
CopyAllObjects = false,
CopyAllPartitionFunctions = false,
CopyAllPartitionSchemes = false,
CopyAllRoles = false,
CopyAllRules = true,
CopyAllSchemas = true,
CopyAllSqlAssemblies = false,
CopyAllSynonyms = false,
CopyAllUserDefinedAggregates = true,
CopyAllUserDefinedDataTypes = true,
CopyAllUserDefinedFunctions = true,
CopyAllUserDefinedTypes = true,
CopyAllUsers = false,
CopyAllViews = false,
Options =
{
WithDependencies = true,
DriAll = true,
Triggers = true,
Indexes = true,
SchemaQualifyForeignKeysReferences = true,
ExtendedProperties = true,
IncludeDatabaseRoleMemberships = false,
Permissions = true,
IncludeDatabaseContext = true
},
PreserveDbo = true,
};
transfer.ScriptTransfer()
but the views are still scripted.
I really want to be able to use transfer as it seems to be the only way to get the objects scripted in dependency order without writing more code. I set
"CopyAllObjects = false" because I thought maybe that was causing the rest of the options that I had set to be ignored, but it didn't seem to do any good.
My goal here is to script out the views separately because I have a database server with views that depend on each other and will need to use dependencywalker on the views in all databases to script them in dependency order.
Please help?
I didn't exactly fix it but ended up filtering out any lines with "create view" in them. so I just call
transfer.ScriptTransfer().Cast<string>().ToList()
unless I am missing something, a lot of these flags (like CopyAllUsers) in the options SMO seems to only honor when it feels like it. :( it's a shame when some options looks exactly like what I need but do not work.

Bluemix SQLDB Query - Can't figure out JSON Parameter Markings

In my Nodered Bluemix application, I'm trying to make a SqlDB query, but I can't find sufficient documentation or examples on how to use the parameter markings in the query. Are there any examples and further insight into what I am doing wrong? Here is the flow I am having trouble with:
[
{
"id":"7924a83a.03355",
"type":"websocket-listener",
"path":"/ws/dbdata",
"wholemsg":"false"
},
{
"id":"b84efad2.9a2a58",
"type":"function",
"name":"Parse JSON",
"func":"msg.payload = JSON.parse(msg.payload);\nvar begin = msg.payload[0].split(\" \");\nbegin[1] = begin[1]+\":00\";\nvar date1 = begin[0].split(\"-\");\nvar processStart = date1[2]+\"-\"+date1[0]+\"-\"+date1[1]+\" \"+begin[1];\n\nvar end = msg.payload[0].split(\" \");\nend[1] = end[1]+\":00\";\nvar date2 = end[0].split(\"-\");\nvar processEnd = date2[2]+\"-\"+date2[0]+\"-\"+date2[1]+\" \"+end[1];\n\nmsg.payload[0] = processStart;\nmsg.payload[1] = processEnd;\nreturn msg;",
"outputs":1,"noerr":0,"x":381.79998779296875,"y":164.8000030517578,"z":"3f9da5d2.b3f0aa",
"wires":[["4f92b16a.cf981"]]
},
{
"id":"3e20f8a4.06451",
"type":"websocket in",
"name":"dbInput",
"server":"7924a83a.03355",
"client":"",
"x":159.8000030517578,"y":164.8000030517578,"z":"3f9da5d2.b3f0aa",
"wires":[["b84efad2.9a2a58"]]
},
{
"id":"68a4a35.5983f5c",
"type":"debug",
"name":"",
"active":true,"console":"false",
"complete":"true",
"x":970.7999877929688,"y":162.8000030517578,"z":"3f9da5d2.b3f0aa",
"wires":[]
},
{
"id":"5a0aed1c.34279c",
"type":"sqldb in",
"service":"LabSensors-sqldb",
"query":"",
"params":"{msg.begin},{msg.end}",
"name":"db Request",
"x":787.7999877929688,"y":163.8000030517578,"z":"3f9da5d2.b3f0aa",
"wires":[["68a4a35.5983f5c"]]
},
{
"id":"e08c4a85.e95e68",
"type":"debug",
"name":"",
"active":true,"console":"false",
"complete":"true",
"x":791.7999877929688,"y":233.8000030517578,"z":"3f9da5d2.b3f0aa",
"wires":[]
},
{
"id":"4f92b16a.cf981",
"type":"function",
"name":"Construct Query",
"func":"msg.begin = msg.payload[0];\nmsg.end = msg.payload[1];\nmsg.payload = \"SELECT * FROM IOT WHERE TIME >= '?' AND TIME < '?'\";\nreturn msg;",
"outputs":1,"noerr":0,"x":583.7999877929688,"y":163.8000030517578,"z":"3f9da5d2.b3f0aa",
"wires":[["5a0aed1c.34279c",
"e08c4a85.e95e68"]]
}
]
In the node-red documentation for the SQLDB query node it says:
"Parameter Markers is a comma delimited set of json paths. These will replace any question marks that you place in your query, in the order that they appear."
Have you tried removing the curly braces, i.e. to set the "params" field in the node to just "msg.begin,msg.end"?
You just need remove single quotes this is a correct sentence:
msg.payload = "SELECT * FROM IOT WHERE TIME >= ? AND TIME < ?";

RStudio shiny datatables save csv unquoted?

How can I save the output of an RStudio Shiny DataTables table using the Save to CSV extension, but have the content saved unquoted instead of the default, which is in double-quotes:
For example, for a single column with two entries, I get a file.csv like this:
"column_name"
"foo"
"bar"
And instead I would like either:
column_name
foo
bar
Or even better, without the header:
foo
bar
My current code looks like this:
output$mytable <- renderDataTable({
entries()
}, options = list(colnames = NULL, bPaginate = FALSE,
"sDom" = 'RMDT<"cvclear"C><"clear">lfrtip',
"oTableTools" = list(
"sSwfPath" = "copy_csv_xls.swf",
"aButtons" = list(
"copy",
"print",
list("sExtends" = "collection",
"sButtonText" = "Save",
"aButtons" = list("csv","xls")
)
)
)
)
)
EDIT:
I tried with one of the suggested answers, and ajax is not allowed, the page complains when I click on SaveTXT. If I do the following, it still puts things within double quotes:
list("sExtends" = "collection",
"sButtonText" = "SaveTXT",
"sFieldBoundary" = '',
"aButtons" = list("csv")
Any ideas?
It should be possible through button options:Button options
And changing sFieldBoundary value.
$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [
{
"sExtends": "ajax",
"sFieldBoundary": '"'
}
]
}
} );
} );
But I couldn't get it working in shiny.