OK this is the case, I have the following query
INSERT INTO 'FoodListTBL' ('AutoNo','CHOCals','PrtCals', 'FatCals','CHOgram','PrtGram','FatGram','CatId', 'TimeTypeId','TotalCals','Visibl', 'IsActive','NameAr','NameEn','CountryId', 'TotalPerUnit','UnitId','PreferedBread1', 'PreferedMilk1','PreferedVeg1','PreferedFat1', 'PreferedFruit1','CauseAllergy','AllergyCatId', 'TotalLikes','NameDescEn','NameDescAr','ChoPerUnit','PrtPerUnit','FatPerUnit','Quantity','PreferedBread2','PreferedMilk2', 'PreferedVeg2','PreferedFat2', 'PreferedFruit2','IV','UV','InsertDate','InsertUser') VALUES (818,0,0, 45, 0, 0, 5, 17, 1, 45,1, 1, 'زبدة قليلة الدسم', 'Butter reduced fat', 0, 45, 14, 0, 0, 0, 0, 0, 0, 0, 0, 'Butter reduced fat', 'زبدة قليلة الدسم', 0, 0, 45, 1, 0, 0, 0, 0, 0, 492, 0, '-', '-' ),(819,0,0, 45, 0, 0, 5, 17, 1, 45,1, 1, 'زبدة', 'Butter regular', 0, 45, 4, 0, 0, 0, 0, 0, 0, 0, 0, 'Butter regular', 'زبدة', 0, 0, 45, 1, 0, 0, 0, 0, 0, 493, 1475, '-', '-')
this query executed successfully on iOS 6.X and failed on any iOS less than 5.X taking into consideration that any other insert query on other tables finished successfully on any iOS
and I've tried two codes for insert this is one of them
if(sqlite3_prepare_v2(database, [query UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
{
if(SQLITE_DONE != sqlite3_step(compiledStatement))
NSLog( #"Error while inserting data: '%s'", sqlite3_errmsg(database));
else NSLog(#"New data inserted");
sqlite3_reset(compiledStatement);
}else
{
NSLog( #"Error while inserting '%s'", sqlite3_errmsg(database));
}
sqlite3_finalize(compiledStatement)
and the result in the two cases is
Error while inserting 'near ",":syntax error'
aging this query is functional on every thing except iOS < 6.0
any clues are appreciated
SQLite before version 3.7.11 does not support the multi-record INSERT syntax.
Use multiple INSERT commands, or insert the records with INSERT ... SELECT ... UNION ALL ....
Related
My aim is to extract frames out of a video but many times the frames are inverted. This is happening because "VideoCapture" in cv2 does read the rotate flag data present in the video metadata. I am running it on mac and installed "ffmpeg" package (5.0.1) using brew package manager. This is my code to check rotation present in a video using ffmpeg.
import ffmpeg
import cv2
import pprint
pp = pprint.PrettyPrinter(depth=4)
def check_rotation(path_video_file):
# this returns meta-data of the video file in form of a dictionary
meta_dict = ffmpeg.probe(path_video_file)
pp.pprint(meta_dict)
# from the dictionary, meta_dict['streams'][0]['tags']['rotate'] is the key
# we are looking for
rotateCode = None
if int(meta_dict['streams'][0]['tags']['rotate']) == 90:
rotateCode = cv2.ROTATE_90_CLOCKWISE
elif int(meta_dict['streams'][0]['tags']['rotate']) == 180:
rotateCode = cv2.ROTATE_180
elif int(meta_dict['streams'][0]['tags']['rotate']) == 270:
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE
return rotateCode
Here the meta_dict is supposed to have information about the rotation but it is not there.
printing out meta_dict gives:
{'format': {'bit_rate': '18498544',
'duration': '3.584000',
'filename': 'video.mp4',
'format_long_name': 'QuickTime / MOV',
'format_name': 'mov,mp4,m4a,3gp,3g2,mj2',
'nb_programs': 0,
'nb_streams': 2,
'probe_score': 100,
'size': '8287348',
'start_time': '0.000000',
'tags': {'com.android.version': '11',
'compatible_brands': 'isommp42',
'creation_time': '2021-12-08T10:56:57.000000Z',
'major_brand': 'mp42',
'minor_version': '0'}},
'streams': [{'avg_frame_rate': '990000/34997',
'bit_rate': '18804651',
'bits_per_raw_sample': '8',
'chroma_location': 'left',
'closed_captions': 0,
'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
'codec_name': 'h264',
'codec_tag': '0x31637661',
'codec_tag_string': 'avc1',
'codec_type': 'video',
'coded_height': 1080,
'coded_width': 1920,
'color_primaries': 'bt470bg',
'color_range': 'pc',
'color_space': 'bt470bg',
'color_transfer': 'smpte170m',
'display_aspect_ratio': '16:9',
'disposition': {'attached_pic': 0,
'captions': 0,
'clean_effects': 0,
'comment': 0,
'default': 1,
'dependent': 0,
'descriptions': 0,
'dub': 0,
'forced': 0,
'hearing_impaired': 0,
'karaoke': 0,
'lyrics': 0,
'metadata': 0,
'original': 0,
'still_image': 0,
'timed_thumbnails': 0,
'visual_impaired': 0},
'duration': '3.499700',
'duration_ts': 314973,
'extradata_size': 35,
'field_order': 'progressive',
'film_grain': 0,
'has_b_frames': 0,
'height': 1080,
'id': '0x1',
'index': 0,
'is_avc': 'true',
'level': 40,
'nal_length_size': '4',
'nb_frames': '99',
'pix_fmt': 'yuvj420p',
'profile': 'High',
'r_frame_rate': '120/1',
'refs': 1,
'sample_aspect_ratio': '1:1',
'side_data_list': [{...}],
'start_pts': 3168,
'start_time': '0.035200',
'tags': {'creation_time': '2021-12-08T10:56:57.000000Z',
'handler_name': 'VideoHandle',
'language': 'eng',
'vendor_id': '[0][0][0][0]'},
'time_base': '1/90000',
'width': 1920},
{'avg_frame_rate': '0/0',
'bit_rate': '128986',
'bits_per_sample': 0,
'channel_layout': 'stereo',
'channels': 2,
'codec_long_name': 'AAC (Advanced Audio Coding)',
'codec_name': 'aac',
'codec_tag': '0x6134706d',
'codec_tag_string': 'mp4a',
'codec_type': 'audio',
'disposition': {'attached_pic': 0,
'captions': 0,
'clean_effects': 0,
'comment': 0,
'default': 1,
'dependent': 0,
'descriptions': 0,
'dub': 0,
'forced': 0,
'hearing_impaired': 0,
'karaoke': 0,
'lyrics': 0,
'metadata': 0,
'original': 0,
'still_image': 0,
'timed_thumbnails': 0,
'visual_impaired': 0},
'duration': '3.584000',
'duration_ts': 172032,
'extradata_size': 2,
'id': '0x2',
'index': 1,
'nb_frames': '168',
'profile': 'LC',
'r_frame_rate': '0/0',
'sample_fmt': 'fltp',
'sample_rate': '48000',
'start_pts': 0,
'start_time': '0.000000',
'tags': {'creation_time': '2021-12-08T10:56:57.000000Z',
'handler_name': 'SoundHandle',
'language': 'eng',
'vendor_id': '[0][0][0][0]'},
'time_base': '1/48000'}]}
Can someone please help me to find if rotation is present in a video?
I am implementing a native webgl context compatible with h5.
Currently I support webgl1.0 APIs.
On iOS I create the EAGLContext with kEAGLRenderingAPIOpenGLES3. Other GL calls works fine, but
glTexImage2D(3553, 0, 6408, 144, 108, 0, 6408, 5126, null), glError()=1282
This call fails.
If I change EAGLContext to opengles2.0, everything works fine.
My question is all parameter values to glTexSubImage2D are the same. Why this call fails if I create the context as es3.0 but succeeds if the context is es2.0.
These are the gl calls dumped. The only difference is that when I create the EAGLContext using GLES3 api level, there is a glError 1282. If the context is created using GLES2 api level, everything works fine.
The first two glTexImage2D use GL_UNSIGNED_BYTE, the failed one uses GL_FLOAT. But es3.0 context should support GL_FLOAT.
17:26:24.683200 Will setup FBOs.
17:26:24.684360 Setup FBOs done.
17:26:24.694778 glCreateTexture()=1
17:26:24.694981 glBindTexture(3553, 1)
17:26:24.695079 glTexParameteri(3553, 10242, 10497)
17:26:24.695142 glTexParameteri(3553, 10243, 10497)
17:26:24.695266 glTexParameteri(3553, 10241, 9985)
17:26:24.695313 glTexParameteri(3553, 10240, 9729)
17:26:24.695414 glTexParameterf(3553, 34046, 1.000000)
17:26:24.695414 glTexImage2D(3553, 0, 6408, 2, 2, 0, 6408, 5121, null)
17:26:24.695414 glTexImage2D(3553, 1, 6408, 1, 1, 0, 6408, 5121, null)
17:26:24.696141 [Buf:GL_UNSIGNED_BYTE:u8] 16, 16, 1
17:26:24.696961 glTexImage2D(3553, 0, 6408, 2, 2, 0, 6408, 5121, [16])
17:26:24.697674 glGenBuffers()=1
17:26:24.697862 glGenBuffers()=2
17:26:24.702478 glGenBuffers()=3
17:26:24.702547 glGenBuffers()=4
17:26:24.702675 glGenBuffers()=5
17:26:24.702734 glGenBuffers()=6
17:26:24.722429 glGenBuffers()=7
17:26:24.722589 glBindBuffer(34962, 7)
17:26:24.722697 glBufferData(34962, [65536], null, 35048)
17:26:24.722758 glGenBuffers()=8
17:26:24.722806 glBindBuffer(34962, 8)
17:26:24.722862 glBufferData(34962, [65536], null, 35048)
17:26:24.723104 createVertexArrayOES(1)
17:26:24.723690 glGenBuffers()=9
17:26:24.723743 glBindBuffer(34962, 9)
17:26:24.723799 glBufferData(34962, [2304000], null, 35048)
17:26:24.723985 glGenBuffers()=10
17:26:24.724068 glBindBuffer(34963, 10)
17:26:24.724120 glBufferData(34963, [64000], null, 35048)
17:26:24.724120 glCreateTexture()=2
17:26:24.747552 glBindTexture(3553, 2)
17:26:24.747625 glTexParameteri(3553, 10242, 33071)
17:26:24.747680 glTexParameteri(3553, 10243, 33071)
17:26:24.747733 glTexParameteri(3553, 10241, 9729)
17:26:24.747778 glTexParameteri(3553, 10240, 9729)
17:26:24.747842 glTexParameterf(3553, 34046, 1.000000)
17:26:24.747842 glTexImage2D(3553, 0, 6408, 144, 108, 0, 6408, 5126, null), glError()=1282
17:26:24.748000 glTexParameteri(3553, 10241, 9728)
17:26:24.748048 glTexParameteri(3553, 10240, 9728)
17:26:24.748120 glTexParameteri(3553, 10242, 33071)
17:26:24.748189 glTexParameteri(3553, 10243, 33071)
17:26:24.748266 glTexParameterf(3553, 34046, 1.000000)+0800
The error is because JS passed invalid combination of internal format/format/type.
glTexImage2D(3553, 0, 6408, 144, 108, 0, 6408, 5126, null), glError()=1282
is actually glTexImage2D(3553, 0, GL_RGBA, 144, 108, 0, GL_RGBA, GL_FLOAT, null)
This combination is not valid according to https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml.
The interesting thing is that in iOS es2.0 context, this combination is valid.
I am trying to read data from UDP socket. I am using Xcode 9.2 and Swift and I want to implement communication without external libraries. I can send the data (testing using Packet Sender), but the problem is when I send the packet back and try to read data. My socket callback function gets called and callback type matches data callback. If I try to load CFData from memory using the pointer, the operation doesn't crash. Then when I try to use a CFDataGetLength or similar function on that object, the app crashes.
func socketCallback(socket: CFSocket?, callbackType: CFSocketCallBackType, address: CFData?, data: UnsafeRawPointer?, info: UnsafeMutableRawPointer?) {
if callbackType == CFSocketCallBackType.dataCallBack {
print("dataCallback called.")
let cf = data!.load(as: CFData.self)
print(cf) // prints __NSCFData
print(CFDataGetLength(cf)) // crashes
}
}
The exception being thrown:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[__NSCFData length]: unrecognized selector sent to class 0x10ca08348'
Same exception for other CFData functions, not just CFDataGetLength, for example
var bytes = [UInt8]()
print(CFDataGetBytes(cf, CFRange(location: 0, length: 3), &bytes))
I have tried to read some data from memory as unsigned bytes, at pointer (data) and with offset:
var array = [UInt8]()
for i in 0...55 {
let pointer = data! + i
array.append(pointer.load(as: UInt8.self))
}
print(array, separator: ", ", terminator: "\n")
It prints the following:
[72, 67, 103, 5, 1, 0, 0, 0, 132, 20, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 97, 97, 0, 0, 0, 0, 0]
I noticed that the number 3 is the length of the message, and bytes 48, 49 and 50 are the data (I have send "aaa", 97 is "a" in ascii).
Socket initialization code:
var socket = CFSocketCreate(nil, PF_INET, SOCK_DGRAM, IPPROTO_UDP, CFSocketCallBackType.dataCallBack.rawValue, socketCallback, nil)
let runLoopSource = CFSocketCreateRunLoopSource(nil, socket, 0)
CFRunLoopAddSource(CFRunLoopGetMain(), runLoopSource, CFRunLoopMode.defaultMode)
Most information that I found was for ObjC and I am not very familiar with ObjC.
What could I have done wrong?
I have an array that looks like this:
foo = ["25\"/64cm", "0\"/0cm", "0\"/0cm", "0\"/0cm", "2\"/6cm", "0\"/0cm", "0\"/0cm", "0\"/0cm", "0\"/0cm", "0\"/0cm"]
I am trying to scan the array, and return a new array of the values (integers) between the / and cm. I am hoping it would come out at:
bar = [64, 0, 0, 0, 6, 0, 0, 0, 0, 0]
Sorry I am new to ruby
foo.map {|s| s[/\d+cm/].to_i }
# => [64, 0, 0, 0, 6, 0, 0, 0, 0, 0]
There should be at least one answer that doesn't use a regex:
foo.map { |s| s.split('/').last.to_i }
#=> [64, 0, 0, 0, 6, 0, 0, 0, 0, 0]
foo.map { |s| /(\d+)cm/.match(s)[1].to_i }
Try This:
foo.join().scan(/\b(\d+cm)/).flatten.map{|x| x.to_i}
I want to add a line break (\n) in front of the 5th element on every other line:
2, 0, 0, 0, 2
4, 0, 0, 0, 4
6, 0, 0, 0, 6
8, 0, 0, 0, 8
... in order to get:
2, 0, 0, 0, 2
4, 0, 0, 0, \n4
6, 0, 0, 0, 6
8, 0, 0, 0, \n8
What I have so far in gawk doesn't work:
gawk '{if (NR % 2) {$5=\n$5; print} else print}'
You could say:
awk '{NR%2 || $5="\\n"$5 }1' filename
Note that you'll need to escape the \ in order to get a literal \.
For your input, it'd produce:
2, 0, 0, 0, 2
4, 0, 0, 0, \n4
6, 0, 0, 0, 6
8, 0, 0, 0, \n8
Alternatively, (as pointed out by #WilliamPursell), you could say:
awk '!(NR%2) {$5="\\n"$5 }1' filename