フィルターのクリア

[database fast/insert] If exdata a struct, values must be scalars?

1 回表示 (過去 30 日間)
David Goldsmith
David Goldsmith 2012 年 1 月 6 日
Hi! I appear to have run into an, as near as I can tell, undocumented "feature" of the Database Toolbox fastinsert and insert functions: if the exdata argument--containing the data one wants to insert--is a struct, then the values have to have size==[1, 1]? Here's all the help says about exdata being a struct: "If exdata is a structure, field names in the structure must exactly match colnames"; I don't see any Examples where exdata is a struct. When I try to fast/insert a struct like struct('a', {'F'}, 'b', [5]) it works fine, but if I change it to struct('a', {'F', 'G'}, 'b', [5 6]), I get a "Too many input arguments" error; this is true regardless of the arrangement (i.e., horizontal or vertical) of the arrays, and regardless of the kind (i.e., "regular" or cell) of the latter array (obviously, in order for 'F' & 'G' to remain distinct, their contianing array must be of the cell variety). My question is, am I doing something wrong (fast/insert appear to support arrays for exdata as long as they're not contained w/in a struct), or is this indeed a "feature" of using a struct for exdata w/ the fast/insert functions? Thanks!
  2 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 1 月 6 日
Please post the full syntax you used and the full error message.
David Goldsmith
David Goldsmith 2012 年 1 月 6 日
insert(conn, tablename, {'a', 'b'}, struct('a', {'F', 'G'}, 'b', [5 6]))
Error using size
Too many input arguments.
Error in database/insert (line 61)
numberOfRows = size(data.(sflds{1}),1);
Error in Insert_dev/tryInsert (line 297)
insert(conn, tablename, {'a', 'b'}, struct('a',{'F', 'G'}, 'b', [5 6]))
Error in Insert_dev/submitStatement (line 257)
success = obj.tryInsert(@insert);

サインインしてコメントする。

採用された回答

David Hruska
David Hruska 2012 年 1 月 9 日
Database Toolbox's insert and fastinsert should work with structures containing multiple rows. I think the issue is in this statement:
struct('a', {'F', 'G'}, 'b', [5 6])
This creates a 1x2 array of structures, rather than a scalar structure whose fields contain vectors of data. I believe the following should do the trick:
insert(conn, tablename, {'a', 'b'}, struct('a', {{'F'; 'G'}}, 'b', {[5; 6]}))
Please see the documentation for struct for details: http://www.mathworks.com/help/techdoc/ref/struct.html
  1 件のコメント
David Goldsmith
David Goldsmith 2012 年 1 月 9 日
Yeah, I figured this out--again (I forgot that I had had this same problem--and had figured out the same solution--previously). What a PITA API! God I wish I could use Python for what I'm doing! :(

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by